-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Allow itinerary in response to be sorted by duration #2593
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
t2gran
merged 5 commits into
opentripplanner:master
from
camsys:vtrans-duration-comparator
Oct 18, 2018
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8a9488d
Add duration comparator. Include tests. More Comparator<Path> impleme…
sdjacobs 33a248f
Add documentation and query parameter support for pathComparator para…
sdjacobs fb1d464
Merge remote-tracking branch 'otp/master' into vtrans-duration-compar…
sdjacobs 15d6de1
Update changelog
sdjacobs c0c8544
Merge branch 'master' into vtrans-duration-comparator
t2gran File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/java/org/opentripplanner/routing/impl/DurationComparator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /* This program is free software: you can redistribute it and/or | ||
| modify it under the terms of the GNU Lesser General Public License | ||
| as published by the Free Software Foundation, either version 3 of | ||
| the License, or (at your option) any later version. | ||
|
|
||
| This program is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
|
|
||
| You should have received a copy of the GNU General Public License | ||
| along with this program. If not, see <http://www.gnu.org/licenses/>. */ | ||
|
|
||
| package org.opentripplanner.routing.impl; | ||
|
|
||
| import org.opentripplanner.routing.spt.GraphPath; | ||
|
|
||
| import java.util.Comparator; | ||
|
|
||
| public class DurationComparator implements Comparator<GraphPath> { | ||
|
|
||
| @Override | ||
| public int compare(GraphPath o1, GraphPath o2) { | ||
| return o1.getDuration() - o2.getDuration(); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/test/java/org/opentripplanner/routing/impl/PathComparatorTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| /* This program is free software: you can redistribute it and/or | ||
| modify it under the terms of the GNU Lesser General Public License | ||
| as published by the Free Software Foundation, either version 3 of | ||
| the License, or (at your option) any later version. | ||
|
|
||
| This program is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU General Public License for more details. | ||
|
|
||
| You should have received a copy of the GNU General Public License | ||
| along with this program. If not, see <http://www.gnu.org/licenses/>. */ | ||
| package org.opentripplanner.routing.impl; | ||
|
|
||
| import org.junit.Test; | ||
| import org.opentripplanner.routing.spt.GraphPath; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.List; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| public class PathComparatorTest { | ||
|
|
||
| GraphPath a = mockGraphPath(5, 7); | ||
|
|
||
| GraphPath b = mockGraphPath(0, 8); | ||
|
|
||
| GraphPath c = mockGraphPath(9, 12); | ||
|
|
||
| private List<GraphPath> paths = Arrays.asList(a, b, c); | ||
|
|
||
| @Test | ||
| public void testPathComparator() { | ||
| paths.sort(new PathComparator(false)); | ||
| assertEquals(paths, Arrays.asList(a, b, c)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testPathComparatorArriveBy() { | ||
| paths.sort(new PathComparator(true)); | ||
| assertEquals(paths, Arrays.asList(c, a, b)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testDurationComparator() { | ||
| paths.sort(new DurationComparator()); | ||
| assertEquals(paths, Arrays.asList(a, c, b)); | ||
| } | ||
|
|
||
|
|
||
| private GraphPath mockGraphPath(long startTime, long endTime) { | ||
| GraphPath path = mock(GraphPath.class); | ||
| when(path.getStartTime()).thenReturn(startTime); | ||
| when(path.getEndTime()).thenReturn(endTime); | ||
| when(path.getDuration()).thenReturn((int) (endTime - startTime)); | ||
| return path; | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cannot any places where
pathComparatoris set. I think a comment on how this is used(set to somethingothernull) should be documented. Is the plan to integrate with some kind of configuration later, routing request parameter, or just fork the code and inject a different strategy?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not set explicitly in the code, but if you include configuration in
router-config.json, it will get set automatically, e.g.This happens via the existing config-setting code:
OpenTripPlanner/src/main/java/org/opentripplanner/standalone/Router.java
Line 98 in adb45ef
I'll add code to allow this to be set via an API parameter as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the clarification. I think your solution is the best, it might be confusing to have "config" params only.