Package org.planit.network.physical
Class LinkSegmentsImpl<LS extends LinkSegment>
- java.lang.Object
-
- org.planit.network.physical.LinkSegmentsImpl<LS>
-
- 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 Summary
Constructors Constructor Description LinkSegmentsImpl(EdgeSegments<LS> edgeSegments)
Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description LS
create(DirectedEdge parent, boolean directionAB)
Create edge segmentLS
get(long id)
Get edge segment by idLS
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.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.Iterator<LS>
iterator()
void
register(DirectedEdge parentEdge, LS edgeSegment, boolean directionAB)
Register a edge segment (not registered on nodes and edge)LS
registerNew(DirectedEdge parentEdge, boolean directionAb, boolean registerOnNodeAndLink)
Create directional edge segment and register itprotected void
registerStartNode(LS linkSegment)
Register a link segment on the networkLS
registerUniqueCopyOf(LS edgeSegmentToCopy, DirectedEdge newParent)
copy the passed in edge segment and register it.void
remove(long edgeSegmentId)
Remove an edge segment by idvoid
remove(LS linkSegment)
Remove an edges segmentlong
size()
Return number of registered edge segments-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.planit.utils.graph.EdgeSegments
isEmpty
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
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 interfaceEdgeSegments<LS extends LinkSegment>
- Parameters:
linkSegment
- to remove
-
remove
public void remove(long edgeSegmentId)
Remove an edge segment by id- Specified by:
remove
in interfaceEdgeSegments<LS extends LinkSegment>
- Parameters:
edgeSegmentId
- to remove by id
-
create
public LS create(DirectedEdge parent, boolean directionAB) throws PlanItException
Create edge segment- Specified by:
create
in interfaceEdgeSegments<LS extends LinkSegment>
- Parameters:
parent
- the parent edge of this edge segmentdirectionAB
- direction of travel- Returns:
- the created edge segment
- Throws:
PlanItException
- thrown if there is an error
-
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 interfaceEdgeSegments<LS extends LinkSegment>
- Parameters:
parentEdge
- the parent edge which specified edge segment will be registered onedgeSegment
- edge segment to be registereddirectionAB
- 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 interfaceEdgeSegments<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 interfaceEdgeSegments<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 interfaceEdgeSegments<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 interfaceEdgeSegments<LS extends LinkSegment>
- Parameters:
edgeSegmentToCopy
- as is except for its ids which will be updated to make it uniquely identifiablenewParent
- update the parent edge to passed in edge- Returns:
- copy of edge segment now registered
-
iterator
public Iterator<LS> iterator()
- Specified by:
iterator
in interfaceIterable<LS extends LinkSegment>
-
registerNew
public LS registerNew(DirectedEdge parentEdge, boolean directionAb, boolean registerOnNodeAndLink) throws PlanItException
Create directional edge segment and register it- Specified by:
registerNew
in interfaceEdgeSegments<LS extends LinkSegment>
- Parameters:
parentEdge
- the parent edge of this edge segmentdirectionAb
- direction of travelregisterOnNodeAndLink
- 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 interfaceLinkSegments<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
-
-