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
public class FormerDefaultContext<T> extends Object implements Context<T>
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FormerDefaultContext.ContextHint
-
Field Summary
Fields Modifier and Type Field Description protected Context<T>
delegate
protected FormerDefaultContext.ContextHint
hint
-
Fields inherited from interface repast.simphony.context.Context
SYN_CONTEXT_PREFIX
-
-
Constructor Summary
Constructors Constructor Description FormerDefaultContext()
FormerDefaultContext(Object name)
FormerDefaultContext(Object name, Object typeID)
FormerDefaultContext(Object name, Object typeID, FormerDefaultContext.ContextHint hint)
FormerDefaultContext(Object name, FormerDefaultContext.ContextHint hint)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(T o)
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
contains(Object o)
boolean
containsAll(Collection<?> c)
Context
findContext(Object id)
This searches the specified context and its descendants for the context with the specified id.Context
findParent(Object o)
Retrieves the context of the specified object starting with the specified Context.Iterable<T>
getAgentLayer(Class<T> agentType)
Iterable<Class>
getAgentTypes()
Collection<ContextListener<T>>
getContextListeners()
Object
getId()
IndexedIterable<T>
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.Stream<T>
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<?>>
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 contextboolean
isEmpty()
Iterator<T>
iterator()
Iterable<T>
query(org.apache.commons.collections15.Predicate query)
boolean
remove(Object o)
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)
ValueLayer
removeValueLayer(String name)
Removes the named ValueLayer from this Context.boolean
retainAll(Collection<?> c)
void
setId(Object id)
void
setTypeID(Object id)
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 Detail
-
hint
protected transient FormerDefaultContext.ContextHint hint
-
-
Constructor Detail
-
FormerDefaultContext
public FormerDefaultContext()
-
FormerDefaultContext
public FormerDefaultContext(Object name)
-
FormerDefaultContext
public FormerDefaultContext(Object name, FormerDefaultContext.ContextHint hint)
-
FormerDefaultContext
public FormerDefaultContext(Object name, Object typeID, FormerDefaultContext.ContextHint hint)
-
-
Method Detail
-
addContextListener
public void addContextListener(ContextListener<T> listener)
- Specified by:
addContextListener
in interfaceContext<T>
-
addProjection
public void addProjection(Projection<? super T> projection)
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
public Projection<? super T> removeProjection(String projectionName)
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
public void addSubContext(Context<? extends T> context)
- Specified by:
addSubContext
in interfaceContext<T>
-
getAgentLayer
public Iterable<T> getAgentLayer(Class<T> agentType)
- Specified by:
getAgentLayer
in interfaceContext<T>
-
getAgentTypes
public Iterable<Class> getAgentTypes()
- Specified by:
getAgentTypes
in interfaceContext<T>
-
getContextListeners
public Collection<ContextListener<T>> getContextListeners()
- Specified by:
getContextListeners
in interfaceContext<T>
-
getProjection
public Projection<?> getProjection(String name)
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
public <X extends Projection<?>> X getProjection(Class<X> projection, String name)
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
public Collection<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
public <X extends Projection<?>> Iterable<X> getProjections(Class<X> clazz)
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
public Context<? extends T> getSubContext(Object id)
- Specified by:
getSubContext
in interfaceContext<T>
-
findParent
public Context findParent(Object o)
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
public Context findContext(Object id)
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
public Iterable<Context<? extends T>> getSubContexts()
- Specified by:
getSubContexts
in interfaceContext<T>
-
removeContextListener
public void removeContextListener(ContextListener<T> listener)
- Specified by:
removeContextListener
in interfaceContext<T>
-
removeSubContext
public void removeSubContext(Context<? extends T> context)
- Specified by:
removeSubContext
in interfaceContext<T>
-
getObjects
public IndexedIterable<T> 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.- 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
public 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 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
public T 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
public Object getId()
- Specified by:
getId
in interfaceRepastElement
-
setId
public void setId(Object id)
- Specified by:
setId
in interfaceRepastElement
-
getTypeID
public 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".
-
setTypeID
public 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".
-
clear
public void clear()
- Specified by:
clear
in interfaceCollection<T>
-
contains
public boolean contains(Object o)
- Specified by:
contains
in interfaceCollection<T>
-
containsAll
public boolean containsAll(Collection<?> c)
- Specified by:
containsAll
in interfaceCollection<T>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfaceCollection<T>
-
remove
public boolean remove(Object o)
- Specified by:
remove
in interfaceCollection<T>
-
removeAll
public boolean removeAll(Collection<?> c)
- Specified by:
removeAll
in interfaceCollection<T>
-
retainAll
public boolean retainAll(Collection<?> c)
- Specified by:
retainAll
in interfaceCollection<T>
-
size
public int size()
- Specified by:
size
in interfaceCollection<T>
-
toArray
public Object[] toArray()
- Specified by:
toArray
in interfaceCollection<T>
-
toArray
public <U> U[] toArray(U[] a)
- Specified by:
toArray
in interfaceCollection<T>
-
add
public boolean add(T o)
- Specified by:
add
in interfaceCollection<T>
-
addAll
public boolean addAll(Collection<? extends T> collection)
- Specified by:
addAll
in interfaceCollection<T>
-
addValueLayer
public void addValueLayer(ValueLayer valueLayer)
Adds the specified ValueLayer to this Context.- Specified by:
addValueLayer
in interfaceContext<T>
- Parameters:
valueLayer
- the ValueLayer to add
-
getValueLayer
public ValueLayer getValueLayer(String name)
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
public Collection<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
public ValueLayer removeValueLayer(String name)
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
public Stream<T> 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.- 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
public 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 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
-
-