Interface Context<T>
- All Superinterfaces:
Collection<T>
,Iterable<T>
,RepastElement
- All Known Subinterfaces:
SpatialContext<T,
V>
- All Known Implementing Classes:
AbstractContext
,AbstractSpatialContext
,DefaultContext
,FormerDefaultContext
,SmallDefaultContext
Context
ecapsulates
a population of agents.
A Context
may have one or more Projection
s associated with it to create a
relational structure on agents in the Context
.
Context
s may also contain multiple sub-Contexts as well as agents. Any number of
sub-Contexts may exist in a Context
. A Context
keeps a reference to its
parent, or containing Context
, if it exists.
The Context
interface contains methods that define Observer design pattern capability. This is
the capability for a Context
to allow listeners to register for future notifications
when certain events occur to the Context
. When one of these
- Author:
- Howe
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
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.findContext
(Object id) findParent
(Object o) getAgentLayer
(Class<T> agentType) getObjects
(Class<?> clazz) Gets a IndexedIterable over 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 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 contextquery
(org.apache.commons.collections15.Predicate query) Deprecated.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.void
Sets an id that indentifies the user-defined type of this context.Methods inherited from interface java.util.Collection
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, parallelStream, remove, removeAll, removeIf, retainAll, size, spliterator, stream, toArray, toArray, toArray
Methods inherited from interface repast.simphony.context.RepastElement
getId, setId
-
Field Details
-
SYN_CONTEXT_PREFIX
- See Also:
-
-
Method Details
-
query
Deprecated.UsegetObjectsAsStream(Class)
and the Java 8+ streaming APIStream
instead. -
getRandomObject
T getRandomObject()Gets an object in this context chosen at random from a uniform distribution.- Returns:
- an object in this context chosen at random from a uniform distribution.
-
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 fewer 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.
- 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
-
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 fewer 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.
- 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
-
getObjects
Gets a IndexedIterable over all the objects in this context (and thus in the sub contexts) that are of the specified type.- Parameters:
clazz
- the type of objects to return- Returns:
- a IndexedIterable over all the objects in this context (and thus in the sub contexts) that are of the specified type.
-
getObjectsAsStream
Gets a sequential Stream over all the objects in this context (and thus in the sub contexts) that are of the specified type.- Parameters:
clazz
- the type of objects to return- Returns:
- a Stream over all the objects in this context (and thus in the sub contexts) that are of the specified type.
-
getTypeID
Object 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".- Returns:
- an id that indentifies the user-defined type of this context.
-
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".- Parameters:
id
- the type id
-
getSubContexts
-
addSubContext
-
removeSubContext
-
getSubContext
-
findParent
-
findContext
-
getContextListeners
Collection<ContextListener<T>> getContextListeners() -
addContextListener
-
removeContextListener
-
getAgentLayer
-
getAgentTypes
-
hasSubContext
boolean hasSubContext()Method to check if subcontext(s) are present in the context- Returns:
- true if subcontext(s) are present and false if not
-
getProjection
Gets the named projection. This does not query subcontexts.- Parameters:
projection
- the type of the projectionname
- the name of the projection to get- Returns:
- the named projection.
-
getProjections
Gets all the projections in this Context of the specified type. This does not query subcontexts.- Parameters:
clazz
- the type of projections to get- Returns:
- all the projections in this Context of the specified type.
-
addProjection
Adds the specified Projection to this Context.- Parameters:
projection
- the projection to add
-
removeProjection
Removes the named projection from this Context.- Parameters:
projectionName
- the name projection to remove- Returns:
- the removed projection.
-
getProjection
Gets the named projection. This does not search subcontexts.- Parameters:
name
- the name of the projection to get- Returns:
- the named projection.
-
getProjections
Collection<Projection<?>> getProjections()Gets an iterable over all the projections contained by this Context.- Returns:
- an iterable over all the projections contained by this Context.
-
addValueLayer
Adds the specified ValueLayer to this Context.- Parameters:
valueLayer
- the ValueLayer to add
-
getValueLayer
Gets the named ValueLayer. This does not search subcontexts.- Parameters:
name
- the name of the ValueLayer to get- Returns:
- the named ValueLayer.
-
getValueLayers
Collection<ValueLayer> getValueLayers()Gets an iterable over the ValueLayer-s contained by this Context.- Returns:
- an iterable over the ValueLayer-s contained by this Context.
-
removeValueLayer
Removes the named ValueLayer from this Context.- Parameters:
name
- the name of the ValueLayer to remove.- Returns:
- the removed ValueLayer or null if the named ValueLayer was not found.
-
getObjectsAsStream(Class)
and the Java 8+ streaming APIStream
instead.