Class GraphIterator<ST extends GraphSegment<ST,PT>,PT extends GraphPoint<PT,ST>>
- java.lang.Object
-
- org.arakhne.afc.math.graph.GraphIterator<ST,PT>
-
- Type Parameters:
PT
- is the type of node in the graphST
- is the type of edge in the graph
- All Implemented Interfaces:
Iterator<ST>
- Direct Known Subclasses:
DepthGraphIterator
,RoadNetworkIterator
public class GraphIterator<ST extends GraphSegment<ST,PT>,PT extends GraphPoint<PT,ST>> extends Object implements Iterator<ST>
This class is an iterator on a graph.The behaviour of the iterator is strongly influenced by the constructor's parameters. The two most important parameters are
allowManyReplies
andassumeOrientedSegments
.The
allowManyReplies
parameter indicates if a segment could be replied many types, or not, by the iterator. This parameter permits to control the behaviour of the iterator against graph cycles.The
assumeOrientedSegments
parameter indicates how the segments are considered by the iterator. IfassumeOrientedSegments
istrue
it means that a segment reached by one of its end point is different than the same segment reached by the other end point. IfassumeOrientedSegments
isfalse
it means that the end points of the segments are not take into account. This parameter is usefull only ifallowManyReplies
is set tofalse
.- Since:
- 13.0
- Version:
- 17.0 2020-01-04 14:41:42
- Author:
- Stéphane GALLAND
- Maven Group Id:
- org.arakhne.afc.core
- Maven Artifact Id:
- mathgraph
-
-
Field Summary
Fields Modifier and Type Field Description protected DynamicDepthUpdater<ST,PT>
dynamicDepthUpdater
The dynamic updater for the depth.
-
Constructor Summary
Constructors Modifier Constructor Description GraphIterator(Graph<ST,PT> graph1, GraphCourseModel<ST,PT> courseModel1, ST segment, PT point, boolean allowManyReplies1, boolean assumeOrientedSegments1, double distanceToReachStartingPoint)
Constructor.protected
GraphIterator(Graph<ST,PT> graph1, GraphCourseModel<ST,PT> courseModel, ST segment, PT point, boolean allowManyReplies, boolean assumeOrientedSegments, double distanceToReachStartingPoint, double distanceToConsumeAfter, DynamicDepthUpdater<ST,PT> dynamicDepthUpdater)
Constructor.GraphIterator(Graph<ST,PT> graph1, ST segment, PT point, boolean allowManyReplies1, boolean assumeOrientedSegments1, double distanceToReachStartingPoint)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
canGotoIntoElement(GraphIterationElement<ST,PT> element)
Replies if the specified element could be added into the list of futher elements.(package private) void
clear()
Clear the temporary buffers of this graph iterator.protected Comparator<GraphIterationElement<ST,PT>>
createVisitedSegmentComparator(boolean assumeOrientedSegments1)
Invoked when a comparator on visited segments is required.(package private) Graph<ST,PT>
getGraph()
Replies the graph on which this iterator is iterating.protected GraphIterationElement<ST,PT>
getNextElement()
Replies the next element without removing it from the iterator list.protected Iterable<GraphIterationElement<ST,PT>>
getNextSegments(boolean avoid_visited_segments, GraphIterationElement<ST,PT> element)
Replies the next segments.boolean
hasNext()
void
ignoreElementsAfter()
Ignore the elements after the specified element.void
ignoreElementsAfter(GraphIterationElement<ST,PT> element)
Ignore the elements after the specified element.boolean
isManySegmentReplyEnabled()
Replies if this iterator is assumed that a segment may be replied many times.boolean
isOrientedSegmentSupportEnabled()
Replies if this iterator is assumed oriented segments or not.protected GraphIterationElement<ST,PT>
newIterationElement(ST previousSegment, ST segment, PT point, boolean fromStartPoint, double distanceToReach, double distanceToConsume)
Create an instance of GraphIterationElement.ST
next()
GraphIterationElement<ST,PT>
nextElement()
Replies the next segment.void
remove()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Iterator
forEachRemaining
-
-
-
-
Field Detail
-
dynamicDepthUpdater
protected final DynamicDepthUpdater<ST extends GraphSegment<ST,PT>,PT extends GraphPoint<PT,ST>> dynamicDepthUpdater
The dynamic updater for the depth. This reference isnull
if there is no need to dynamically update the depth.
-
-
Constructor Detail
-
GraphIterator
public GraphIterator(Graph<ST,PT> graph1, ST segment, PT point, boolean allowManyReplies1, boolean assumeOrientedSegments1, double distanceToReachStartingPoint)
Constructor.- Parameters:
graph1
- is the graph associated to this iterator.segment
- is the segment from which to start.point
- is the segment's point indicating the direction.allowManyReplies1
- may betrue
to allow to reply many times the same segment, otherwhisefalse
.assumeOrientedSegments1
- may betrue
to assume that the same segment has two different instances for graph iteration: the first instance is associated the first point of the segment and the second instance is associated to the last point of the segment. If this parameter isfalse
to assume that the end points of a segment are not distinguished.distanceToReachStartingPoint
- is the distance to reach the starting point. It must be negative or nul.
-
GraphIterator
public GraphIterator(Graph<ST,PT> graph1, GraphCourseModel<ST,PT> courseModel1, ST segment, PT point, boolean allowManyReplies1, boolean assumeOrientedSegments1, double distanceToReachStartingPoint)
Constructor.- Parameters:
graph1
- is the graph associated to this iterator.courseModel1
- is the course model to use.segment
- is the segment from which to start.point
- is the segment's point indicating the direction.allowManyReplies1
- may betrue
to allow to reply many times the same segment, otherwhisefalse
.assumeOrientedSegments1
- may betrue
to assume that the same segment has two different instances for graph iteration: the first instance is associated the first point of the segment and the second instance is associated to the last point of the segment. If this parameter isfalse
to assume that the end points of a segment are not distinguished.distanceToReachStartingPoint
- is the distance to reach the starting point. It must be negative or nul.
-
GraphIterator
protected GraphIterator(Graph<ST,PT> graph1, GraphCourseModel<ST,PT> courseModel, ST segment, PT point, boolean allowManyReplies, boolean assumeOrientedSegments, double distanceToReachStartingPoint, double distanceToConsumeAfter, DynamicDepthUpdater<ST,PT> dynamicDepthUpdater)
Constructor.- Parameters:
graph1
- is the graph associated to this iterator.courseModel
- is the course model to use.segment
- is the segment from which to start.point
- is the segment's point indicating the direction.allowManyReplies
- may betrue
to allow to reply many times the same segment, otherwhisefalse
.assumeOrientedSegments
- may betrue
to assume that the same segment has two different instances for graph iteration: the first instance is associated the first point of the segment and the second instance is associated to the last point of the segment. If this parameter isfalse
to assume that the end points of a segment are not distinguished.distanceToReachStartingPoint
- is the distance to reach the starting point.distanceToConsumeAfter
- is the distance to consume after traversing the segment. It must be negative or nul.dynamicDepthUpdater
- if notnull
, it is used to dynamically update thedistanceToConsumeAfter
.
-
-
Method Detail
-
createVisitedSegmentComparator
@Pure protected Comparator<GraphIterationElement<ST,PT>> createVisitedSegmentComparator(boolean assumeOrientedSegments1)
Invoked when a comparator on visited segments is required.- Parameters:
assumeOrientedSegments1
- may betrue
to assume that the same segment has two different instances for graph iteration: the first instance is associated the first point of the segment and the second instance is associated to the last point of the segment. If this parameter isfalse
to assume that the end points of a segment are not distinguished.- Returns:
- the graph element iterator, or
null
to use the default comparation behaviour of theGraphIterationElement
.
-
getGraph
@Pure Graph<ST,PT> getGraph()
Replies the graph on which this iterator is iterating.- Returns:
- the graph.
-
clear
void clear()
Clear the temporary buffers of this graph iterator.
-
getNextSegments
protected final Iterable<GraphIterationElement<ST,PT>> getNextSegments(boolean avoid_visited_segments, GraphIterationElement<ST,PT> element)
Replies the next segments.- Parameters:
avoid_visited_segments
- istrue
to avoid to reply already visited segments, otherwisefalse
element
- is the element from which the next segments must be replied.- Returns:
- the list of the following segments
- See Also:
next()
-
getNextElement
protected GraphIterationElement<ST,PT> getNextElement()
Replies the next element without removing it from the iterator list.- Returns:
- the next element without removing it from the iterator list.
-
hasNext
@Pure public boolean hasNext()
-
next
public final ST next()
-
nextElement
public final GraphIterationElement<ST,PT> nextElement()
Replies the next segment.- Returns:
- the next segment
-
newIterationElement
protected GraphIterationElement<ST,PT> newIterationElement(ST previousSegment, ST segment, PT point, boolean fromStartPoint, double distanceToReach, double distanceToConsume)
Create an instance of GraphIterationElement.- Parameters:
previousSegment
- is the previous element that permits to reach this object during an iterationsegment
- is the current segmentpoint
- is the point on which the iteration arrived on the current segment.fromStartPoint
- indicates if the current search is reached from its start point. This parameter is useful when the current segment is connected to the same road connected with its start point and its end point.distanceToReach
- is the distance that is already consumed to reach the segment.distanceToConsume
- is the rest of distance to consume including the segment.- Returns:
- a graph iteration element.
-
canGotoIntoElement
@Pure protected boolean canGotoIntoElement(GraphIterationElement<ST,PT> element)
Replies if the specified element could be added into the list of futher elements.- Parameters:
element
- the element to test.- Returns:
true
if the given element is addable into the associated list.
-
ignoreElementsAfter
public void ignoreElementsAfter(GraphIterationElement<ST,PT> element)
Ignore the elements after the specified element.- Parameters:
element
- the reference element.
-
ignoreElementsAfter
public void ignoreElementsAfter()
Ignore the elements after the specified element.
-
remove
public void remove()
-
isManySegmentReplyEnabled
@Pure public final boolean isManySegmentReplyEnabled()
Replies if this iterator is assumed that a segment may be replied many times.- Returns:
true
if this iterator allows cycles, otherwisefalse
-
isOrientedSegmentSupportEnabled
@Pure public final boolean isOrientedSegmentSupportEnabled()
Replies if this iterator is assumed oriented segments or not.- Returns:
true
if this iterator assumes oriented segments, otherwisefalse
-
-