Skip to content

Commit

Permalink
refactor: rename package mcmin to mcmax
Browse files Browse the repository at this point in the history
  • Loading branch information
t2gran committed Jun 19, 2024
1 parent 960f243 commit 78c4a17
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -25,7 +25,6 @@ boolean isEmpty() {
return items.isEmpty();
}


boolean isSingleItemGroup() {
return items.size() == 1;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,6 +12,7 @@
* simple bookkeeping for the state of the filter.
*/
class State {

private final List<Item> items;
private final List<Group> groups;
private final List<Item> result = new ArrayList<>();
Expand Down Expand Up @@ -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.
Expand All @@ -108,7 +108,12 @@ private static Item findBestItem(List<Group> groups) {
*/
@Nullable
private static Item findItemInFirstSingleItemGroup(List<Group> 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<Item> createListOfItems(List<Itinerary> itineraries) {
Expand All @@ -119,7 +124,10 @@ private static ArrayList<Item> createListOfItems(List<Itinerary> itineraries) {
return items;
}

private static List<Group> createGroups(Collection<Item> items, List<SingeCriteriaComparator> comparators) {
private static List<Group> createGroups(
Collection<Item> items,
List<SingeCriteriaComparator> comparators
) {
List<Group> groups = new ArrayList<>();
for (SingeCriteriaComparator comparator : comparators) {
if (comparator.strictOrder()) {
Expand All @@ -135,7 +143,10 @@ private static List<Group> createGroups(Collection<Item> items, List<SingeCriter
* In a strict ordered group only one optimal value exist for the criteria defined by the given
* {@code comparator}. All items that have this value should be included in the group created.
*/
private static Group createOrderedGroup(Collection<Item> items, SingeCriteriaComparator comparator) {
private static Group createOrderedGroup(
Collection<Item> items,
SingeCriteriaComparator comparator
) {
Group group = null;
for (Item item : items) {
if (group == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -153,10 +153,10 @@ private static String toStr(List<Itinerary> 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(", "));
}
Expand All @@ -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)
);
}
}
}

0 comments on commit 78c4a17

Please sign in to comment.