Class LinkSegmentsImpl<LS extends LinkSegment>

  • Type Parameters:
    LS - link segments type
    All Implemented Interfaces:
    Iterable<LS>, EdgeSegments<LS>, LinkSegments<LS>

    public class LinkSegmentsImpl<LS extends LinkSegment>
    extends Object
    implements LinkSegments<LS>
    Links implementation wrapper that simply utilises passed in edges of the desired generic type to delegate registration and creation of its links on
    Author:
    markr
    • Constructor Detail

      • LinkSegmentsImpl

        public LinkSegmentsImpl​(EdgeSegments<LS> edgeSegments)
        Constructor
        Parameters:
        edgeSegments - to use to create and register link segments on
    • Method Detail

      • registerStartNode

        protected void registerStartNode​(LS linkSegment)
        Register a link segment on the network
        Parameters:
        linkSegment - the link segment to be registered
      • remove

        public void remove​(LS linkSegment)
        Remove an edges segment
        Specified by:
        remove in interface EdgeSegments<LS extends LinkSegment>
        Parameters:
        linkSegment - to remove
      • remove

        public void remove​(long edgeSegmentId)
        Remove an edge segment by id
        Specified by:
        remove in interface EdgeSegments<LS extends LinkSegment>
        Parameters:
        edgeSegmentId - to remove by id
      • register

        public void register​(DirectedEdge parentEdge,
                             LS edgeSegment,
                             boolean directionAB)
                      throws PlanItException
        Register a edge segment (not registered on nodes and edge)
        Specified by:
        register in interface EdgeSegments<LS extends LinkSegment>
        Parameters:
        parentEdge - the parent edge which specified edge segment will be registered on
        edgeSegment - edge segment to be registered
        directionAB - direction of travel
        Throws:
        PlanItException - thrown if there is an error
      • get

        public LS get​(long id)
        Get edge segment by id
        Specified by:
        get in interface EdgeSegments<LS extends LinkSegment>
        Parameters:
        id - id of the edge segment
        Returns:
        retrieved edge Segment
      • getByXmlId

        public LS getByXmlId​(String xmlId)
        Return an edge segment by its Xml id Note: not an efficient implementation since it loops over all link segments in linear time to identify the correct one, preferably use get instead whenever possible.
        Specified by:
        getByXmlId in interface EdgeSegments<LS extends LinkSegment>
        Parameters:
        xmlId - the XML id of the edge segment
        Returns:
        the specified edge segment instance
      • size

        public long size()
        Return number of registered edge segments
        Specified by:
        size in interface EdgeSegments<LS extends LinkSegment>
        Returns:
        number of registered edge segments
      • registerUniqueCopyOf

        public LS registerUniqueCopyOf​(LS edgeSegmentToCopy,
                                       DirectedEdge newParent)
        copy the passed in edge segment and register it.
        Specified by:
        registerUniqueCopyOf in interface EdgeSegments<LS extends LinkSegment>
        Parameters:
        edgeSegmentToCopy - as is except for its ids which will be updated to make it uniquely identifiable
        newParent - update the parent edge to passed in edge
        Returns:
        copy of edge segment now registered
      • registerNew

        public LS registerNew​(DirectedEdge parentEdge,
                              boolean directionAb,
                              boolean registerOnNodeAndLink)
                       throws PlanItException
        Create directional edge segment and register it
        Specified by:
        registerNew in interface EdgeSegments<LS extends LinkSegment>
        Parameters:
        parentEdge - the parent edge of this edge segment
        directionAb - direction of travel
        registerOnNodeAndLink - option to register the new edge segment on the underlying edge and its vertices
        Returns:
        the created edge segment
        Throws:
        PlanItException - thrown if there is an error
      • getByExternalId

        public LS getByExternalId​(String externalId)
        Retrieve a link segment by its external Id This method is not efficient, since it loops through all the registered link segments in order to find the required link segment. TODO: currently utilised in Python wrapper via get_by_external_id as well as for feature in initial costs that can be provided by external id, this should be refactored such that this is no longer possible, or be made more efficient.
        Specified by:
        getByExternalId in interface LinkSegments<LS extends LinkSegment>
        Parameters:
        externalId - the external Id of the specified link segment type
        Returns:
        the retrieved link segment, or null if no link segment type was found