Package repast.simphony.engine.graph
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 simpleTraverser
that will return elements from an Iterator in the order they are returned by that iterator. This is useful primarily for working with theCollectionUtils
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:
setDefaultDistance(double)
-
-
Constructor Summary
Constructors Constructor Description IterableTraverser(Iterable<T> iterable)
Constructs this traverser based on the iterator returned by this iterable.IterableTraverser(Iterable<T> iterable, boolean skipFirst)
Constructs this traverser based on the iterator returned by this iterable.IterableTraverser(Iterator<T> iterator)
Constructs this traverser based on the iterator returned by this iterable.IterableTraverser(Iterator<T> iterator, boolean skipFirst)
Constructs this traverser based on the iterator returned by this iterable.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double
getDistance(T fromNode, T toNode)
Always returns the default distance of this instance.Iterator<T>
getSuccessors(T previousNode, T currentNode)
Retrieves an iterator that will return the next object in the iterator.void
setDefaultDistance(double defaultDistance)
Sets the value that will be returned by#getDistance(T, T)
.
-
-
-
Constructor Detail
-
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(Iterator, boolean)
-
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 traversingskipFirst
- whether or not to skip the first value in the iterator, for more information on this seeIterableTraverser(Iterator, boolean)
- See Also:
IterableTraverser(Iterator, boolean)
-
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(Iterator, boolean)
-
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 theCollectionUtils
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 traverseskipFirst
- whether or not to skip the first value in the iterator
-
-
Method Detail
-
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 interfaceTraverser<T>
- Parameters:
previousNode
- ignoredcurrentNode
- ignored- Returns:
- an iterator as specified in the description
- See Also:
GraphParams
-
getDistance
public double getDistance(T fromNode, T toNode)
Always returns the default distance of this instance.- Specified by:
getDistance
in interfaceTraverser<T>
- Parameters:
fromNode
- ignoredtoNode
- ignored- Returns:
- the default distance
- See Also:
setDefaultDistance(double)
-
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)
-
-