public class GenericOOState extends java.lang.Object implements MutableOOState
OOState. Stores the set of ObjectInstances with a map from
the object name to the instance as well as a list of lists, organizing objects by their object class.
The copy() operation will copy the collections, but not the actual ObjectInstance they hold;
therefore, this is a ShallowCopyState. If you want to modify the values of an ObjectInstance
in this state and the state is copied from another state, then you should retrieve the object with the
touch(String) method, will update this state's instance of that object with a copy of it and return you
the copy that can be safely modified. This object's set(Object, Object) method and other mutable
methods will also perform safe copy-on-write operations.| Modifier and Type | Field and Description |
|---|---|
protected java.util.Map<java.lang.String,java.util.List<ObjectInstance>> |
objectsByClass |
protected java.util.Map<java.lang.String,ObjectInstance> |
objectsMap |
| Constructor and Description |
|---|
GenericOOState() |
GenericOOState(ObjectInstance... objects) |
GenericOOState(OOState srcOOState) |
| Modifier and Type | Method and Description |
|---|---|
MutableOOState |
addObject(ObjectInstance o)
Adds object instance o to this state.
|
GenericOOState |
copy()
Returns a copy of this state suitable for creating state transitions.
|
java.lang.Object |
get(java.lang.Object variableKey)
Returns the value for the given variable key.
|
java.util.Map<java.lang.String,java.util.List<ObjectInstance>> |
getObjectsByClass()
Getter method for underlying data to support serialization.
|
java.util.Map<java.lang.String,ObjectInstance> |
getObjectsMap()
Getter method for underlying data to support serialization.
|
protected java.util.List<ObjectInstance> |
getOrGenerateObjectClassList(java.lang.String className) |
int |
numObjects()
Returns the number of object instances in this state.
|
ObjectInstance |
object(java.lang.String oname)
Returns the object in this state with the name oname
|
java.util.List<ObjectInstance> |
objects()
Returns the list of object instances in this state.
|
java.util.List<ObjectInstance> |
objectsOfClass(java.lang.String oclass)
Returns all objects that belong to the object class named oclass
|
MutableOOState |
removeObject(java.lang.String oname)
Removes the object instance with the name oname from this state.
|
MutableOOState |
renameObject(java.lang.String objectName,
java.lang.String newName)
Renames the identifier for object instance o in this state to newName.
|
MutableState |
set(java.lang.Object variableKey,
java.lang.Object value)
Sets the value for the given variable key.
|
void |
setObjectsByClass(java.util.Map<java.lang.String,java.util.List<ObjectInstance>> objectsByClass)
Setter method for underlying data to support serialization
|
void |
setObjectsMap(java.util.Map<java.lang.String,ObjectInstance> objectsMap)
Setter method for underlying data to support serialization
|
java.lang.String |
toString() |
ObjectInstance |
touch(java.lang.String obname)
Copies the object with the given name, and updates its index in this state.
|
java.util.List<java.lang.Object> |
variableKeys()
Returns the list of state variable keys.
|
protected java.util.Map<java.lang.String,java.util.List<ObjectInstance>> objectsByClass
protected java.util.Map<java.lang.String,ObjectInstance> objectsMap
public GenericOOState()
public GenericOOState(OOState srcOOState)
public GenericOOState(ObjectInstance... objects)
public java.util.List<java.lang.Object> variableKeys()
StatevariableKeys in interface Statepublic java.lang.Object get(java.lang.Object variableKey)
Statepublic MutableState set(java.lang.Object variableKey, java.lang.Object value)
MutableStateset in interface MutableStatevariableKey - the key identifier for the variable value to changevalue - the variable value to which the variable should be set.public GenericOOState copy()
StateDeepCopyState or ShallowCopyState annotations. If it is a shallow copy, you should not *directly*
modify any fields of a copied state without copying the fields first, or it could contaminate the state from
which the copy was made. Alternatively, use the MutableState.set(Object, Object) method to modify
ShallowCopyState copied states,
which for ShallowCopyState instances should perform a safe copy-on-write operation.public MutableOOState addObject(ObjectInstance o)
MutableOOStateaddObject in interface MutableOOStateo - the object instance to be added to this state.public MutableOOState removeObject(java.lang.String oname)
MutableOOStateremoveObject in interface MutableOOStateoname - the name of the object instance to remove.public MutableOOState renameObject(java.lang.String objectName, java.lang.String newName)
MutableOOStaterenameObject in interface MutableOOStateobjectName - the current object namenewName - the new name of the object instancepublic int numObjects()
OOStatenumObjects in interface OOStatepublic ObjectInstance object(java.lang.String oname)
OOStatepublic java.util.List<ObjectInstance> objects()
OOStatepublic java.util.List<ObjectInstance> objectsOfClass(java.lang.String oclass)
OOStateobjectsOfClass in interface OOStateoclass - the name of the object class for which objects should be returnedpublic java.lang.String toString()
toString in class java.lang.Objectpublic ObjectInstance touch(java.lang.String obname)
ObjectInstance to ensure that you do not contaminate any states
from which this state was copied.obname - the name of the object to be modified.ObjectInstance with the given name. Null if this state contains no object with that namepublic java.util.Map<java.lang.String,java.util.List<ObjectInstance>> getObjectsByClass()
ObjectInstance objects for objects in this state.public void setObjectsByClass(java.util.Map<java.lang.String,java.util.List<ObjectInstance>> objectsByClass)
objectsByClass - the underlying Map from class names to ObjectInstance objects for objects in this state.public java.util.Map<java.lang.String,ObjectInstance> getObjectsMap()
ObjectInstance objects for objects in this state.public void setObjectsMap(java.util.Map<java.lang.String,ObjectInstance> objectsMap)
objectsMap - the underlying Map from object names to ObjectInstance objects for objects in this state.protected java.util.List<ObjectInstance> getOrGenerateObjectClassList(java.lang.String className)