Package repast.simphony.engine.graph
Class IterableTraverser<T>
java.lang.Object
repast.simphony.engine.graph.IterableTraverser<T>
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionIterableTraverser
(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
Modifier and TypeMethodDescriptiondouble
getDistance
(T fromNode, T toNode) Always returns the default distance of this instance.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 bygetDistance(T, T)
.
-
Constructor Details
-
IterableTraverser
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
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
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
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 Details
-
getSuccessors
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:
-
getDistance
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
public void setDefaultDistance(double defaultDistance) Sets the value that will be returned bygetDistance(T, T)
.- Parameters:
defaultDistance
- the value to be returned bygetDistance(T, T)
-