Esempio n. 1
0
  private HandlingActivity calculateNextExpectedActivity(
      RouteSpecification routeSpecification, Itinerary itinerary) {
    if (!onTrack()) return NO_ACTIVITY;

    if (lastEvent == null)
      return new HandlingActivity(HandlingEvent.Type.RECEIVE, routeSpecification.getOrigin());

    switch (lastEvent.getType()) {
      case LOAD:
        for (Leg leg : itinerary.getLegs()) {
          if (leg.getLoadLocation().equals(lastEvent.getLocation())) {
            return new HandlingActivity(
                HandlingEvent.Type.UNLOAD, leg.getUnloadLocation(), leg.getVoyage());
          }
        }

        return NO_ACTIVITY;

      case UNLOAD:
        for (Iterator<Leg> it = itinerary.getLegs().iterator(); it.hasNext(); ) {
          final Leg leg = it.next();
          if (leg.getUnloadLocation().equals(lastEvent.getLocation())) {
            if (it.hasNext()) {
              final Leg nextLeg = it.next();
              return new HandlingActivity(
                  HandlingEvent.Type.LOAD, nextLeg.getLoadLocation(), nextLeg.getVoyage());
            } else {
              return new HandlingActivity(HandlingEvent.Type.CLAIM, leg.getUnloadLocation());
            }
          }
        }

        return NO_ACTIVITY;

      case RECEIVE:
        final Leg firstLeg = itinerary.getLegs().iterator().next();
        return new HandlingActivity(
            HandlingEvent.Type.LOAD, firstLeg.getLoadLocation(), firstLeg.getVoyage());

      case CLAIM:
      default:
        return NO_ACTIVITY;
    }
  }