@Override public void tick(TimeLapse timeLapse) { synchronized (this) { // TODO this can be optimized by scheduling events upon registering currentTime = timeLapse.getStartTime(); final Collection<Parcel> parcels = parcelState.get(ParcelState.ANNOUNCED); final List<Parcel> newAvailables = newArrayList(); for (final Parcel p : parcels) { if (timeLapse.getStartTime() >= p.getPickupTimeWindow().begin) { newAvailables.add(p); } } for (final Parcel p : newAvailables) { parcelState.put(ParcelState.AVAILABLE, p); eventDispatcher.dispatchEvent( new PDPModelEvent(PDPModelEventType.PARCEL_AVAILABLE, self, currentTime, p, null)); } } }
@Override public Collection<Parcel> getParcels(ParcelState state) { synchronized (this) { return parcelState.get(state); } }