repast.simphony.context
Class ContextIterable<T>

java.lang.Object
  extended by repast.simphony.util.collections.RandomIterable<T>
      extended by repast.simphony.context.ContextIterable<T>
All Implemented Interfaces:
Iterable<T>, Iterator<T>, ContextListener<T>

public class ContextIterable<T>
extends RandomIterable<T>
implements ContextListener<T>

An iterable that iterates over a collection of objects at random. The "length" of the iterable may be less than the number of objects in the collection.

Version:
$Revision$ $Date$
Author:
Nick Collier

Field Summary
 
Fields inherited from class repast.simphony.util.collections.RandomIterable
index, list, numReturned, numToReturn, returned
 
Constructor Summary
ContextIterable(IndexedIterable<T> iter, long count, Context<T> context)
          Creates a RandomIterable that will iterate over count number of objects in the specified IndexedIterable.
 
Method Summary
 void eventOccured(ContextEvent<T> ev)
          Notify this event of a change to a context.
 T next()
          Returns the next element in the iteration.
 
Methods inherited from class repast.simphony.util.collections.RandomIterable
hasNext, iterator, remove, removeEvent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ContextIterable

public ContextIterable(IndexedIterable<T> iter,
                       long count,
                       Context<T> context)
Creates a RandomIterable that will iterate over count number of objects in the specified IndexedIterable.

Parameters:
iter -
count -
context - the context associated with this iterable. This will listen on the context and respond appropriately to remove events
Method Detail

next

public T next()
Returns the next element in the iteration. Calling this method repeatedly until the RandomIterable.hasNext() method returns false will return each element in the underlying collection exactly once.

Specified by:
next in interface Iterator<T>
Overrides:
next in class RandomIterable<T>
Returns:
the next element in the iteration.
Throws:
NoSuchElementException - iteration has no more elements.

eventOccured

public void eventOccured(ContextEvent<T> ev)
Notify this event of a change to a context.

Specified by:
eventOccured in interface ContextListener<T>
Parameters:
ev - The event of which to notify the listener.