Package org.goplanit.graph.modifier
Class DirectedGraphModifierImpl
- java.lang.Object
-
- org.goplanit.utils.event.EventProducerImpl
-
- org.goplanit.graph.modifier.DirectedGraphModifierImpl
-
- All Implemented Interfaces:
EventProducer
,DirectedGraphModifier
,DirectedGraphModifierEventProducer
,GraphModifierEventProducer
,GraphModifier<DirectedVertex,DirectedEdge>
,TopologicalModifier
public class DirectedGraphModifierImpl extends EventProducerImpl implements DirectedGraphModifier
Implementation of a directed graph modifier that supports making changes to any untyped directed graph. The benefit of using the untyped directed graph is that it does not rely on knowing the specific typed containers used for vertices, edges, edge segments which in turn signals that no information on the underlying factories is required.- Author:
- markr
-
-
Field Summary
-
Fields inherited from class org.goplanit.utils.event.EventProducerImpl
listeners
-
-
Constructor Summary
Constructors Constructor Description DirectedGraphModifierImpl(UntypedDirectedGraph<?,?,?> theDirectedGraph)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addListener(GraphModifierListener listener)
Register listener for all its supported types fired by the graph modifiervoid
addListener(GraphModifierListener listener, GraphModifierEventType eventType)
Register listeners for events fired by the graph modifier<Ex extends DirectedEdge>
ExbreakEdgeAt(DirectedVertex vertexToBreakAt, Ex edgeToBreak, PlanitJtsCrsUtils geoUtils)
Identical to theGraphImpl
implementation except that we now also account for the edge segments present on the edge.<Ex extends DirectedEdge>
Map<Long,Set<Ex>>breakEdgesAt(List<Ex> edgesToBreak, DirectedVertex vertexToBreakAt, org.opengis.referencing.crs.CoordinateReferenceSystem crs)
Break the passed in edges by inserting the passed in vertex in between.protected void
fireEvent(EventListener eventListener, Event event)
Depending on whether these are directed or undirected evens call the appropriate notification methodprotected UntypedDirectedGraph<?,?,?>
getUntypedDirectedGraph()
Access to directed graph we are modifyingvoid
recreateManagedEntitiesIds()
This method will recreate all ids of the graph's components, e.g., vertices, edges, etc.void
removeDanglingSubGraphs(Integer belowSize, Integer aboveSize, boolean alwaysKeepLargest)
remove any dangling subgraphs below a given size from the graph if they exist and subsequently reorder the internal ids if neededvoid
removeListener(GraphModifierListener listener)
Remove listener for all event types it is registered forvoid
removeListener(GraphModifierListener listener, GraphModifierEventType eventType)
Remove listener for given event typevoid
removeSubGraph(Set<? extends DirectedVertex> subGraphToRemove)
remove the subgraph identified by the passed in verticesvoid
removeSubGraphOf(DirectedVertex referenceVertex)
remove the (sub)graph in which the passed in vertex resides.void
reset()
reset all state related information of the instance-
Methods inherited from class org.goplanit.utils.event.EventProducerImpl
addListener, addListener, addListener, addListener, fireEvent, getEventTypesWithListeners, hasListener, hasListeners, numberOfListeners, removeAllListeners, removeListener, removeListener
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.goplanit.utils.graph.modifier.GraphModifier
breakEdgesAt, removeDanglingSubGraphs
-
Methods inherited from interface org.goplanit.utils.graph.modifier.event.GraphModifierEventProducer
removeAllListeners
-
-
-
-
Constructor Detail
-
DirectedGraphModifierImpl
public DirectedGraphModifierImpl(UntypedDirectedGraph<?,?,?> theDirectedGraph)
Constructor.- Parameters:
theDirectedGraph
- to use
-
-
Method Detail
-
fireEvent
protected void fireEvent(EventListener eventListener, Event event)
Depending on whether these are directed or undirected evens call the appropriate notification method- Specified by:
fireEvent
in classEventProducerImpl
- Parameters:
eventListener
- to notify for the eventevent
- to process for the listener
-
getUntypedDirectedGraph
protected UntypedDirectedGraph<?,?,?> getUntypedDirectedGraph()
Access to directed graph we are modifying- Returns:
- directed graph
-
removeSubGraph
public void removeSubGraph(Set<? extends DirectedVertex> subGraphToRemove)
remove the subgraph identified by the passed in vertices- Specified by:
removeSubGraph
in interfaceGraphModifier<DirectedVertex,DirectedEdge>
- Parameters:
subGraphToRemove
- the one to remove
-
recreateManagedEntitiesIds
public void recreateManagedEntitiesIds()
This method will recreate all ids of the graph's components, e.g., vertices, edges, etc. but only when the containers used for them are the primary ManagedIdEntities containers, i.e., when the graph is responsible of uniquely tracking all entities by their managed id. If not, for example, if this is a subgraph reusing parts of the main graph, it will not recreate the ids.The reasoning is that if we would recreate ids of the container while the container does not contain all = let's say - vertices, their managedId is no longer guaranteed to be unique which can lead to issues
Method can be used in conjunctions with the removal of parts of the graph and the result is required to have unique contiguous ids
- Specified by:
recreateManagedEntitiesIds
in interfaceGraphModifier<DirectedVertex,DirectedEdge>
-
breakEdgeAt
public <Ex extends DirectedEdge> Ex breakEdgeAt(DirectedVertex vertexToBreakAt, Ex edgeToBreak, PlanitJtsCrsUtils geoUtils) throws PlanItException
Identical to theGraphImpl
implementation except that we now also account for the edge segments present on the edge. Copies of the original edge segments are placed on (vertexToBreakAt,vertexB), while the original ones are retained at (vertexA,vertexToBreakAt)- Specified by:
breakEdgeAt
in interfaceGraphModifier<DirectedVertex,DirectedEdge>
- Type Parameters:
Ex
- edge type- Parameters:
edgeToBreak
- edge to breakvertexToBreakAt
- the vertex to break atgeoUtils
- required to update edge lengths- Returns:
- newly created edge due to breaking, null if not feasible
- Throws:
PlanItException
- thrown if error
-
breakEdgesAt
public <Ex extends DirectedEdge> Map<Long,Set<Ex>> breakEdgesAt(List<Ex> edgesToBreak, DirectedVertex vertexToBreakAt, org.opengis.referencing.crs.CoordinateReferenceSystem crs) throws PlanItException
Break the passed in edges by inserting the passed in vertex in between. After completion the original edges remain as (VertexA,VertexToBreakAt), and new edges are inserted for (VertexToBreakAt,VertexB).- Specified by:
breakEdgesAt
in interfaceGraphModifier<DirectedVertex,DirectedEdge>
- Type Parameters:
Ex
- edge type- Parameters:
edgesToBreak
- the links to breakvertexToBreakAt
- the node to break atcrs
- required to update edge lengths- Returns:
- affectedEdges the list of all result edges of the breaking of links by their original link id
- Throws:
PlanItException
- thrown if error
-
removeDanglingSubGraphs
public void removeDanglingSubGraphs(Integer belowSize, Integer aboveSize, boolean alwaysKeepLargest) throws PlanItException
remove any dangling subgraphs below a given size from the graph if they exist and subsequently reorder the internal ids if needed- Specified by:
removeDanglingSubGraphs
in interfaceGraphModifier<DirectedVertex,DirectedEdge>
- Parameters:
belowSize
- remove subgraphs below the given sizeaboveSize
- remove subgraphs above the given size (typically set to maximum value)alwaysKeepLargest
- indicate if the largest of the subgraphs is always to be kept even if it does not match the criteria- Throws:
PlanItException
- thrown if error
-
removeSubGraphOf
public void removeSubGraphOf(DirectedVertex referenceVertex) throws PlanItException
remove the (sub)graph in which the passed in vertex resides. Apply reordering of internal ids of remaining network.- Specified by:
removeSubGraphOf
in interfaceGraphModifier<DirectedVertex,DirectedEdge>
- Parameters:
referenceVertex
- to identify subnetwork by- Throws:
PlanItException
- thrown if error
-
reset
public void reset()
reset all state related information of the instance- Specified by:
reset
in interfaceGraphModifier<DirectedVertex,DirectedEdge>
-
addListener
public void addListener(GraphModifierListener listener)
Register listener for all its supported types fired by the graph modifier- Specified by:
addListener
in interfaceGraphModifierEventProducer
- Parameters:
listener
- to register
-
addListener
public void addListener(GraphModifierListener listener, GraphModifierEventType eventType)
Register listeners for events fired by the graph modifier- Specified by:
addListener
in interfaceGraphModifierEventProducer
- Parameters:
listener
- to registereventType
- to register listener for
-
removeListener
public void removeListener(GraphModifierListener listener, GraphModifierEventType eventType)
Remove listener for given event type- Specified by:
removeListener
in interfaceGraphModifierEventProducer
- Parameters:
listener
- to removeeventType
- to unregister listener for
-
removeListener
public void removeListener(GraphModifierListener listener)
Remove listener for all event types it is registered for- Specified by:
removeListener
in interfaceGraphModifierEventProducer
- Parameters:
listener
- to remove
-
-