org.opentripplanner.routing.impl.PathComparator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of otp Show documentation
Show all versions of otp Show documentation
The OpenTripPlanner multimodal journey planning system
package org.opentripplanner.routing.impl;
import java.util.Comparator;
import org.opentripplanner.routing.spt.GraphPath;
public class PathComparator implements Comparator {
boolean compareStartTimes;
public PathComparator(boolean compareStartTimes) {
this.compareStartTimes = compareStartTimes;
}
/**
* For depart-after search results sort by arrival time ascending
* For arrive-before search results sort by departure time descending
*/
@Override
public int compare(GraphPath o1, GraphPath o2) {
if (compareStartTimes) {
return (int) (o2.getStartTime() - o1.getStartTime());
} else {
return (int) (o1.getEndTime() - o2.getEndTime());
}
}
}