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

  • Type Parameters:
    PT - is the type of node in the graph
    ST - is the type of edge in the graph
    GP - is the type of graph path
    All Implemented Interfaces:
    Iterable<ST>, Graph<ST,​PT>
    Direct Known Subclasses:
    SubRoadNetwork

    public class SubGraph<ST extends GraphSegment<ST,​PT>,​PT extends GraphPoint<PT,​ST>,​GP extends GraphPath<GP,​ST,​PT>>
    extends Object
    implements Graph<ST,​PT>
    A subgraph.

    The segments is the subgraph are weak references to the segments to the complete 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
    • Constructor Detail

      • SubGraph

        protected SubGraph​(Collection<ST> segments1,
                           int pointNumber1,
                           Comparator<GraphIterationElement<ST,​PT>> orientedIterator,
                           Comparator<GraphIterationElement<ST,​PT>> notOrientedIterator)
        Constructor.
        Parameters:
        segments1 - is the collection to use to store the segments.
        pointNumber1 - is the number of connection points in the subgraph described by the segments.
        orientedIterator - is a comparator which may be used by this subgraph.
        notOrientedIterator - is a comparator which may be used by this subgraph.
    • Method Detail

      • getParentGraph

        @Pure
        protected final Graph<ST,​PT> getParentGraph()
        Replies the parent graph is this subgraph was built.
        Returns:
        the parent graph or null
      • getGraphSegments

        @Pure
        protected final Collection<ST> getGraphSegments()
        Replies the segments in this subgraph.

        Caution: the replied collection is the real reference to the internal collection. Any change in this collection outside this SubGraph class may causes invalid behaviour (no event...).

        Returns:
        the internal data structure that contains all the segments in this subgraph.
      • build

        public final void build​(GraphIterator<ST,​PT> iterator)
        Build a subgraph from the specified graph.
        Parameters:
        iterator - is the iterator on the graph.
      • build

        public final void build​(GraphIterator<ST,​PT> iterator,
                                SubGraphBuildListener<ST,​PT> listener)
        Build a subgraph from the specified graph.
        Parameters:
        iterator - is the iterator on the graph.
        listener - is the listener invoked each time a segment was added to the subgraph.
      • isTerminalPoint

        @Pure
        protected final boolean isTerminalPoint​(PT point)
        Replies if the given point is a terminal point.
        Parameters:
        point - the point to test.
        Returns:
        true if the point is terminal otherwise false
      • wrapSegment

        @Pure
        protected ST wrapSegment​(ST segment)
        Create a wrapping segment for the given graph segment.
        Parameters:
        segment - the segment to wrap.
        Returns:
        a wrapping segment or the segment itself.
      • wrapPoint

        @Pure
        protected PT wrapPoint​(PT point,
                               ST segment,
                               boolean isTerminal)
        Create a wrapping point for the given graph point.
        Parameters:
        point - the point to wrap.
        segment - is the segment connected to the point.
        isTerminal - indicates if this point should be a terminal point.
        Returns:
        a wrapping point or the point itself.
      • isEmpty

        @Pure
        public boolean isEmpty()
        Description copied from interface: Graph
        Replies if this graph is empty or not.
        Specified by:
        isEmpty in interface Graph<ST extends GraphSegment<ST,​PT>,​PT extends GraphPoint<PT,​ST>>
        Returns:
        true if the graph is empty, otherwise false.
      • contains

        @Pure
        public boolean contains​(Object obj)
        Description copied from interface: Graph
        Replies is this graph contains the given segment. The test is based on Object.equals(Object).
        Specified by:
        contains in interface Graph<ST extends GraphSegment<ST,​PT>,​PT extends GraphPoint<PT,​ST>>
        Parameters:
        obj - the object to search for.
        Returns:
        true if the graph contains the segment, otherwise false.
      • getSegmentCount

        @Pure
        public final int getSegmentCount()
        Description copied from interface: Graph
        Replies the count of segments in this graph.
        Specified by:
        getSegmentCount in interface Graph<ST extends GraphSegment<ST,​PT>,​PT extends GraphPoint<PT,​ST>>
        Returns:
        the count of segments in this graph.
      • getPointCount

        @Pure
        public final int getPointCount()
        Description copied from interface: Graph
        Replies the count of points in this graph.
        Specified by:
        getPointCount in interface Graph<ST extends GraphSegment<ST,​PT>,​PT extends GraphPoint<PT,​ST>>
        Returns:
        the count of points in this graph.
      • depthIterator

        @Pure
        public GraphIterator<ST,​PT> depthIterator​(ST startingSegment,
                                                        double depth,
                                                        double positionFromStartingPoint,
                                                        PT startingPoint,
                                                        boolean allowManyReplies,
                                                        boolean assumeOrientedSegments,
                                                        DynamicDepthUpdater<ST,​PT> dynamicDepthUpdater)
        Description copied from interface: Graph
        Replies an iterator that permits to move along the segment's graph starting from the specified segment and from the specified starting point. If the specified starting point is not one of the ends of the segment, this function assumes to start from the point replied by GraphSegment.getBeginPoint().

        This function does not allow the cycles during the iterations.

        Specified by:
        depthIterator in interface Graph<ST extends GraphSegment<ST,​PT>,​PT extends GraphPoint<PT,​ST>>
        Parameters:
        startingSegment - is the first segment to iterate.
        depth - is the maximal depth to reach.
        positionFromStartingPoint - is the starting position from the startingPoint.
        startingPoint - is the starting point of the iterations.
        allowManyReplies - may be true to allow to reply many times the same segment, otherwhise false.
        assumeOrientedSegments - may be true 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 is false to assume that the end points of a segment are not distinguished.
        dynamicDepthUpdater - if not null, it is a lambda that is used for dynamically updating the maximal depth.
        Returns:
        the iterator.
        See Also:
        Graph.depthIterator(GraphSegment, double, double, GraphPoint, boolean, boolean)
      • iterator

        @Pure
        public GraphIterator<ST,​PT> iterator​(ST startingSegment,
                                                   PT startingPoint,
                                                   boolean allowManyReplies,
                                                   boolean assumeOrientedSegments)
        Description copied from interface: Graph
        Replies an iterator that permits to move along the road segment's graph starting from this road segment and from the specified starting point.
        Specified by:
        iterator in interface Graph<ST extends GraphSegment<ST,​PT>,​PT extends GraphPoint<PT,​ST>>
        Parameters:
        startingSegment - is the first segment to iterate.
        startingPoint - is the starting point of the iterations.
        allowManyReplies - may be true to allow to reply many times the same segment, otherwhise false.
        assumeOrientedSegments - may be true 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 is false to assume that the end points of a segment are not distinguished.
        Returns:
        the iterator.