Class GraphPath<GP extends GraphPath<GP,​ST,​PT>,​ST extends GraphSegment<ST,​PT>,​PT extends GraphPoint<PT,​ST>>

  • Type Parameters:
    GP - is the type of the graph graph itself.
    PT - is the type of node in the graph
    ST - 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 Detail

    • Constructor Detail

      • GraphPath

        protected GraphPath​(List<ST> original)
        Constructor of graph path that is backed to the given list.
        Parameters:
        original - the list to be the backend.
        Since:
        16.0
      • GraphPath

        public GraphPath()
        Construct a path.
      • GraphPath

        public GraphPath​(ST segment,
                         PT startingPoint1)
        Constructor.
        Parameters:
        segment - is the segment from which to start.
        startingPoint1 - is the segment's point indicating the direction.
    • 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:

        
         GraphPath path = new GraphPath();
         path.add(s1);
         path.add(s2);
        If the path is not reversable, it is becoming [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:

        
         GraphPath path = new GraphPath();
         path.add(s1, p2);
         path.add(s2);
        The first segment is not reversable because of the call to the add function with the connection as parameter. The path is becoming s1, s2, and nothing else.
        Returns:
        true if the first segment could be reversed; otherwise false.
      • 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:

        
         GraphPath path = new GraphPath();
         path.add(s1);
         path.add(s2);
        If the path is not reversable, it is becoming [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:

        
         GraphPath path = new GraphPath();
         path.add(s1, p2);
         path.add(s2);
        The first segment is not reversable because of the call to the add function with the connection as parameter. The path is becoming s1, s2, and nothing else.
        Parameters:
        isReversable1 - is true if the first segment could be reversed; otherwise false.
      • add

        public boolean add​(ST segment,
                           PT point)
        Description copied from interface: GraphSegmentList
        Add the segment starting from the given point.
        Specified by:
        add in interface GraphSegmentList<GP extends GraphPath<GP,​ST,​PT>,​ST extends GraphSegment<ST,​PT>>
        Parameters:
        segment - is the segment to add
        point - is the point at which the path is starting to go through the given segment.
        Returns:
        true on success, otherwise false
      • 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.
      • 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 or false
      • 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 remove
        pt - is the point on which the segment was connected as its first point.
        Returns:
        true on success, otherwise false
      • 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 interface GraphSegmentList<GP extends GraphPath<GP,​ST,​PT>,​ST extends GraphSegment<ST,​PT>>
        Parameters:
        obj - the reference segment.
        Returns:
        true on success, otherwise false
      • 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 interface GraphSegmentList<GP extends GraphPath<GP,​ST,​PT>,​ST extends GraphSegment<ST,​PT>>
        Parameters:
        obj - the reference element.
        Returns:
        true on success, otherwise false
      • 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 interface GraphSegmentList<GP extends GraphPath<GP,​ST,​PT>,​ST extends GraphSegment<ST,​PT>>
        Parameters:
        obj - is the segment to remove
        pt - is the point on which the segment was connected as its first point.
        Returns:
        true on success, otherwise false
      • 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 interface GraphSegmentList<GP extends GraphPath<GP,​ST,​PT>,​ST extends GraphSegment<ST,​PT>>
        Parameters:
        obj - the reference element.
        Returns:
        true on success, otherwise false
      • 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 interface GraphSegmentList<GP extends GraphPath<GP,​ST,​PT>,​ST extends GraphSegment<ST,​PT>>
        Parameters:
        obj - is the segment to remove
        pt - is the point on which the segment was connected as its first point.
        Returns:
        true on success, otherwise false
      • 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 remove
        pt - is the point on which the segment was connected as its first point.
        Returns:
        true on success, otherwise false
      • 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 interface GraphSegmentList<GP extends GraphPath<GP,​ST,​PT>,​ST extends GraphSegment<ST,​PT>>
        Parameters:
        obj - the reference segment.
        Returns:
        true on success, otherwise false
      • 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 remove
        pt - is the point on which the segment was connected as its first point.
        Returns:
        true on success, otherwise false
      • 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, otherwise false
      • 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, otherwise false
      • 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 remove
        pt - is the point on which the segment was connected as its first point.
        Returns:
        true on success, otherwise false
      • 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 remove
        pt - is the point on which the segment was connected as its first point.
        Returns:
        true on success, otherwise false
      • 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, otherwise false
      • 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 remove
        pt - is the point on which the segment was connected as its first point.
        Returns:
        true on success, otherwise false
      • 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, otherwise false
      • invert

        public void invert()
        Revert the order of the graph segment in this path.
      • clone

        @Pure
        public GP clone()
        Overrides:
        clone in class Object
      • 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.