@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 the correctness of end of day definition. */ @Test public void isEndOfDayTest() { // travel time = 0 rm.removeObject(d); rm.addObjectAtSamePosition(d, depot); assertFalse(d.isEndOfDay(time(minute(0), minute(1)))); assertFalse(d.isEndOfDay(time(minute(29), minute(30)))); assertTrue(d.isEndOfDay(time(minute(30), minute(31)))); // travel time = 4 minutes from the depot at (3,5) rm.removeObject(d); rm.addObjectAt(d, new Point(5, 5)); assertFalse(d.isEndOfDay(time(minute(25), minute(26)))); assertTrue(d.isEndOfDay(time(minute(26), minute(27)))); // travel time = 4.5 minutes from the depot rm.removeObject(d); rm.addObjectAt(d, new Point(5, 5.5)); assertFalse(d.isEndOfDay(time(minute(24), minute(25)))); assertTrue(d.isEndOfDay(time(minute(25), minute(26)))); }