Package repast.simphony.context
Class FormerDefaultContext<T>
java.lang.Object
repast.simphony.context.FormerDefaultContext<T>
- All Implemented Interfaces:
Iterable<T>
,Collection<T>
,Context<T>
,RepastElement
-
Nested Class Summary
-
Field Summary
Fields inherited from interface repast.simphony.context.Context
SYN_CONTEXT_PREFIX
-
Constructor Summary
ConstructorDescriptionFormerDefaultContext
(Object name) FormerDefaultContext
(Object name, Object typeID) FormerDefaultContext
(Object name, Object typeID, FormerDefaultContext.ContextHint hint) -
Method Summary
Modifier and TypeMethodDescriptionboolean
boolean
addAll
(Collection<? extends T> collection) void
addContextListener
(ContextListener<T> listener) void
addProjection
(Projection<? super T> projection) Adds the specified Projection to this Context.void
addSubContext
(Context<? extends T> context) void
addValueLayer
(ValueLayer valueLayer) Adds the specified ValueLayer to this Context.void
clear()
boolean
boolean
containsAll
(Collection<?> c) findContext
(Object id) This searches the specified context and its descendants for the context with the specified id.findParent
(Object o) Retrieves the context of the specified object starting with the specified Context.getAgentLayer
(Class<T> agentType) getId()
getObjects
(Class<?> clazz) Gets a IndexedIterable over the all the objects in this context (and thus in the sub contexts) that are of the specified type.getObjectsAsStream
(Class<?> clazz) Gets a sequential Stream over the all the objects in this context (and thus in the sub contexts) that are of the specified type.<X extends Projection<?>>
XgetProjection
(Class<X> projection, String name) Gets the named projection.Projection<?>
getProjection
(String name) Gets the named projection.Collection<Projection<?>>
Gets an iterable over all the projections contained by this Context.<X extends Projection<?>>
Iterable<X>getProjections
(Class<X> clazz) Gets all the projections in this Context of the specified type.Gets an object in this context chosen at random from a uniform distribution.getRandomObjects
(Class<? extends T> clazz, long count) Gets an iterable over a collection of objects chosen at random.getRandomObjectsAsStream
(Class<? extends T> clazz, long count) Gets a sequential Stream over a collection of objects chosen at random.getSubContext
(Object id) Gets an id that indentifies the user-defined type of this context.getValueLayer
(String name) Gets the named ValueLayer.Gets an iterable over the ValueLayer-s contained by this Context.boolean
Method to check if subcontext(s) are present in the contextboolean
isEmpty()
iterator()
query
(org.apache.commons.collections15.Predicate query) boolean
boolean
removeAll
(Collection<?> c) void
removeContextListener
(ContextListener<T> listener) Projection<? super T>
removeProjection
(String projectionName) Removes the named projection from this Context.void
removeSubContext
(Context<? extends T> context) removeValueLayer
(String name) Removes the named ValueLayer from this Context.boolean
retainAll
(Collection<?> c) void
void
Sets an id that indentifies the user-defined type of this context.int
size()
Object[]
toArray()
<U> U[]
toArray
(U[] a) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Collection
equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray
-
Field Details
-
hint
-
delegate
-
-
Constructor Details
-
FormerDefaultContext
public FormerDefaultContext() -
FormerDefaultContext
-
FormerDefaultContext
-
FormerDefaultContext
-
FormerDefaultContext
-
-
Method Details
-
addContextListener
- Specified by:
addContextListener
in interfaceContext<T>
-
addProjection
Description copied from interface:Context
Adds the specified Projection to this Context.- Specified by:
addProjection
in interfaceContext<T>
- Parameters:
projection
- the projection to add
-
removeProjection
Removes the named projection from this Context.- Specified by:
removeProjection
in interfaceContext<T>
- Parameters:
projectionName
- the name projection to remove- Returns:
- the removed projection.
-
addSubContext
- Specified by:
addSubContext
in interfaceContext<T>
-
getAgentLayer
- Specified by:
getAgentLayer
in interfaceContext<T>
-
getAgentTypes
- Specified by:
getAgentTypes
in interfaceContext<T>
-
getContextListeners
- Specified by:
getContextListeners
in interfaceContext<T>
-
getProjection
Description copied from interface:Context
Gets the named projection. This does not search subcontexts.- Specified by:
getProjection
in interfaceContext<T>
- Parameters:
name
- the name of the projection to get- Returns:
- the named projection.
-
getProjection
Description copied from interface:Context
Gets the named projection. This does not query subcontexts.- Specified by:
getProjection
in interfaceContext<T>
- Parameters:
projection
- the type of the projectionname
- the name of the projection to get- Returns:
- the named projection.
-
getProjections
Description copied from interface:Context
Gets an iterable over all the projections contained by this Context.- Specified by:
getProjections
in interfaceContext<T>
- Returns:
- an iterable over all the projections contained by this Context.
-
getProjections
Description copied from interface:Context
Gets all the projections in this Context of the specified type. This does not query subcontexts.- Specified by:
getProjections
in interfaceContext<T>
- Parameters:
clazz
- the type of projections to get- Returns:
- all the projections in this Context of the specified type.
-
getSubContext
- Specified by:
getSubContext
in interfaceContext<T>
-
findParent
Retrieves the context of the specified object starting with the specified Context. This will traverse into the specified context's sub contexts until it finds the lowest level context the object is in.- Specified by:
findParent
in interfaceContext<T>
- Parameters:
o
- an object to find in the contexts- Returns:
- the context that contains the object
-
findContext
This searches the specified context and its descendants for the context with the specified id. This searches through the contexts in a breadth-first manner, and will return the first context whose getId() method returns the specified id. This includes the start context.- Specified by:
findContext
in interfaceContext<T>
- Parameters:
id
- the id of the context to search for- Returns:
- the first context found with the given id, or null if no context is found
-
getSubContexts
- Specified by:
getSubContexts
in interfaceContext<T>
-
query
-
removeContextListener
- Specified by:
removeContextListener
in interfaceContext<T>
-
removeSubContext
- Specified by:
removeSubContext
in interfaceContext<T>
-
getObjects
Gets a IndexedIterable over the all the objects in this context (and thus in the sub contexts) that are of the specified type.- Specified by:
getObjects
in interfaceContext<T>
- Parameters:
clazz
- the type of objects to return- Returns:
- a IndexedIterable over the all the objects in this context (and thus in the sub contexts) that are of the specified type.
-
getRandomObjects
Gets an iterable over a collection of objects chosen at random. The number of objects is determined by the specified count and the type of objects by the specified class. If the context contains less objects than the specified count, all the appropriate objects in the context will be returned. If this is repeatedly called with a count equal to the number of objects in the context, the iteration order will be shuffled each time.- Specified by:
getRandomObjects
in interfaceContext<T>
- Parameters:
clazz
- the class of the objects to returncount
- the number of random objects to return- Returns:
- an iterable over a collection of random objects
-
getRandomObject
Gets an object in this context chosen at random from a uniform distribution.- Specified by:
getRandomObject
in interfaceContext<T>
- Returns:
- an object in this context chosen at random from a uniform distribution.
-
getId
- Specified by:
getId
in interfaceRepastElement
-
setId
- Specified by:
setId
in interfaceRepastElement
-
getTypeID
Gets an id that indentifies the user-defined type of this context. A context type typically refers to the role the context plays in a particular model. For example, the type of the context may be "School" and the agents in that context would be "Pupils". -
setTypeID
Sets an id that indentifies the user-defined type of this context. A context type typically refers to the role the context plays in a particular model. For example, the type of the context may be "School" and the agents in that context would be "Pupils". -
clear
public void clear()- Specified by:
clear
in interfaceCollection<T>
-
contains
- Specified by:
contains
in interfaceCollection<T>
-
containsAll
- Specified by:
containsAll
in interfaceCollection<T>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmpty
in interfaceCollection<T>
-
iterator
-
remove
- Specified by:
remove
in interfaceCollection<T>
-
removeAll
- Specified by:
removeAll
in interfaceCollection<T>
-
retainAll
- Specified by:
retainAll
in interfaceCollection<T>
-
size
public int size()- Specified by:
size
in interfaceCollection<T>
-
toArray
- Specified by:
toArray
in interfaceCollection<T>
-
toArray
public <U> U[] toArray(U[] a) - Specified by:
toArray
in interfaceCollection<T>
-
add
- Specified by:
add
in interfaceCollection<T>
-
addAll
- Specified by:
addAll
in interfaceCollection<T>
-
addValueLayer
Adds the specified ValueLayer to this Context.- Specified by:
addValueLayer
in interfaceContext<T>
- Parameters:
valueLayer
- the ValueLayer to add
-
getValueLayer
Gets the named ValueLayer. This does not search subcontexts.- Specified by:
getValueLayer
in interfaceContext<T>
- Parameters:
name
- the name of the ValueLayer to get- Returns:
- the named ValueLayer.
-
getValueLayers
Gets an iterable over the ValueLayer-s contained by this Context.- Specified by:
getValueLayers
in interfaceContext<T>
- Returns:
- an iterable over the ValueLayer-s contained by this Context.
-
removeValueLayer
Removes the named ValueLayer from this Context.- Specified by:
removeValueLayer
in interfaceContext<T>
- Parameters:
name
- the name of the ValueLayer to remove.- Returns:
- the removed ValueLayer or null if the named ValueLayer was not found.
-
hasSubContext
public boolean hasSubContext()Description copied from interface:Context
Method to check if subcontext(s) are present in the context- Specified by:
hasSubContext
in interfaceContext<T>
- Returns:
- true if subcontext(s) are present and false if not
-
getObjectsAsStream
Gets a sequential Stream over the all the objects in this context (and thus in the sub contexts) that are of the specified type.- Specified by:
getObjectsAsStream
in interfaceContext<T>
- Parameters:
clazz
- the type of objects to return- Returns:
- a Stream over the all the objects in this context (and thus in the sub contexts) that are of the specified type.
-
getRandomObjectsAsStream
Gets a sequential Stream over a collection of objects chosen at random. The number of objects is determined by the specified count and the type of objects by the specified class. If the context contains less objects than the specified count, all the appropriate objects in the context will be returned.If this is repeatedly called with a count equal to the number of objects in the context, the iteration order will be shuffled each time.
- Specified by:
getRandomObjectsAsStream
in interfaceContext<T>
- Parameters:
clazz
- the class of the objects to returncount
- the number of random objects to return- Returns:
- a sequential Stream over a collection of random objects
-