@SuppressWarnings("synthetic-access") @Nullable @Override public DefaultEvent handle(@Nullable StateEvent event, RouteFollowingVehicle context) { if (!route.isEmpty()) { checkCurrentParcelOwnership(); if (!isTooEarly(route.peek(), currentTime.get())) { return DefaultEvent.GOTO; } // else it is too early, and we do nothing } else if (currentTime.get().hasTimeLeft() && isEndOfDay(currentTime.get()) && !getRoadModel().equalPosition(context, depot.get())) { // check if it is time to go back to the depot getRoadModel().moveTo(context, depot.get(), currentTime.get()); } currentTime.get().consumeAll(); return null; } }
@SuppressWarnings("synthetic-access") @Nullable @Override public DefaultEvent handle(@Nullable StateEvent event, RouteFollowingVehicle context) { if (!route.isEmpty()) { checkCurrentParcelOwnership(); if (!isTooEarly(route.peek(), currentTime.get())) { return DefaultEvent.GOTO; } // else it is too early, and we do nothing } else if (currentTime.get().hasTimeLeft() && isEndOfDay(currentTime.get()) && !getRoadModel().equalPosition(context, depot.get())) { // check if it is time to go back to the depot getRoadModel().moveTo(context, depot.get(), currentTime.get()); } currentTime.get().consumeAll(); return null; } }
/** * Test illegal argument: transition state. */ @Test(expected = IllegalArgumentException.class) public void isTooEarlyTransitionStateFail() { d.setRoute(asList(p1)); tick(3, 6); assertEquals(ParcelState.PICKING_UP, pm.getParcelState(p1)); d.isTooEarly(p1, time(2)); }
/** * Test method when parcel is already in the available state. */ @Test public void isTooEarlyAvailableState() { tick(5, 6); assertFalse(d.isTooEarly(p1, time(2))); }
/** * Test illegal argument: delivered state. */ @Test(expected = IllegalArgumentException.class) public void isTooEarlyDeliveredStateFail() { d.setRoute(asList(p1, p1)); tick(0, 60); assertEquals(ParcelState.DELIVERED, pm.getParcelState(p1)); d.isTooEarly(p1, time(2)); }
/** * Test definition of isTooEarly. */ @Test public void testIsTooEarly() { // traveling 1km at 30km/h should take 2 minutes assertEquals(minute(2), d.computeTravelTimeTo(new Point(1, 2), SI.MILLI(SI.SECOND))); // if we start immediately we are too early assertTrue(d.isTooEarly(p1, time(0, 10))); assertTrue(d.isTooEarly(p1, time(minute(2), minute(3)))); assertFalse(d.isTooEarly(p1, time(minute(2) + 1, minute(3) + 1))); assertFalse(d.isTooEarly(p1, time(minute(3), minute(4)))); assertFalse(d.isTooEarly(p1, time(minute(4), minute(5)))); assertFalse(d.isTooEarly(p1, time(minute(10), minute(11)))); assertTrue(d.isTooEarly(p2, time(0, 10))); assertTrue(d.isTooEarly(p2, time(minute(10) + 10, minute(11) + 10))); assertFalse(d.isTooEarly(p2, time(minute(10) + 11, minute(11) + 11))); assertFalse(d.isTooEarly(p2, time(minute(11), minute(12)))); assertFalse(d.isTooEarly(p2, time(minute(12), minute(13)))); assertFalse(d.isTooEarly(p2, time(minute(20), minute(21)))); }