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. A Context ecapsulates a population of agents.

A Context may have one or more Projections associated with it to create a relational structure on agents in the Context.

Contexts 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 Details

  • Method Details

    • query

      @Deprecated Iterable<T> query(org.apache.commons.collections15.Predicate query)
      Deprecated.
      Use getObjectsAsStream(Class) and the Java 8+ streaming API Stream 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 return
      count - 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 return
      count - 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
    • getSubContexts

      Iterable<Context<? extends T>> getSubContexts()
    • addSubContext

      void addSubContext(Context<? extends T> context)
    • removeSubContext

      void removeSubContext(Context<? extends T> context)
    • getSubContext

      Context<? extends T> getSubContext(Object id)
    • findParent

      Context findParent(Object o)
    • findContext

      Context findContext(Object id)
    • getContextListeners

      Collection<ContextListener<T>> getContextListeners()
    • addContextListener

      void addContextListener(ContextListener<T> listener)
    • removeContextListener

      void removeContextListener(ContextListener<T> listener)
    • getAgentLayer

      Iterable<T> getAgentLayer(Class<T> agentType)
    • getAgentTypes

      Iterable<Class> 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

      <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 projection
      name - 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.