Package repast.simphony.context
Class AbstractContext<T>
java.lang.Object
java.util.AbstractCollection<T>
repast.simphony.context.AbstractContext<T>
- All Implemented Interfaces:
Iterable<T>,Collection<T>,Context<T>,ContextListener,RepastElement
- Direct Known Subclasses:
AbstractSpatialContext,SmallDefaultContext
public abstract class AbstractContext<T>
extends AbstractCollection<T>
implements Context<T>, ContextListener
Abstract base class implementation of the
Context interface.-
Field Summary
FieldsFields inherited from interface repast.simphony.context.Context
SYN_CONTEXT_PREFIX -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanvoidaddContextListener(ContextListener<T> listener) protected abstract booleanaddInternal(T o) voidaddProjection(Projection<? super T> projection) Adds the specified Projection to this Context.voidaddSubContext(Context<? extends T> context) voidaddValueLayer(ValueLayer valueLayer) Adds the specified ValueLayer to this Context.voidclear()booleanprotected abstract booleanvoidListener method for context events.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.protected voidprotected voidprotected voidfireSubContextAdded(Context<? extends T> context) protected voidfireSubContextRemoved(Context<? extends T> context) getAgentLayer(Class<T> agentType) getId()<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.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.protected booleanbooleanMethod to check if subcontext(s) are present in the contextiterator()By default the iterator returns in the contents in this context in the order entered then it returns the contents of the subcontexts in the order the subcontexts were added.query(org.apache.commons.collections15.Predicate query) final booleanvoidremoveContextListener(ContextListener<T> listener) protected abstract booleanProjection<? super T>removeProjection(String projectionName) Removes the named projection from this Context.voidremoveSubContext(Context<? extends T> context) removeValueLayer(String name) Removes the named ValueLayer from this Context.voidvoidSets an id that indentifies the user-defined type of this context.intsize()protected abstract intMethods inherited from class java.util.AbstractCollection
addAll, containsAll, isEmpty, removeAll, retainAll, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
addAll, containsAll, equals, hashCode, isEmpty, parallelStream, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArray, toArrayMethods inherited from interface repast.simphony.context.Context
getObjects, getObjectsAsStream, getRandomObject, getRandomObjects, getRandomObjectsAsStream
-
Field Details
-
subContexts
-
-
Constructor Details
-
AbstractContext
public AbstractContext()
-
-
Method Details
-
getId
- Specified by:
getIdin interfaceRepastElement
-
setId
- Specified by:
setIdin 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". -
addContextListener
- Specified by:
addContextListenerin interfaceContext<T>
-
getContextListeners
- Specified by:
getContextListenersin interfaceContext<T>
-
query
-
removeContextListener
- Specified by:
removeContextListenerin interfaceContext<T>
-
add
- Specified by:
addin interfaceCollection<T>- Overrides:
addin classAbstractCollection<T>
-
fireAddContextEvent
- Parameters:
o-
-
addInternal
-
containsInternal
-
contains
- Specified by:
containsin interfaceCollection<T>- Overrides:
containsin classAbstractCollection<T>
-
iterator
By default the iterator returns in the contents in this context in the order entered then it returns the contents of the subcontexts in the order the subcontexts were added.- Specified by:
iteratorin interfaceCollection<T>- Specified by:
iteratorin interfaceIterable<T>- Specified by:
iteratorin classAbstractCollection<T>
-
iteratorInternal
-
eventOccured
Listener method for context events. This is primiarly used to receive ContextEvents from a subcontext and pass them on to this context's own listeners.- Specified by:
eventOccuredin interfaceContextListener<T>- Parameters:
ev-
-
addSubContext
- Specified by:
addSubContextin interfaceContext<T>
-
hasSubContext
public boolean hasSubContext()Description copied from interface:ContextMethod to check if subcontext(s) are present in the context- Specified by:
hasSubContextin interfaceContext<T>- Returns:
- true if subcontext(s) are present and false if not
-
getSubContexts
- Specified by:
getSubContextsin interfaceContext<T>
-
removeSubContext
- Specified by:
removeSubContextin interfaceContext<T>
-
remove
- Specified by:
removein interfaceCollection<T>- Overrides:
removein classAbstractCollection<T>
-
clear
public void clear()- Specified by:
clearin interfaceCollection<T>- Overrides:
clearin classAbstractCollection<T>
-
handleRemove
-
fireRemoveEvent
-
fireSubContextAdded
-
fireSubContextRemoved
-
removeInternal
-
size
public int size()- Specified by:
sizein interfaceCollection<T>- Specified by:
sizein classAbstractCollection<T>
-
sizeInternal
protected abstract int sizeInternal() -
getSubContext
- Specified by:
getSubContextin 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:
findParentin 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:
findContextin 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
-
getAgentTypes
- Specified by:
getAgentTypesin interfaceContext<T>
-
getAgentLayer
- Specified by:
getAgentLayerin interfaceContext<T>
-
getProjection
Description copied from interface:ContextGets the named projection. This does not query subcontexts.- Specified by:
getProjectionin 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:ContextGets all the projections in this Context of the specified type. This does not query subcontexts.- Specified by:
getProjectionsin interfaceContext<T>- Parameters:
clazz- the type of projections to get- Returns:
- all the projections in this Context of the specified type.
-
getProjection
Description copied from interface:ContextGets the named projection. This does not search subcontexts.- Specified by:
getProjectionin interfaceContext<T>- Parameters:
name- the name of the projection to get- Returns:
- the named projection.
-
addProjection
Description copied from interface:ContextAdds the specified Projection to this Context.- Specified by:
addProjectionin interfaceContext<T>- Parameters:
projection- the projection to add
-
removeProjection
Removes the named projection from this Context.- Specified by:
removeProjectionin interfaceContext<T>- Parameters:
projectionName- the name projection to remove- Returns:
- the removed projection.
-
getProjections
Gets an iterable over all the projections contained by this Context.- Specified by:
getProjectionsin interfaceContext<T>- Returns:
- an iterable over all the projections contained by this Context.
-
addValueLayer
Adds the specified ValueLayer to this Context.- Specified by:
addValueLayerin interfaceContext<T>- Parameters:
valueLayer- the ValueLayer to add
-
removeValueLayer
Removes the named ValueLayer from this Context.- Specified by:
removeValueLayerin interfaceContext<T>- Parameters:
name- the name of the ValueLayer to remove.- Returns:
- the removed ValueLayer or null if the named ValueLayer was not found.
-
getValueLayers
Gets an iterable over the ValueLayer-s contained by this Context.- Specified by:
getValueLayersin interfaceContext<T>- Returns:
- an iterable over the ValueLayer-s contained by this Context.
-
getValueLayer
Gets the named ValueLayer. This does not search subcontexts.- Specified by:
getValueLayerin interfaceContext<T>- Parameters:
name- the name of the ValueLayer to get- Returns:
- the named ValueLayer.
-