From 78c4a17669b3eb12dcf3f75f4c098dc436887587 Mon Sep 17 00:00:00 2001 From: Thomas Gran Date: Wed, 19 Jun 2024 14:00:06 +0200 Subject: [PATCH] refactor: rename package mcmin to mcmax --- .../system/{mcmin => mcmax}/Group.java | 3 +-- .../filters/system/{mcmin => mcmax}/Item.java | 2 +- .../McMinimumNumberItineraryFilter.java | 2 +- .../system/{mcmin => mcmax}/State.java | 21 ++++++++++++++----- .../system/{mcmin => mcmax}/ItemTest.java | 2 +- .../McMinimumNumberItineraryFilterTest.java | 20 +++++++++--------- 6 files changed, 30 insertions(+), 20 deletions(-) rename src/main/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/{mcmin => mcmax}/Group.java (98%) rename src/main/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/{mcmin => mcmax}/Item.java (98%) rename src/main/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/{mcmin => mcmax}/McMinimumNumberItineraryFilter.java (99%) rename src/main/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/{mcmin => mcmax}/State.java (93%) rename src/test/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/{mcmin => mcmax}/ItemTest.java (99%) rename src/test/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/{mcmin => mcmax}/McMinimumNumberItineraryFilterTest.java (95%) diff --git a/src/main/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/mcmin/Group.java b/src/main/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/mcmax/Group.java similarity index 98% rename from src/main/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/mcmin/Group.java rename to src/main/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/mcmax/Group.java index 0f231517ae3..7bfdad83e8f 100644 --- a/src/main/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/mcmin/Group.java +++ b/src/main/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/mcmax/Group.java @@ -1,4 +1,4 @@ -package org.opentripplanner.routing.algorithm.filterchain.filters.system.mcmin; +package org.opentripplanner.routing.algorithm.filterchain.filters.system.mcmax; import java.util.ArrayList; import java.util.Iterator; @@ -25,7 +25,6 @@ boolean isEmpty() { return items.isEmpty(); } - boolean isSingleItemGroup() { return items.size() == 1; } diff --git a/src/main/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/mcmin/Item.java b/src/main/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/mcmax/Item.java similarity index 98% rename from src/main/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/mcmin/Item.java rename to src/main/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/mcmax/Item.java index 58898f2ee63..36c3d662493 100644 --- a/src/main/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/mcmin/Item.java +++ b/src/main/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/mcmax/Item.java @@ -1,4 +1,4 @@ -package org.opentripplanner.routing.algorithm.filterchain.filters.system.mcmin; +package org.opentripplanner.routing.algorithm.filterchain.filters.system.mcmax; import org.opentripplanner.model.plan.Itinerary; diff --git a/src/main/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/mcmin/McMinimumNumberItineraryFilter.java b/src/main/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/mcmax/McMinimumNumberItineraryFilter.java similarity index 99% rename from src/main/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/mcmin/McMinimumNumberItineraryFilter.java rename to src/main/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/mcmax/McMinimumNumberItineraryFilter.java index b1e7b857c3b..da8d6fa1c66 100644 --- a/src/main/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/mcmin/McMinimumNumberItineraryFilter.java +++ b/src/main/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/mcmax/McMinimumNumberItineraryFilter.java @@ -1,4 +1,4 @@ -package org.opentripplanner.routing.algorithm.filterchain.filters.system.mcmin; +package org.opentripplanner.routing.algorithm.filterchain.filters.system.mcmax; import java.util.List; import java.util.function.Predicate; diff --git a/src/main/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/mcmin/State.java b/src/main/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/mcmax/State.java similarity index 93% rename from src/main/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/mcmin/State.java rename to src/main/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/mcmax/State.java index acce6a963f4..d616c505446 100644 --- a/src/main/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/mcmin/State.java +++ b/src/main/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/mcmax/State.java @@ -1,4 +1,4 @@ -package org.opentripplanner.routing.algorithm.filterchain.filters.system.mcmin; +package org.opentripplanner.routing.algorithm.filterchain.filters.system.mcmax; import java.util.ArrayList; import java.util.Collection; @@ -12,6 +12,7 @@ * simple bookkeeping for the state of the filter. */ class State { + private final List items; private final List groups; private final List result = new ArrayList<>(); @@ -86,7 +87,6 @@ private void removeGroupsWitchContainsItem(Item item) { groups.removeIf(Group::isEmpty); } - /** * The best item is the one witch exists in most groups, and in case of a tie, the sort order/ * itinerary index is used. @@ -108,7 +108,12 @@ private static Item findBestItem(List groups) { */ @Nullable private static Item findItemInFirstSingleItemGroup(List groups) { - return groups.stream().filter(Group::isSingleItemGroup).findFirst().map(Group::first).orElse(null); + return groups + .stream() + .filter(Group::isSingleItemGroup) + .findFirst() + .map(Group::first) + .orElse(null); } private static ArrayList createListOfItems(List itineraries) { @@ -119,7 +124,10 @@ private static ArrayList createListOfItems(List itineraries) { return items; } - private static List createGroups(Collection items, List comparators) { + private static List createGroups( + Collection items, + List comparators + ) { List groups = new ArrayList<>(); for (SingeCriteriaComparator comparator : comparators) { if (comparator.strictOrder()) { @@ -135,7 +143,10 @@ private static List createGroups(Collection items, List items, SingeCriteriaComparator comparator) { + private static Group createOrderedGroup( + Collection items, + SingeCriteriaComparator comparator + ) { Group group = null; for (Item item : items) { if (group == null) { diff --git a/src/test/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/mcmin/ItemTest.java b/src/test/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/mcmax/ItemTest.java similarity index 99% rename from src/test/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/mcmin/ItemTest.java rename to src/test/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/mcmax/ItemTest.java index fbb2f5dea57..c8cd04212e5 100644 --- a/src/test/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/mcmin/ItemTest.java +++ b/src/test/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/mcmax/ItemTest.java @@ -1,4 +1,4 @@ -package org.opentripplanner.routing.algorithm.filterchain.filters.system.mcmin; +package org.opentripplanner.routing.algorithm.filterchain.filters.system.mcmax; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; diff --git a/src/test/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/mcmin/McMinimumNumberItineraryFilterTest.java b/src/test/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/mcmax/McMinimumNumberItineraryFilterTest.java similarity index 95% rename from src/test/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/mcmin/McMinimumNumberItineraryFilterTest.java rename to src/test/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/mcmax/McMinimumNumberItineraryFilterTest.java index 8d3d03cb857..e094e53cd03 100644 --- a/src/test/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/mcmin/McMinimumNumberItineraryFilterTest.java +++ b/src/test/java/org/opentripplanner/routing/algorithm/filterchain/filters/system/mcmax/McMinimumNumberItineraryFilterTest.java @@ -1,4 +1,4 @@ -package org.opentripplanner.routing.algorithm.filterchain.filters.system.mcmin; +package org.opentripplanner.routing.algorithm.filterchain.filters.system.mcmax; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.opentripplanner.model.plan.TestItineraryBuilder.newItinerary; @@ -153,10 +153,10 @@ private static String toStr(List list) { .stream() .map(i -> "[ %d %d %s ]".formatted( - i.getGeneralizedCost(), - i.getNumberOfTransfers(), - groupsToString(i.getGeneralizedCost2().orElse(-1)) - ) + i.getGeneralizedCost(), + i.getNumberOfTransfers(), + groupsToString(i.getGeneralizedCost2().orElse(-1)) + ) ) .collect(Collectors.joining(", ")); } @@ -182,11 +182,11 @@ Itinerary create() { public String toString() { // The red-x is a unicode character(U+274C) and should be visible in most IDEs. return "%s %d %d %s".formatted( - expected ? "" : "❌", - c1, - nTransfers, - groupsToString(transitGroupIds) - ); + expected ? "" : "❌", + c1, + nTransfers, + groupsToString(transitGroupIds) + ); } } }