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
public interface Context<T> extends Collection<T>, RepastElement
Represents a group of agents that participate in a simulation. AContext
ecapsulates a population of agents.A
Context
may have one or moreProjection
s associated with it to create a relational structure on agents in theContext
.Context
s may also contain multiple sub-Contexts as well as agents. Any number of sub-Contexts may exist in aContext
. AContext
keeps a reference to its parent, or containingContext
, if it exists.The
Context
interface contains methods that define Observer design pattern capability. This is the capability for aContext
to allow listeners to register for future notifications when certain events occur to theContext
. When one of these- Author:
- Howe
-
-
Field Summary
Fields Modifier and Type Field Description static String
SYN_CONTEXT_PREFIX
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description 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.Context
findContext(Object id)
Context
findParent(Object o)
Iterable<T>
getAgentLayer(Class<T> agentType)
Iterable<Class>
getAgentTypes()
Collection<ContextListener<T>>
getContextListeners()
IndexedIterable<T>
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.Stream<T>
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<?>>
getProjections()
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.T
getRandomObject()
Gets an object in this context chosen at random from a uniform distribution.Iterable<T>
getRandomObjects(Class<? extends T> clazz, long count)
Gets an iterable over a collection of objects chosen at random.Stream<T>
getRandomObjectsAsStream(Class<? extends T> clazz, long count)
Gets a sequential Stream over a collection of objects chosen at random.Context<? extends T>
getSubContext(Object id)
Iterable<Context<? extends T>>
getSubContexts()
Object
getTypeID()
Gets an id that indentifies the user-defined type of this context.ValueLayer
getValueLayer(String name)
Gets the named ValueLayer.Collection<ValueLayer>
getValueLayers()
Gets an iterable over the ValueLayer-s contained by this Context.boolean
hasSubContext()
Method to check if subcontext(s) are present in the contextIterable<T>
query(org.apache.commons.collections15.Predicate query)
Deprecated.UsegetObjectsAsStream(Class)
and the Java 8+ streaming APIStream
instead.void
removeContextListener(ContextListener<T> listener)
Projection<? super T>
removeProjection(String projectionName)
Removes the named projection from this Context.void
removeSubContext(Context<? extends T> context)
ValueLayer
removeValueLayer(String name)
Removes the named ValueLayer from this Context.void
setTypeID(Object id)
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 Detail
-
SYN_CONTEXT_PREFIX
static final String SYN_CONTEXT_PREFIX
- See Also:
- Constant Field Values
-
-
Method Detail
-
query
@Deprecated Iterable<T> query(org.apache.commons.collections15.Predicate 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
Iterable<T> getRandomObjects(Class<? extends T> clazz, long count)
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
Stream<T> getRandomObjectsAsStream(Class<? extends T> clazz, long count)
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
IndexedIterable<T> 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.- 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
Stream<T> 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.- 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
void setTypeID(Object id)
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
-
getContextListeners
Collection<ContextListener<T>> getContextListeners()
-
addContextListener
void addContextListener(ContextListener<T> listener)
-
removeContextListener
void removeContextListener(ContextListener<T> listener)
-
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
<X extends Projection<?>> X getProjection(Class<X> projection, String name)
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
<X extends Projection<?>> Iterable<X> getProjections(Class<X> clazz)
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
void addProjection(Projection<? super T> projection)
Adds the specified Projection to this Context.- Parameters:
projection
- the projection to add
-
removeProjection
Projection<? super T> removeProjection(String projectionName)
Removes the named projection from this Context.- Parameters:
projectionName
- the name projection to remove- Returns:
- the removed projection.
-
getProjection
Projection<?> getProjection(String name)
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
void addValueLayer(ValueLayer valueLayer)
Adds the specified ValueLayer to this Context.- Parameters:
valueLayer
- the ValueLayer to add
-
getValueLayer
ValueLayer getValueLayer(String name)
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
ValueLayer removeValueLayer(String name)
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.
-
-