repast.simphony.context
Class SmallDefaultContext<T>

java.lang.Object
  extended by java.util.AbstractCollection<T>
      extended by repast.simphony.context.AbstractContext<T>
          extended by repast.simphony.context.SmallDefaultContext<T>
All Implemented Interfaces:
Iterable<T>, Collection<T>, Context<T>, ContextListener, RepastElement
Direct Known Subclasses:
DefaultContext

public class SmallDefaultContext<T>
extends AbstractContext<T>


Field Summary
protected  IndexedIterable allObjs
           
protected  Map<Class,List<T>> objectMap
           
 
Fields inherited from class repast.simphony.context.AbstractContext
subContexts
 
Fields inherited from interface repast.simphony.context.Context
SYN_CONTEXT_PREFIX
 
Constructor Summary
SmallDefaultContext()
           
SmallDefaultContext(Object id)
           
SmallDefaultContext(Object name, Object typeID)
           
 
Method Summary
protected  boolean addInternal(T o)
           
protected  boolean containsInternal(Object o)
           
 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.
 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.
protected  Iterator<T> iteratorInternal()
           
 boolean removeAll(Collection<?> c)
           
protected  boolean removeInternal(Object obj)
           
 boolean retainAll(Collection<?> c)
           
protected  int sizeInternal()
           
 
Methods inherited from class repast.simphony.context.AbstractContext
add, addContextListener, addProjection, addSubContext, addValueLayer, clear, contains, eventOccured, findContext, findParent, fireAddContextEvent, fireRemoveEvent, fireSubContextAdded, fireSubContextRemoved, getAgentLayer, getAgentTypes, getContextListeners, getId, getProjection, getProjection, getProjections, getProjections, getSubContext, getSubContexts, getTypeID, getValueLayer, getValueLayers, handleRemove, hasSubContext, iterator, query, remove, removeContextListener, removeProjection, removeSubContext, removeValueLayer, setId, setTypeID, size
 
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, isEmpty, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Collection
addAll, containsAll, equals, hashCode, isEmpty, toArray, toArray
 

Field Detail

objectMap

protected Map<Class,List<T>> objectMap

allObjs

protected IndexedIterable allObjs
Constructor Detail

SmallDefaultContext

public SmallDefaultContext()

SmallDefaultContext

public SmallDefaultContext(Object id)

SmallDefaultContext

public SmallDefaultContext(Object name,
                           Object typeID)
Method Detail

containsInternal

protected boolean containsInternal(Object o)
Specified by:
containsInternal in class AbstractContext<T>

iteratorInternal

protected Iterator<T> iteratorInternal()
Specified by:
iteratorInternal in class AbstractContext<T>

sizeInternal

protected int sizeInternal()
Specified by:
sizeInternal in class AbstractContext<T>

addInternal

protected boolean addInternal(T o)
Specified by:
addInternal in class AbstractContext<T>

removeInternal

protected boolean removeInternal(Object obj)
Specified by:
removeInternal in class AbstractContext<T>

removeAll

public boolean removeAll(Collection<?> c)
Specified by:
removeAll in interface Collection<T>
Overrides:
removeAll in class AbstractCollection<T>

retainAll

public boolean retainAll(Collection<?> c)
Specified by:
retainAll in interface Collection<T>
Overrides:
retainAll in class AbstractCollection<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.

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.

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.

Returns:
an object in this context chosen at random from a uniform distribution.