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>
segmentList
Package access to avoid comiplation error.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(int index, ST segment)
boolean
add(ST segment)
boolean
add(ST segment, PT point)
Add the segment starting from the given point.boolean
addAll(int index, Collection<? extends ST> collection)
boolean
addAll(Collection<? extends ST> collection)
void
clear()
GP
clone()
boolean
contains(Object obj)
boolean
containsAll(Collection<?> collection)
ST
get(int index)
ST
getAntepenulvianSegment()
Replies the antepenulvian segment.PT
getFirstPoint()
Replies the first point.ST
getFirstSegment()
Replies the first segment.PT
getLastPoint()
Replies the last point.ST
getLastSegment()
Replies the last segment.double
getLength()
Replies the length of the path.ST
getSecondSegment()
Replies the second element of the path if it exists.PT
getStartingPointFor(int index)
Replies the starting point for the segment at the given index.int
indexOf(Object obj)
void
invert()
Revert the order of the graph segment in this path.boolean
isEmpty()
boolean
isFirstSegmentReversable()
Replies if this first segment could be reversed when the second segment is inserted to fit the order of the insertions.Iterator<ST>
iterator()
int
lastIndexOf(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.ST
remove(int index)
boolean
remove(Object obj)
boolean
removeAfter(ST obj)
Remove the path's elements after the specified one.boolean
removeAfter(ST obj, PT pt)
Remove the path's elements after the specified one which is starting at the specified point.boolean
removeAfterLast(ST obj)
Remove the path's elements after the specified one.boolean
removeAfterLast(ST obj, PT pt)
Remove the path's elements after the specified one which is starting at the specified point.boolean
removeAll(Collection<?> collection)
boolean
removeBefore(ST obj)
Remove the path's elements before the specified one.boolean
removeBefore(ST obj, PT pt)
Remove the path's elements before the specified one which is starting at the specified point.boolean
removeBeforeLast(ST obj)
Remove the path's elements before the specified one.boolean
removeBeforeLast(ST obj, PT pt)
Remove the path's elements before the specified one which is starting at the specified point.boolean
removeFrom(ST obj)
Remove the path's elements after the specified one.boolean
removeFrom(ST obj, PT pt)
Remove the path's elements after the specified one which is starting at the specified point.boolean
removeFromLast(ST obj)
Remove the path's elements after the specified one.boolean
removeFromLast(ST obj, PT pt)
Remove the path's elements after the specified one which is starting at the specified point.(package private) boolean
removeUntil(int index, boolean inclusive)
Package access to avoid compilation error.boolean
removeUntil(ST obj)
Remove the path's elements before the specified one.boolean
removeUntil(ST obj, PT pt)
Remove the path's elements before the specified one which is starting at the specified point.boolean
removeUntilLast(ST obj)
Remove the path's elements before the specified one.boolean
removeUntilLast(ST obj, PT pt)
Remove the path's elements before the specified one which is starting at the specified point.boolean
retainAll(Collection<?> collection)
ST
set(int index, ST element)
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.int
size()
GP
splitAfter(ST obj)
Split this path and retains the first part of the part in this object and reply the second part.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.GP
splitAfterLast(ST obj)
Split this path and retains the first part of the part in this object and reply the second part.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.GP
splitAt(int position)
Split this path and retains the first part of the part in this object and reply the second part.GP
splitAt(ST obj)
Split this path and retains the first part of the part in this object and reply the second part.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.GP
splitAtLast(ST obj)
Split this path and retains the first part of the part in this object and reply the second part.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.List<ST>
subList(int fromIndex, int toIndex)
Object[]
toArray()
<T> T[]
toArray(T[] array)
String
toString()
-
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:
true
if 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
- istrue
if 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:GraphSegmentList
Replies an iterator on the path's points.- Specified by:
pointIterator
in 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:GraphSegmentList
Replies 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:
containsAll
in interfaceCollection<GP extends GraphPath<GP,ST,PT>>
- Specified by:
containsAll
in interfaceList<GP extends GraphPath<GP,ST,PT>>
-
add
public boolean add(ST segment, PT point)
Description copied from interface:GraphSegmentList
Add the segment starting from the given point.
-
add
public void add(int index, ST segment)
- Specified by:
add
in 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:GraphSegmentList
Replies the last point.- Specified by:
getLastPoint
in 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:GraphSegmentList
Replies the first point.- Specified by:
getFirstPoint
in 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:GraphSegmentList
Replies the last segment.- Specified by:
getLastSegment
in 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:GraphSegmentList
Replies the antepenulvian segment.- Specified by:
getAntepenulvianSegment
in 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:GraphSegmentList
Replies the second element of the path if it exists.- Specified by:
getSecondSegment
in 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:GraphSegmentList
Replies the first segment.- Specified by:
getFirstSegment
in 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:
true
orfalse
-
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:
true
on 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:
removeUntil
in interfaceGraphSegmentList<GP extends GraphPath<GP,ST,PT>,ST extends GraphSegment<ST,PT>>
- Parameters:
obj
- the reference segment.- Returns:
true
on 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:
removeBefore
in interfaceGraphSegmentList<GP extends GraphPath<GP,ST,PT>,ST extends GraphSegment<ST,PT>>
- Parameters:
obj
- the reference element.- Returns:
true
on 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:
removeBefore
in 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:
true
on 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:
removeBeforeLast
in interfaceGraphSegmentList<GP extends GraphPath<GP,ST,PT>,ST extends GraphSegment<ST,PT>>
- Parameters:
obj
- the reference element.- Returns:
true
on 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:
removeBeforeLast
in 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:
true
on 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:
true
on 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:
removeUntilLast
in interfaceGraphSegmentList<GP extends GraphPath<GP,ST,PT>,ST extends GraphSegment<ST,PT>>
- Parameters:
obj
- the reference segment.- Returns:
true
on 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:
true
on 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:
true
on 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:
true
on 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:
true
on 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:
true
on 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:
true
on 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:
true
on 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:
true
on 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.
-
-