type){
if(defaultProblemStates_.containsKey(stateId)) return defaultProblemStates_.getState(stateId, type);
return null;
}
-
- /**
- * Generic method to add a default route state.
- *
- * for example if you want to store 'maximum weight' at route-level, the default might be zero and you
- * can add the default simply by coding
- * addDefaultRouteState(StateFactory.createStateId("max_weight"), Integer.class, 0)
- *
- * @param stateId for which a default state is added
- * @param type of state
- * @param defaultState default state value
- */
+
+ @Deprecated
public void addDefaultRouteState(StateId stateId, Class type, T defaultState){
if(StateFactory.isReservedId(stateId)) StateFactory.throwReservedIdException(stateId.toString());
defaultRouteStates_.put(stateId, type.cast(defaultState));
}
- /**
- * Generic method to add default activity state.
- *
- * @param stateId for which a default state is added
- * @param type of state
- * @param defaultState default state value
- */
+ @Deprecated
public void addDefaultActivityState(StateId stateId, Class type, T defaultState){
if(StateFactory.isReservedId(stateId)) StateFactory.throwReservedIdException(stateId.toString());
defaultActivityStates_.put(stateId, type.cast(defaultState));
}
/**
- * Clears all states.
+ * Clears all states, i.e. set all value to null.
*
*/
public void clear(){
@@ -258,12 +273,19 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
}
/**
- * Returns activity state of type 'type'.
- *
+ * Returns associated state for the specified activity and stateId, or it returns null if no value is associated.
+ * If type class is not equal to the associated type class of the requested state value, it throws a ClassCastException.
+ *
+ * @param act the activity for which a state value is associated to
+ * @param stateId the stateId for which a state value is associated to
+ * @param type the type of class of the associated state value
+ * @param the type
+ * @return the state value that is associated to the specified activity and stateId, or null if no value is associated.
+ * @throws java.lang.ClassCastException if type class is not equal to the associated type class of the requested state value
*/
@Override
public T getActivityState(TourActivity act, StateId stateId, Class type) {
- if(act.getIndex()<0) return getDefaultTypedActivityState(act, stateId, type);
+// if(act.getIndex()<0) return getDefaultTypedActivityState(act, stateId, type);
T state;
try{
state = type.cast(activity_states[act.getIndex()][stateId.getIndex()]);
@@ -271,20 +293,37 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
catch (ClassCastException e){
throw getClassCastException(e,stateId,type.toString(),activity_states[act.getIndex()][stateId.getIndex()].getClass().toString());
}
- if(state == null) throw new NullPointerException("state " + stateId.toString() + " of activity " + act + " is missing.");
+// if(state == null) throw new NullPointerException("state " + stateId.toString() + " of activity " + act + " is missing.");
return state;
}
+ /**
+ * Returns true if a state value is associated to the specified activity, vehicle and stateId.
+ *
+ * @param act the activity for which a state value is associated to
+ * @param vehicle the vehicle for which a state value is associated to
+ * @param stateId the stateId which is the associated key to the problem state
+ * @return true if a state value is associated otherwise false
+ */
public boolean hasActivityState(TourActivity act, Vehicle vehicle, StateId stateId){
return vehicle_dependent_activity_states[act.getIndex()][vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()] != null;
}
/**
- * Returns activity state of type 'type'.
- *
+ * Returns the associated state value to the specified activity, vehicle and stateId, or null if no state value is
+ * associated.
+ * If type class is not equal to the associated type class of the requested state value, it throws a ClassCastException.
+ * @param act the activity for which a state value is associated to
+ * @param vehicle the vehicle for which a state value is associated to
+ * @param stateId the stateId which is the associated key to the problem state
+ * @param type the class of the associated state value
+ * @param the type of the class
+ * @return the associated state value to the specified activity, vehicle and stateId, or null if no state value is
+ * associated.
+ * @throws java.lang.ClassCastException if type class is not equal to the associated type class of the requested state value
*/
public T getActivityState(TourActivity act, Vehicle vehicle, StateId stateId, Class type) {
- if(act.getIndex()<0) return getDefaultTypedActivityState(act, stateId, type);
+// if(act.getIndex()<0) return getDefaultTypedActivityState(act, stateId, type);
T state;
try {
state = type.cast(vehicle_dependent_activity_states[act.getIndex()][vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()]);
@@ -293,7 +332,7 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
Object state_class = vehicle_dependent_activity_states[act.getIndex()][vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()];
throw getClassCastException(e,stateId,type.toString(),state_class.getClass().toString());
}
- if(state == null) throw new NullPointerException("state " + stateId.toString() + " of activity " + act + " for vehicle " + vehicle.getId() + " is missing.");
+// if(state == null) throw new NullPointerException("state " + stateId.toString() + " of activity " + act + " for vehicle " + vehicle.getId() + " is missing.");
return state;
}
@@ -301,13 +340,7 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
return new ClassCastException(e + "\n" + "state with stateId '" + stateId.toString() + "' is of " + memorizedTypeClass + ". cannot cast it to " + requestedTypeClass + ".");
}
- /**
- *
- * @param act activity for which the state is requested
- * @param stateId stateId of requested state
- * @param type class of state value
- * @return state value
- */
+ @Deprecated
private T getDefaultTypedActivityState(TourActivity act, StateId stateId, Class type) {
if(defaultActivityStates_.containsKey(stateId)){
return type.cast(defaultActivityStates_.get(stateId));
@@ -321,15 +354,19 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
return null;
}
- /**
- * Return route state of type 'type'.
- *
- * @return route-state
- * @throws ClassCastException if state of route and stateId is of another type
- */
+ /**
+ * Returns the route state that is associated to the route and stateId, or null if no state is associated.
+ * If type class is not equal to the associated type class of the requested state value, it throws a ClassCastException.
+ *
+ * @param route the route which the associated route key to the route state
+ * @param stateId the stateId which is the associated key to the route state
+ * @param type the class of the associated state value
+ * @param the type of the class
+ * @return the route state that is associated to the route and stateId, or null if no state is associated.
+ */
@Override
public T getRouteState(VehicleRoute route, StateId stateId, Class type) {
- if(route.isEmpty()) return getDefaultTypedRouteState(stateId,type);
+// if(route.isEmpty()) return getDefaultTypedRouteState(stateId,type);
T state;
try{
state = type.cast(route_states[route.getActivities().get(0).getIndex()][stateId.getIndex()]);
@@ -341,10 +378,29 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
return state;
}
+ /**
+ * Returns true if a state is assigned to the specified route, vehicle and stateId. Otherwise it returns false.
+ *
+ * @param route the route for which the state is requested
+ * @param vehicle the vehicle for which the state is requested
+ * @param stateId the stateId(entifier) for the state that is requested
+ * @return true if state exists and false otherwise
+ */
public boolean hasRouteState(VehicleRoute route, Vehicle vehicle, StateId stateId) {
return vehicle_dependent_route_states[route.getActivities().get(0).getIndex()][vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()] != null;
}
+ /**
+ * Returns the route state that is assigned to the specified route, vehicle and stateId.
+ * Returns null if no state can be found
+ * @param route the route for which the state is requested
+ * @param vehicle the vehicle for which the state is requested
+ * @param stateId the stateId(entifier) for the state that is requested
+ * @param type the type class of the requested state
+ * @param the type of the class
+ * @return the actual route state that is assigned to the route, vehicle and stateId
+ * @throws java.lang.ClassCastException if specified type is not equal to the memorized type
+ */
public T getRouteState(VehicleRoute route, Vehicle vehicle, StateId stateId, Class type) {
if(route.isEmpty()) return getDefaultTypedRouteState(stateId,type);
T state;
@@ -354,7 +410,6 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
catch( ClassCastException e){
throw getClassCastException(e, stateId, type.toString(), vehicle_dependent_route_states[route.getActivities().get(0).getIndex()][vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()].getClass().toString());
}
- if(state==null) throw new NullPointerException("state " + stateId.toString() + " of route " + route + " for vehicle " + vehicle.getId() + " is missing.");
return state;
}
@@ -365,22 +420,6 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
return null;
}
-
- /**
- * Generic method to memorize state 'state' of type 'type' of act and stateId.
- *
- * For example:
- * Capacity loadAtMyActivity = Capacity.Builder.newInstance().addCapacityDimension(0,10).build();
- * stateManager.putTypedActivityState(myActivity, StateFactory.createStateId("act-load"), Capacity.class, loadAtMyActivity);
- *
you can retrieve the load at myActivity by
- * Capacity load = stateManager.getActivityState(myActivity, StateFactory.createStateId("act-load"), Capacity.class);
- *
- * @param act for which a new state should be memorized
- * @param stateId stateId of state
- * @param type class of state-value
- * @param state state-value
- * @deprecated use putActivityState(...) instead
- */
@Deprecated
public void putTypedActivityState(TourActivity act, StateId stateId, Class type, T state){
if(stateId.getIndex()<10) throw new IllegalStateException("either you use a reserved stateId that is applied\n" +
@@ -415,6 +454,16 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
putInternalTypedActivityState(act, stateId, state);
}
+ /**
+ * Associates the specified activity and stateId to the state value. If a state value is already associated to the
+ * specified activity and stateId, it is replaced by the new state value.
+ *
+ * @param act the activity for which a state value is associated to
+ * @param stateId the stateId which is the associated key to the activity state
+ * @param state the state that is associated to the activity and stateId
+ * @param the type of the state
+ * @throws java.lang.IllegalStateException if stateId is equall to a stateId that is already used internally.
+ */
public void putActivityState(TourActivity act, StateId stateId, T state){
if(stateId.getIndex()<10) throw new IllegalStateException("either you use a reserved stateId that is applied\n" +
"internally or your stateId has been created without index, e.g. StateFactory.createId(stateName)\n" +
@@ -424,6 +473,17 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
putInternalTypedActivityState(act, stateId, state);
}
+ /**
+ * Associates the specified activity, vehicle and stateId to the state value. If a state value is already associated to the
+ * specified activity and stateId, it is replaced by the new state value.
+ *
+ * @param act the activity for which a state value is associated to
+ * @param vehicle the vehicle for which a state value is associated to
+ * @param stateId the stateId which is the associated key to the activity state
+ * @param state the state that is associated to the activity and stateId
+ * @param the type of the state
+ * @throws java.lang.IllegalStateException if stateId is equall to a stateId that is already used internally.
+ */
public void putActivityState(TourActivity act, Vehicle vehicle, StateId stateId, T state){
if(stateId.getIndex()<10) throw new IllegalStateException("either you use a reserved stateId that is applied\n" +
"internally or your stateId has been created without index, e.g. StateFactory.createId(stateName)\n" +
@@ -448,44 +508,37 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
vehicle_dependent_activity_states[act.getIndex()][vehicle.getVehicleTypeIdentifier().getIndex()][stateId.getIndex()]=state;
}
- /**
- * Generic method to memorize state 'state' of type 'type' of route and stateId.
- *
- * For example:
- * double totalRouteDuration = 100.0;
- * stateManager.putTypedActivityState(myRoute, StateFactory.createStateId("route-duration"), Double.class, totalRouteDuration);
- *
you can retrieve the duration of myRoute then by
- * double totalRouteDuration = stateManager.getRouteState(myRoute, StateFactory.createStateId("route-duration"), Double.class);
- *
- * @param route for which a state needs to be memorized
- * @param stateId stateId of the state value to identify it
- * @param type type of state
- * @param state state value
- * @deprecated use putRouteState(...) instead
- */
@Deprecated
public void putTypedRouteState(VehicleRoute route, StateId stateId, Class type, T state){
putRouteState(route, stateId, state);
}
/**
- * Generic method to memorize state 'state' of type 'type' of route and stateId.
+ * Associates the specified route, vehicle and stateId to the state value. If a state value is already associated to the
+ * specified activity and stateId, it is replaced by the new state value.
*
- * For example:
- * double totalRouteDuration = 100.0;
- * stateManager.putTypedActivityState(myRoute, StateFactory.createStateId("route-duration"), Double.class, totalRouteDuration);
- *
you can retrieve the duration of myRoute then by
- * double totalRouteDuration = stateManager.getRouteState(myRoute, StateFactory.createStateId("route-duration"), Double.class);
- *
- * @param route for which a state needs to be memorized
- * @param stateId stateId of the state value to identify it
- * @param state state value
+ * @param route the route for which a state value is associated to
+ * @param stateId the stateId which is the associated key to the activity state
+ * @param state the state that is associated to the activity and stateId
+ * @param the type of the state
+ * @throws java.lang.IllegalStateException if stateId is equall to a stateId that is already used internally.
*/
public void putRouteState(VehicleRoute route, StateId stateId, T state){
if(stateId.getIndex()<10) StateFactory.throwReservedIdException(stateId.toString());
putTypedInternalRouteState(route, stateId, state);
}
+ /**
+ * Associates the specified route, vehicle and stateId to the state value. If a state value is already associated to the
+ * specified activity and stateId, it is replaced by the new state value.
+ *
+ * @param route the route for which a state value is associated to
+ * @param vehicle the vehicle for which a state value is associated to
+ * @param stateId the stateId which is the associated key to the activity state
+ * @param state the state that is associated to the activity and stateId
+ * @param the type of the state
+ * @throws java.lang.IllegalStateException if stateId is equall to a stateId that is already used internally.
+ */
public void putRouteState(VehicleRoute route, Vehicle vehicle, StateId stateId, T state){
if(stateId.getIndex()<10) StateFactory.throwReservedIdException(stateId.toString());
putTypedInternalRouteState(route, vehicle, stateId, state);
@@ -521,9 +574,12 @@ public class StateManager implements RouteAndActivityStateGetter, IterationStart
if(updater instanceof RuinListener) addListener((RuinListener) updater);
updaters.add(updater);
}
-
-
-
+
+ /**
+ * Returns an unmodifiable collections of stateUpdaters that have been added to this stateManager.
+ *
+ * @return an unmodifiable collections of stateUpdaters that have been added to this stateManager.
+ */
Collection getStateUpdaters(){
return Collections.unmodifiableCollection(updaters);
}