Skip to content

Commit

Permalink
Merge branch 'release/0.10'
Browse files Browse the repository at this point in the history
  • Loading branch information
jmortlock committed Nov 10, 2020
2 parents ef3f1a3 + 05c5613 commit cfc2bab
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
### QuickTravel Client Java

## 0.10.2

* [TT-8303] Add support for matching resource id in closest departure finder

## 0.10.1

* [TT-8250] Add masterpoint_resource_id field to resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,21 @@ public class ClosestDepartureFinder {
private Route route;
private DateTime targetDate;
private Integer vesselId;
private Integer resourceId;

ClosestDepartureFinder(Route route, Date targetDate, Integer vesselId) {
ClosestDepartureFinder(Route route, Date targetDate, Integer vesselId, Integer resourceId) {
this.route = route;
this.targetDate = new DateTime(targetDate);
this.vesselId = vesselId;
this.resourceId = resourceId;
}

private boolean matchVessel(Integer vesselId) {
return this.vesselId == null || vesselId.equals(this.vesselId);
}

private boolean matchResource(Integer resourceId) {
return this.resourceId == null || resourceId.equals(this.resourceId);
}

public Departure find() {
Expand All @@ -28,7 +38,7 @@ public Departure find() {

List<Departure> departures = new ArrayList<>();
for (Departure d : route.getDepartures()) {
if (this.vesselId == null || d.getVesselId() == vesselId) {
if (matchResource(d.getResourceId()) && matchVessel(d.getVesselId())) {
departures.add(d);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import java.util.Date;

public class DepartureFinder {
public static Departure closest(Route route, Date targetDate, Integer vesselId) {
return new ClosestDepartureFinder(route, targetDate, vesselId).find();
public static Departure closest(Route route, Date targetDate, Integer vesselId, Integer resourceId) {
return new ClosestDepartureFinder(route, targetDate, vesselId, resourceId).find();
}

public static Departure closest(Route route, Date targetDate) {
return DepartureFinder.closest(route, targetDate, null);
return DepartureFinder.closest(route, targetDate, null, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,28 @@ public class ClosestDepartureFinderTest {

private static Departure departureA =
ClosestDepartureFinderTest.makeDeparture(
DateHelper.parseIso("2018-06-14T09:00:00+09:30"), 1);
DateHelper.parseIso("2018-06-14T09:00:00+09:30"), 1, 100);

private static Departure departureB =
ClosestDepartureFinderTest.makeDeparture(
DateHelper.parseIso("2018-06-14T10:00:00+09:30"), 1);
DateHelper.parseIso("2018-06-14T10:00:00+09:30"), 1, 100);

private static Departure departureC =
ClosestDepartureFinderTest.makeDeparture(
DateHelper.parseIso("2018-06-14T11:00:00+09:30"), 1);
DateHelper.parseIso("2018-06-14T11:00:00+09:30"), 1, 100);

private static Departure departureD =
ClosestDepartureFinderTest.makeDeparture(
DateHelper.parseIso("2018-06-14T13:00:00+09:30"), 2);
DateHelper.parseIso("2018-06-14T13:00:00+09:30"), 2, 100);

private static Departure departureE =
ClosestDepartureFinderTest.makeDeparture(
DateHelper.parseIso("2018-06-14T13:00:00+09:30"), 3);
DateHelper.parseIso("2018-06-14T13:00:00+09:30"), 3, 101);

private static Departure makeDeparture(Date time, int vesselId) {
private static Departure makeDeparture(Date time, int vesselId, int resourceId) {
Departure departure = new Departure(time);
departure.setVesselId(vesselId);
departure.setResourceId(resourceId);
return departure;
}

Expand Down Expand Up @@ -91,23 +92,42 @@ public void exactDepartureTime() {
public void whenSpecificVessel() {
Route route = testRoute();
Date target = DateHelper.parseIso("2018-06-14T11:00:00+09:30");
Departure match = DepartureFinder.closest(route, target, 2);
Departure match = DepartureFinder.closest(route, target, 2, null);
Assert.assertSame(departureD, match);

//Try Same time different vessel
match = DepartureFinder.closest(route, target, 1);
match = DepartureFinder.closest(route, target, 1, null);
Assert.assertSame(departureC, match);

//Try Same time different vessel
match = DepartureFinder.closest(route, target, 3);
match = DepartureFinder.closest(route, target, 3, null);
Assert.assertSame(departureE, match);
}

@Test
public void whenNoSpecificVesselFound() {
Route route = testRoute();
Date target = DateHelper.parseIso("2018-06-14T11:00:00+09:30");
Departure match = DepartureFinder.closest(route, target, 10);
Departure match = DepartureFinder.closest(route, target, 10, null);
Assert.assertNull(match);
}

@Test
public void whenSpecificResource() {
Route route = testRoute();
Date target = DateHelper.parseIso("2018-06-14T11:00:00+09:30");
Departure match = DepartureFinder.closest(route, target, 2, 100);
Assert.assertSame(departureD, match);

//Try Same time specific vessel
match = DepartureFinder.closest(route, target, 1, 100);
Assert.assertSame(departureC, match);

//Try without vessel, specific resource
match = DepartureFinder.closest(route, target, null, 101);
Assert.assertSame(departureE, match);

match = DepartureFinder.closest(route, target, null, 101);
Assert.assertSame(departureE, match);
}
}

0 comments on commit cfc2bab

Please sign in to comment.