Class GraphPath<GP extends GraphPath<GP,ST,PT>,ST extends GraphSegment<ST,PT>,PT extends GraphPoint<PT,ST>>
- java.lang.Object
-
- org.arakhne.afc.math.graph.GraphPath<GP,ST,PT>
-
- Type Parameters:
GP- is the type of the graph graph itself.PT- is the type of node in the graphST- is the type of edge in the graph
- All Implemented Interfaces:
Cloneable,Iterable<ST>,Collection<ST>,List<ST>,GraphSegmentList<ST,PT>
- Direct Known Subclasses:
RoadPath
public class GraphPath<GP extends GraphPath<GP,ST,PT>,ST extends GraphSegment<ST,PT>,PT extends GraphPoint<PT,ST>> extends Object implements GraphSegmentList<ST,PT>, Cloneable
This class describes a path inside a graph.- 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 (package private) List<ST>segmentListPackage access to avoid comiplation error.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int index, ST segment)booleanadd(ST segment)booleanadd(ST segment, PT point)Add the segment starting from the given point.booleanaddAll(int index, Collection<? extends ST> collection)booleanaddAll(Collection<? extends ST> collection)voidclear()GPclone()booleancontains(Object obj)booleancontainsAll(Collection<?> collection)STget(int index)STgetAntepenulvianSegment()Replies the antepenulvian segment.PTgetFirstPoint()Replies the first point.STgetFirstSegment()Replies the first segment.PTgetLastPoint()Replies the last point.STgetLastSegment()Replies the last segment.doublegetLength()Replies the length of the path.STgetSecondSegment()Replies the second element of the path if it exists.PTgetStartingPointFor(int index)Replies the starting point for the segment at the given index.intindexOf(Object obj)voidinvert()Revert the order of the graph segment in this path.booleanisEmpty()booleanisFirstSegmentReversable()Replies if this first segment could be reversed when the second segment is inserted to fit the order of the insertions.Iterator<ST>iterator()intlastIndexOf(Object obj)ListIterator<ST>listIterator()ListIterator<ST>listIterator(int index)Iterator<PT>pointIterator()Replies an iterator on the path's points.Iterable<PT>points()Replies an iterator on the path's points.STremove(int index)booleanremove(Object obj)booleanremoveAfter(ST obj)Remove the path's elements after the specified one.booleanremoveAfter(ST obj, PT pt)Remove the path's elements after the specified one which is starting at the specified point.booleanremoveAfterLast(ST obj)Remove the path's elements after the specified one.booleanremoveAfterLast(ST obj, PT pt)Remove the path's elements after the specified one which is starting at the specified point.booleanremoveAll(Collection<?> collection)booleanremoveBefore(ST obj)Remove the path's elements before the specified one.booleanremoveBefore(ST obj, PT pt)Remove the path's elements before the specified one which is starting at the specified point.booleanremoveBeforeLast(ST obj)Remove the path's elements before the specified one.booleanremoveBeforeLast(ST obj, PT pt)Remove the path's elements before the specified one which is starting at the specified point.booleanremoveFrom(ST obj)Remove the path's elements after the specified one.booleanremoveFrom(ST obj, PT pt)Remove the path's elements after the specified one which is starting at the specified point.booleanremoveFromLast(ST obj)Remove the path's elements after the specified one.booleanremoveFromLast(ST obj, PT pt)Remove the path's elements after the specified one which is starting at the specified point.(package private) booleanremoveUntil(int index, boolean inclusive)Package access to avoid compilation error.booleanremoveUntil(ST obj)Remove the path's elements before the specified one.booleanremoveUntil(ST obj, PT pt)Remove the path's elements before the specified one which is starting at the specified point.booleanremoveUntilLast(ST obj)Remove the path's elements before the specified one.booleanremoveUntilLast(ST obj, PT pt)Remove the path's elements before the specified one which is starting at the specified point.booleanretainAll(Collection<?> collection)STset(int index, ST element)voidsetFirstSegmentReversable(boolean isReversable1)Set if this first segment could be reversed when the second segment is inserted to fit the order of the insertions.intsize()GPsplitAfter(ST obj)Split this path and retains the first part of the part in this object and reply the second part.GPsplitAfter(ST obj, PT startPoint)Split this path and retains the first part of the part in this object and reply the second part.GPsplitAfterLast(ST obj)Split this path and retains the first part of the part in this object and reply the second part.GPsplitAfterLast(ST obj, PT startPoint)Split this path and retains the first part of the part in this object and reply the second part.GPsplitAt(int position)Split this path and retains the first part of the part in this object and reply the second part.GPsplitAt(ST obj)Split this path and retains the first part of the part in this object and reply the second part.GPsplitAt(ST obj, PT startPoint)Split this path and retains the first part of the part in this object and reply the second part.GPsplitAtLast(ST obj)Split this path and retains the first part of the part in this object and reply the second part.GPsplitAtLast(ST obj, PT startPoint)Split this path and retains the first part of the part in this object and reply the second part.List<ST>subList(int fromIndex, int toIndex)Object[]toArray()<T> T[]toArray(T[] array)StringtoString()-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.List
equals, hashCode, replaceAll, sort, spliterator
-
-
-
-
Field Detail
-
segmentList
List<ST extends GraphSegment<ST,PT>> segmentList
Package access to avoid comiplation error.
-
-
Method Detail
-
isFirstSegmentReversable
@Pure public boolean isFirstSegmentReversable()
Replies if this first segment could be reversed when the second segment is inserted to fit the order of the insertions.Let s1 and s2 two segments respectively linked to the points [p1, p2] and [p1, p3]. Let the following code:
If the path is not reversable, it is becomingGraphPath path = new GraphPath(); path.add(s1); path.add(s2);[s2, s1]because the order of s1 is preserved. If the path is reversable, it is becoming[s1, s2]because the first segment is reverted to fit the order of the calls to the add function.Let s1 and s2 the same segments as previously. Let the following code:
The first segment is not reversable because of the call to the add function with the connection as parameter. The path is becomingGraphPath path = new GraphPath(); path.add(s1, p2); path.add(s2);s1, s2, and nothing else.- Returns:
trueif the first segment could be reversed; otherwisefalse.
-
setFirstSegmentReversable
public void setFirstSegmentReversable(boolean isReversable1)
Set if this first segment could be reversed when the second segment is inserted to fit the order of the insertions.Let s1 and s2 two segments respectively linked to the points [p1, p2] and [p1, p3]. Let the following code:
If the path is not reversable, it is becomingGraphPath path = new GraphPath(); path.add(s1); path.add(s2);[s2, s1]because the order of s1 is preserved. If the path is reversable, it is becoming[s1, s2]because the first segment is reverted to fit the order of the calls to the add function.Let s1 and s2 the same segments as previously. Let the following code:
The first segment is not reversable because of the call to the add function with the connection as parameter. The path is becomingGraphPath path = new GraphPath(); path.add(s1, p2); path.add(s2);s1, s2, and nothing else.- Parameters:
isReversable1- istrueif the first segment could be reversed; otherwisefalse.
-
size
@Pure public int size()
-
isEmpty
@Pure public boolean isEmpty()
-
contains
@Pure public boolean contains(Object obj)
-
pointIterator
@Pure public Iterator<PT> pointIterator()
Description copied from interface:GraphSegmentListReplies an iterator on the path's points.- Specified by:
pointIteratorin interfaceGraphSegmentList<GP extends GraphPath<GP,ST,PT>,ST extends GraphSegment<ST,PT>>- Returns:
- an iterator on the path's points.
-
points
@Pure public Iterable<PT> points()
Description copied from interface:GraphSegmentListReplies an iterator on the path's points.
-
toArray
@Pure public Object[] toArray()
-
toArray
public <T> T[] toArray(T[] array)
-
containsAll
@Pure public boolean containsAll(Collection<?> collection)
- Specified by:
containsAllin interfaceCollection<GP extends GraphPath<GP,ST,PT>>- Specified by:
containsAllin interfaceList<GP extends GraphPath<GP,ST,PT>>
-
add
public boolean add(ST segment, PT point)
Description copied from interface:GraphSegmentListAdd the segment starting from the given point.
-
add
public void add(int index, ST segment)- Specified by:
addin interfaceList<GP extends GraphPath<GP,ST,PT>>- Throws:
IndexOutOfBoundsException- if the index is invalid.IllegalArgumentException- is the given segment cannot be connected.
-
add
public boolean add(ST segment)
-
getLastPoint
@Pure public PT getLastPoint()
Description copied from interface:GraphSegmentListReplies the last point.- Specified by:
getLastPointin interfaceGraphSegmentList<GP extends GraphPath<GP,ST,PT>,ST extends GraphSegment<ST,PT>>- Returns:
- the last point.
-
getFirstPoint
@Pure public PT getFirstPoint()
Description copied from interface:GraphSegmentListReplies the first point.- Specified by:
getFirstPointin interfaceGraphSegmentList<GP extends GraphPath<GP,ST,PT>,ST extends GraphSegment<ST,PT>>- Returns:
- the first point.
-
getStartingPointFor
@Pure public PT getStartingPointFor(int index)
Replies the starting point for the segment at the given index.- Parameters:
index- is the index of the segment.- Returns:
- the starting point for the segment at the given index.
-
getLastSegment
@Pure public ST getLastSegment()
Description copied from interface:GraphSegmentListReplies the last segment.- Specified by:
getLastSegmentin interfaceGraphSegmentList<GP extends GraphPath<GP,ST,PT>,ST extends GraphSegment<ST,PT>>- Returns:
- the last segment or
null.
-
getAntepenulvianSegment
@Pure public ST getAntepenulvianSegment()
Description copied from interface:GraphSegmentListReplies the antepenulvian segment.- Specified by:
getAntepenulvianSegmentin interfaceGraphSegmentList<GP extends GraphPath<GP,ST,PT>,ST extends GraphSegment<ST,PT>>- Returns:
- the antepenulvian segment or
null.
-
getSecondSegment
@Pure public ST getSecondSegment()
Description copied from interface:GraphSegmentListReplies the second element of the path if it exists.- Specified by:
getSecondSegmentin interfaceGraphSegmentList<GP extends GraphPath<GP,ST,PT>,ST extends GraphSegment<ST,PT>>- Returns:
- the second element of the path if it exists.
-
getFirstSegment
@Pure public ST getFirstSegment()
Description copied from interface:GraphSegmentListReplies the first segment.- Specified by:
getFirstSegmentin interfaceGraphSegmentList<GP extends GraphPath<GP,ST,PT>,ST extends GraphSegment<ST,PT>>- Returns:
- the first segment or
null.
-
addAll
public boolean addAll(Collection<? extends ST> collection)
-
addAll
public boolean addAll(int index, Collection<? extends ST> collection)
-
remove
public boolean remove(Object obj)
-
remove
public ST remove(int index)
-
removeUntil
boolean removeUntil(int index, boolean inclusive)Package access to avoid compilation error. You must not call this function directly.- Parameters:
index- the reference index.inclusive- indicates if the element at the reference index is included in the removed elements.- Returns:
trueorfalse
-
removeUntil
public boolean removeUntil(ST obj, PT pt)
Remove the path's elements before the specified one which is starting at the specified point. The specified element will be removed.This function removes until the first occurence of the given object.
- Parameters:
obj- is the segment to removept- is the point on which the segment was connected as its first point.- Returns:
trueon success, otherwisefalse
-
removeUntil
public boolean removeUntil(ST obj)
Remove the path's elements before the specified one. The specified element will also be removed.This function removes until the first occurence of the given object.
- Specified by:
removeUntilin interfaceGraphSegmentList<GP extends GraphPath<GP,ST,PT>,ST extends GraphSegment<ST,PT>>- Parameters:
obj- the reference segment.- Returns:
trueon success, otherwisefalse
-
removeBefore
public boolean removeBefore(ST obj)
Remove the path's elements before the specified one. The specified element will not be removed.This function removes until the first occurence of the given object.
- Specified by:
removeBeforein interfaceGraphSegmentList<GP extends GraphPath<GP,ST,PT>,ST extends GraphSegment<ST,PT>>- Parameters:
obj- the reference element.- Returns:
trueon success, otherwisefalse
-
removeBefore
public boolean removeBefore(ST obj, PT pt)
Remove the path's elements before the specified one which is starting at the specified point. The specified element will not be removed.This function removes until the first occurence of the given object.
- Specified by:
removeBeforein interfaceGraphSegmentList<GP extends GraphPath<GP,ST,PT>,ST extends GraphSegment<ST,PT>>- Parameters:
obj- is the segment to removept- is the point on which the segment was connected as its first point.- Returns:
trueon success, otherwisefalse
-
removeBeforeLast
public boolean removeBeforeLast(ST obj)
Remove the path's elements before the specified one. The specified element will not be removed.This function removes until the last occurence of the given object.
- Specified by:
removeBeforeLastin interfaceGraphSegmentList<GP extends GraphPath<GP,ST,PT>,ST extends GraphSegment<ST,PT>>- Parameters:
obj- the reference element.- Returns:
trueon success, otherwisefalse
-
removeBeforeLast
public boolean removeBeforeLast(ST obj, PT pt)
Remove the path's elements before the specified one which is starting at the specified point. The specified element will not be removed.This function removes until the last occurence of the given object.
- Specified by:
removeBeforeLastin interfaceGraphSegmentList<GP extends GraphPath<GP,ST,PT>,ST extends GraphSegment<ST,PT>>- Parameters:
obj- is the segment to removept- is the point on which the segment was connected as its first point.- Returns:
trueon success, otherwisefalse
-
removeUntilLast
public boolean removeUntilLast(ST obj, PT pt)
Remove the path's elements before the specified one which is starting at the specified point. The specified element will be removed.This function removes until the last occurence of the given object.
- Parameters:
obj- is the segment to removept- is the point on which the segment was connected as its first point.- Returns:
trueon success, otherwisefalse
-
removeUntilLast
public boolean removeUntilLast(ST obj)
Remove the path's elements before the specified one. The specified element will also be removed.This function removes until the last occurence of the given object.
- Specified by:
removeUntilLastin interfaceGraphSegmentList<GP extends GraphPath<GP,ST,PT>,ST extends GraphSegment<ST,PT>>- Parameters:
obj- the reference segment.- Returns:
trueon success, otherwisefalse
-
removeAfter
public boolean removeAfter(ST obj, PT pt)
Remove the path's elements after the specified one which is starting at the specified point. The specified element will not be removed.This function removes after the first occurence of the given object.
- Parameters:
obj- is the segment to removept- is the point on which the segment was connected as its first point.- Returns:
trueon success, otherwisefalse
-
removeAfter
public boolean removeAfter(ST obj)
Remove the path's elements after the specified one. The specified element will not be removed.This function removes after the first occurence of the given object.
- Parameters:
obj- the reference segment.- Returns:
trueon success, otherwisefalse
-
removeAfterLast
public boolean removeAfterLast(ST obj)
Remove the path's elements after the specified one. The specified element will not be removed.This function removes after the last occurence of the given object.
- Parameters:
obj- the reference segment.- Returns:
trueon success, otherwisefalse
-
removeAfterLast
public boolean removeAfterLast(ST obj, PT pt)
Remove the path's elements after the specified one which is starting at the specified point. The specified element will not be removed.This function removes after the last occurence of the given object.
- Parameters:
obj- is the segment to removept- is the point on which the segment was connected as its first point.- Returns:
trueon success, otherwisefalse
-
removeFromLast
public boolean removeFromLast(ST obj, PT pt)
Remove the path's elements after the specified one which is starting at the specified point. The specified element will be removed.This function removes after the last occurence of the given object.
- Parameters:
obj- is the segment to removept- is the point on which the segment was connected as its first point.- Returns:
trueon success, otherwisefalse
-
removeFromLast
public boolean removeFromLast(ST obj)
Remove the path's elements after the specified one. The specified element will also be removed.This function removes until the last occurence of the given object.
- Parameters:
obj- the reference segment.- Returns:
trueon success, otherwisefalse
-
removeFrom
public boolean removeFrom(ST obj, PT pt)
Remove the path's elements after the specified one which is starting at the specified point. The specified element will be removed.This function removes after the first occurence of the given object.
- Parameters:
obj- is the segment to removept- is the point on which the segment was connected as its first point.- Returns:
trueon success, otherwisefalse
-
removeFrom
public boolean removeFrom(ST obj)
Remove the path's elements after the specified one. The specified element will also be removed.This function removes until the first occurence of the given object.
- Parameters:
obj- the reference segment.- Returns:
trueon success, otherwisefalse
-
indexOf
@Pure public int indexOf(Object obj)
-
lastIndexOf
@Pure public int lastIndexOf(Object obj)
-
removeAll
public boolean removeAll(Collection<?> collection)
-
retainAll
public boolean retainAll(Collection<?> collection)
-
clear
public void clear()
-
listIterator
@Pure public ListIterator<ST> listIterator()
-
listIterator
@Pure public ListIterator<ST> listIterator(int index)
-
invert
public void invert()
Revert the order of the graph segment in this path.
-
splitAt
public GP splitAt(ST obj)
Split this path and retains the first part of the part in this object and reply the second part. The first occurrence of this specified element will be in the second part.This function removes until the last occurence of the given object.
- Parameters:
obj- the reference segment.- Returns:
- the rest of the path after the first occurence of the given element.
-
splitAt
public GP splitAt(ST obj, PT startPoint)
Split this path and retains the first part of the part in this object and reply the second part. The first occurrence of this specified element will be in the second part.This function removes until the last occurence of the given object.
- Parameters:
obj- the reference segment.startPoint- is the starting point of the searched segment.- Returns:
- the rest of the path after the first occurence of the given element.
-
splitAt
public GP splitAt(int position)
Split this path and retains the first part of the part in this object and reply the second part. The segment at the given position will be in the second part.- Parameters:
position- the segment index in the path.- Returns:
- the rest of the path after the element at the given position.
-
splitAfterLast
public GP splitAfterLast(ST obj)
Split this path and retains the first part of the part in this object and reply the second part. The last occurence of the specified element will be in the first part.This function removes until the last occurence of the given object.
- Parameters:
obj- the reference segment.- Returns:
- the rest of the path after the last occurence of the given element.
-
splitAfterLast
public GP splitAfterLast(ST obj, PT startPoint)
Split this path and retains the first part of the part in this object and reply the second part. The last occurence of the specified element will be in the first part.This function removes until the last occurence of the given object.
- Parameters:
obj- is the segment to search for.startPoint- is the starting point of the searched segment.- Returns:
- the rest of the path after the last occurence of the given element.
-
splitAtLast
public GP splitAtLast(ST obj, PT startPoint)
Split this path and retains the first part of the part in this object and reply the second part. The last occurence of the specified element will be in the second part.This function removes until the last occurence of the given object.
- Parameters:
obj- the reference segment.startPoint- is the starting point of the searched segment.- Returns:
- the rest of the path after the last occurence of the given element.
-
splitAtLast
public GP splitAtLast(ST obj)
Split this path and retains the first part of the part in this object and reply the second part. The last occurence of the specified element will be in the second part.This function removes until the last occurence of the given object.
- Parameters:
obj- the reference segment.- Returns:
- the rest of the path after the last occurence of the given element.
-
splitAfter
public GP splitAfter(ST obj)
Split this path and retains the first part of the part in this object and reply the second part. The first occurrence of specified element will be in the first part.This function removes until the last occurence of the given object.
- Parameters:
obj- the reference segment.- Returns:
- the rest of the path after the first occurence of the given element.
-
splitAfter
public GP splitAfter(ST obj, PT startPoint)
Split this path and retains the first part of the part in this object and reply the second part. The first occurrence of specified element will be in the first part.This function removes until the last occurence of the given object.
- Parameters:
obj- the reference segment.startPoint- is the starting point of the searched segment.- Returns:
- the rest of the path after the first occurence of the given element.
-
getLength
@Pure public double getLength()
Replies the length of the path.- Returns:
- the length of the path.
-
-