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>
  • Field Details

  • Constructor Details

  • Method Details

    • addContextListener

      public void addContextListener(ContextListener<T> listener)
      Specified by:
      addContextListener in interface Context<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 interface Context<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 interface Context<T>
      Parameters:
      projectionName - the name projection to remove
      Returns:
      the removed projection.
    • addSubContext

      public void addSubContext(Context<? extends T> context)
      Specified by:
      addSubContext in interface Context<T>
    • getAgentLayer

      public Iterable<T> getAgentLayer(Class<T> agentType)
      Specified by:
      getAgentLayer in interface Context<T>
    • getAgentTypes

      public Iterable<Class> getAgentTypes()
      Specified by:
      getAgentTypes in interface Context<T>
    • getContextListeners

      public Collection<ContextListener<T>> getContextListeners()
      Specified by:
      getContextListeners in interface Context<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 interface Context<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 interface Context<T>
      Parameters:
      projection - the type of the projection
      name - 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 interface Context<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 interface Context<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 interface Context<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 interface Context<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 interface Context<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 interface Context<T>
    • query

      public Iterable<T> query(org.apache.commons.collections15.Predicate query)
      Specified by:
      query in interface Context<T>
    • removeContextListener

      public void removeContextListener(ContextListener<T> listener)
      Specified by:
      removeContextListener in interface Context<T>
    • removeSubContext

      public void removeSubContext(Context<? extends T> context)
      Specified by:
      removeSubContext in interface Context<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 interface Context<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 interface Context<T>
      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
    • getRandomObject

      public T getRandomObject()
      Gets an object in this context chosen at random from a uniform distribution.
      Specified by:
      getRandomObject in interface Context<T>
      Returns:
      an object in this context chosen at random from a uniform distribution.
    • getId

      public Object getId()
      Specified by:
      getId in interface RepastElement
    • setId

      public void setId(Object id)
      Specified by:
      setId in interface RepastElement
    • 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".
      Specified by:
      getTypeID in interface Context<T>
      Returns:
      an id that indentifies the user-defined type of this context.
    • 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".
      Specified by:
      setTypeID in interface Context<T>
      Parameters:
      id - the type id
    • clear

      public void clear()
      Specified by:
      clear in interface Collection<T>
    • contains

      public boolean contains(Object o)
      Specified by:
      contains in interface Collection<T>
    • containsAll

      public boolean containsAll(Collection<?> c)
      Specified by:
      containsAll in interface Collection<T>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Collection<T>
    • iterator

      public Iterator<T> iterator()
      Specified by:
      iterator in interface Collection<T>
      Specified by:
      iterator in interface Iterable<T>
    • remove

      public boolean remove(Object o)
      Specified by:
      remove in interface Collection<T>
    • removeAll

      public boolean removeAll(Collection<?> c)
      Specified by:
      removeAll in interface Collection<T>
    • retainAll

      public boolean retainAll(Collection<?> c)
      Specified by:
      retainAll in interface Collection<T>
    • size

      public int size()
      Specified by:
      size in interface Collection<T>
    • toArray

      public Object[] toArray()
      Specified by:
      toArray in interface Collection<T>
    • toArray

      public <U> U[] toArray(U[] a)
      Specified by:
      toArray in interface Collection<T>
    • add

      public boolean add(T o)
      Specified by:
      add in interface Collection<T>
    • addAll

      public boolean addAll(Collection<? extends T> collection)
      Specified by:
      addAll in interface Collection<T>
    • addValueLayer

      public void addValueLayer(ValueLayer valueLayer)
      Adds the specified ValueLayer to this Context.
      Specified by:
      addValueLayer in interface Context<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 interface Context<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 interface Context<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 interface Context<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 interface Context<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 interface Context<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 interface Context<T>
      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