Class IterableTraverser<T>

java.lang.Object
repast.simphony.engine.graph.IterableTraverser<T>
All Implemented Interfaces:
Traverser<T>

public class IterableTraverser<T> extends Object implements Traverser<T>
A simple Traverser that will return elements from an Iterator in the order they are returned by that iterator. This is useful primarily for working with the CollectionUtils class.

Since the getDistance method of this class does not generally make sense for a list, it will default to returning 1 or the defaultDistance value.

Version:
$Revision: 1.1 $ $Date: 2005/12/21 22:25:35 $
Author:
Jerry Vos
See Also:
  • Constructor Details

    • IterableTraverser

      public IterableTraverser(Iterable<T> iterable)
      Constructs this traverser based on the iterator returned by this iterable.

      Same as: IterableTraverser(iterable.iterator(), true)

      Parameters:
      iterable - the iterable who's iterator to use for traversing
      See Also:
    • IterableTraverser

      public IterableTraverser(Iterable<T> iterable, boolean skipFirst)
      Constructs this traverser based on the iterator returned by this iterable.

      Same as: IterableTraverser(iterable.iterator(), skipFirst)

      Parameters:
      iterable - the iterable who's iterator to use for traversing
      skipFirst - whether or not to skip the first value in the iterator, for more information on this see IterableTraverser(Iterator, boolean)
      See Also:
    • IterableTraverser

      public IterableTraverser(Iterator<T> iterator)
      Constructs this traverser based on the iterator returned by this iterable.

      Same as: IterableTraverser(iterator, true)

      Parameters:
      iterator - the iterator to traverse
      See Also:
    • IterableTraverser

      public IterableTraverser(Iterator<T> iterator, boolean skipFirst)
      Constructs this traverser based on the iterator returned by this iterable.

      Based on the skipFirst value this traverser will (or will not) skip the first value returned by the iterator. This is useful because the scheduling and the CollectionUtils methods take in a root element that they start their execution on, and then they use this traverser. In these cases if you do not skip the first element you will have that element executed upon twice, once because it is the root, and once because it is the first element returned by the iterator.

      Parameters:
      iterator - the iterator to traverse
      skipFirst - whether or not to skip the first value in the iterator
  • Method Details

    • getSuccessors

      public Iterator<T> getSuccessors(T previousNode, T currentNode)
      Retrieves an iterator that will return the next object in the iterator. If there are no more objects in the iterator it will return an iterator that is empty (meaning it will always return false for it's hasNext).
      Specified by:
      getSuccessors in interface Traverser<T>
      Parameters:
      previousNode - ignored
      currentNode - ignored
      Returns:
      an iterator as specified in the description
      See Also:
    • getDistance

      public double getDistance(T fromNode, T toNode)
      Always returns the default distance of this instance.
      Specified by:
      getDistance in interface Traverser<T>
      Parameters:
      fromNode - ignored
      toNode - ignored
      Returns:
      the default distance
      See Also:
    • setDefaultDistance

      public void setDefaultDistance(double defaultDistance)
      Sets the value that will be returned by getDistance(T, T).
      Parameters:
      defaultDistance - the value to be returned by getDistance(T, T)