Package com.luciad.network.graph
Class TLcdGraph<N,E>
java.lang.Object
com.luciad.network.graph.TLcdGraph<N,E>
- All Implemented Interfaces:
ILcdEditableGraph<N,
,E> ILcdGraph<N,
E>
Implementation of
ILcdGraph
.
This implementation uses equals() and hashCode() to identify the nodes and edges
it contains - a correct implementation of both methods is thus required for all
edges and nodes contained in this graph.- Since:
- 5.1
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds an edge to this graph, connecting the two given nodes.void
addGraphListener
(ILcdGraphListener<N, E> aGraphListener) Registers the givenILcdGraphListener
with this graph.void
Adds a node to this graph.boolean
canAddEdge
(E aEdge, N aStartNode, N aEndNode) Returnstrue
if the given edge can be added to this graph,false
otherwise.boolean
canAddNode
(N aNode) Returnstrue
if the given node can be added to this graph,false
otherwise.boolean
canRemoveEdge
(E aEdge) Returnstrue
if the given edge can be removed from this graph,false
otherwise.boolean
canRemoveNode
(N aNode) Returnstrue
if the given node can be removed from this graph,false
otherwise.void
clear
(int aFireEventMode) Clears the graph; all edges and nodes are removed.boolean
containsEdge
(E aEdge) Returns true ifaEdge
is contained in this graph, false otherwise.boolean
containsNode
(N aNode) Returns true ifaNode
is part of this graph, false otherwise.void
edgeChanged
(E aEdge, int aEventMode) This method should be called when the given edge has changed.void
edgesChanged
(Vector<E> aEdges, int aEventMode) This method should be called when the given edges have changed.void
Fires all the collected graph changes, i.e., all graph events that have been generated using the the ILcdFireEventMode.FIRE_LATER mode, after the previous call tofireCollectedGraphChanges()
.getEdges()
Returns an Enumeration containing all edges in this graph.Returns an Enumeration containing all edges connected to the given node.getEndNode
(E aEdge) Returns the end node of the given edge in this graph.getNodes()
Returns an Enumeration containing all nodes in this graph.getOppositeNode
(E aEdge, N aNode) IfaNode
is one of the two nodes connected by the given edge in this graph, returns the other node, otherwise throwsIllegalArgumentException
.getStartNode
(E aEdge) Returns the start node of the given edge in this graph.boolean
isConnected
(E aEdge, N aNode) Returns true ifaNode
is one the nodes to which this edge is connected.void
nodeChanged
(N aNode, int aEventMode) This method should be called when the given node has changed.void
nodesChanged
(Vector<N> aNodes, int aEventMode) This method should be called when the given nodes have changed.removeEdge
(E aEdge, int aFireEventMode) Removes an edge from this graph.void
removeEdges
(int aFireEventMode) Removes all edges from this graph - nodes will remain in the graph.void
removeGraphListener
(ILcdGraphListener<N, E> aGraphListener) Unregisters the givenILcdGraphListener
from this graph.removeNode
(N aNode, int aFireEventMode) Removes a node from this graph.toString()
Returns a general description of this graph, containing the number of nodes and edges contained in this graph.
-
Constructor Details
-
TLcdGraph
public TLcdGraph()Constructs a new, empty graph.
-
-
Method Details
-
containsNode
Description copied from interface:ILcdGraph
Returns true ifaNode
is part of this graph, false otherwise.- Specified by:
containsNode
in interfaceILcdGraph<N,
E> - Parameters:
aNode
- the node to be checked.- Returns:
true
ifaNode
is part of the graph,false
otherwise.
-
getNodes
Description copied from interface:ILcdGraph
Returns an Enumeration containing all nodes in this graph. -
containsEdge
Description copied from interface:ILcdGraph
Returns true ifaEdge
is contained in this graph, false otherwise.- Specified by:
containsEdge
in interfaceILcdGraph<N,
E> - Parameters:
aEdge
- the edge to be checked- Returns:
true
ifaEdge
is part of the graph,false
otherwise.
-
getEdges
Description copied from interface:ILcdGraph
Returns an Enumeration containing all edges in this graph. -
getEdges
Description copied from interface:ILcdGraph
Returns an Enumeration containing all edges connected to the given node. -
getStartNode
Description copied from interface:ILcdGraph
Returns the start node of the given edge in this graph.- Specified by:
getStartNode
in interfaceILcdGraph<N,
E> - Parameters:
aEdge
- the edge whose start node should be returned.- Returns:
- the start node.
-
getEndNode
Description copied from interface:ILcdGraph
Returns the end node of the given edge in this graph.- Specified by:
getEndNode
in interfaceILcdGraph<N,
E> - Parameters:
aEdge
- the edge whose end node should be returned.- Returns:
- the end node.
-
getOppositeNode
Description copied from interface:ILcdGraph
IfaNode
is one of the two nodes connected by the given edge in this graph, returns the other node, otherwise throwsIllegalArgumentException
.- Specified by:
getOppositeNode
in interfaceILcdGraph<N,
E> - Parameters:
aEdge
- the edge whose opposite node should be returned.aNode
- one of the twoObject
's connected by the given edge.- Returns:
- if
aNode
is one of the two nodes connected by this edge, returns the other node connected by this edge.
-
isConnected
Description copied from interface:ILcdGraph
Returns true ifaNode
is one the nodes to which this edge is connected.- Specified by:
isConnected
in interfaceILcdGraph<N,
E> - Parameters:
aEdge
- the edge whose connectivity should be checked.aNode
- the node whose connectivity should be checked.- Returns:
- true if
aNode
is one the nodes to which this edge is connected.
-
addGraphListener
Description copied from interface:ILcdGraph
Registers the givenILcdGraphListener
with this graph. All events generated by this graph afterwards will be sent to the given listener, until it is removed from this graph.- Specified by:
addGraphListener
in interfaceILcdGraph<N,
E> - Parameters:
aGraphListener
- the graph listener to be registered with this graph.
-
removeGraphListener
Description copied from interface:ILcdGraph
Unregisters the givenILcdGraphListener
from this graph. After it has been unregistered, no events generated by this graph will be sent to the given listener anymore.- Specified by:
removeGraphListener
in interfaceILcdGraph<N,
E> - Parameters:
aGraphListener
- the graph listener to be unregistered from this graph.
-
canAddNode
Description copied from interface:ILcdEditableGraph
Returnstrue
if the given node can be added to this graph,false
otherwise. More specifically, a node can be added to this graph if the following conditions are met:- the node is not
null
- the node is not yet part of this graph
- the node satisfies all additional implementation-specific requirements (see the documentation of the implementing class).
- Specified by:
canAddNode
in interfaceILcdEditableGraph<N,
E> - Parameters:
aNode
- the node to be verified.- Returns:
true
if the node can be added to this graph,false
otherwise.
- the node is not
-
addNode
Description copied from interface:ILcdEditableGraph
Adds a node to this graph.- Specified by:
addNode
in interfaceILcdEditableGraph<N,
E> - Parameters:
aNode
- the node to be added to this graph.aFireEventMode
- the mode for sending out the TLcdGraphChangedEvent. This can be one ofILcdFireEventMode.FIRE_NOW, ILcdFireEventMode.FIRE_LATER or ILcdFireEventMode.NO_EVENT
.- Preconditions:
canAddNode(aNode)
- Note: this validation is potentially expensive, and should be avoided whenever possible.
-
canRemoveNode
Description copied from interface:ILcdEditableGraph
Returnstrue
if the given node can be removed from this graph,false
otherwise. More specifically, a node can be remove from this graph if the following conditions are met:- the node is not
null
- the node is part of this graph
- there are no edges in this graph, connected to the node
- Specified by:
canRemoveNode
in interfaceILcdEditableGraph<N,
E> - Parameters:
aNode
- the node to be verified.- Returns:
true
if the node can be removed from this graph,false
otherwise.
- the node is not
-
removeNode
Description copied from interface:ILcdEditableGraph
Removes a node from this graph.- Specified by:
removeNode
in interfaceILcdEditableGraph<N,
E> - Parameters:
aNode
- the node to be removed from this graph.aFireEventMode
- the mode for sending out the TLcdGraphChangedEvent. This can be one ofILcdFireEventMode.FIRE_NOW, ILcdFireEventMode.FIRE_LATER or ILcdFireEventMode.NO_EVENT
.- Preconditions:
canRemoveNode(aNode)
- Note: this validation is potentially expensive, and should be avoided whenever possible.- Returns:
- the node that was removed from the graph.
-
canAddEdge
Description copied from interface:ILcdEditableGraph
Returnstrue
if the given edge can be added to this graph,false
otherwise. More specifically, an edge can be added to this graph if the following conditions are met:- none of the arguments is
null
- the edge is not yet part of this graph
- both nodes are part of this graph
- the edge satisfies all additional implementation-specific requirements (see the documentation of the implementing class).
- Specified by:
canAddEdge
in interfaceILcdEditableGraph<N,
E> - Parameters:
aEdge
- the edge to be verified.aStartNode
- the first node that should be connected by the given edge.aEndNode
- the second node that should be connected by the given edge.- Returns:
true
if the edge can be added to this graph,false
otherwise.
- none of the arguments is
-
addEdge
Description copied from interface:ILcdEditableGraph
Adds an edge to this graph, connecting the two given nodes.- Specified by:
addEdge
in interfaceILcdEditableGraph<N,
E> - Parameters:
aEdge
- the edge to be added to this graph.aStartNode
- the first node that should be connected by the given edge.aEndNode
- the second node that should be connected by the given edge.aFireEventMode
- the mode for sending out the TLcdGraphChangedEvent. This can be one ofILcdFireEventMode.FIRE_NOW, ILcdFireEventMode.FIRE_LATER or ILcdFireEventMode.NO_EVENT
.- Preconditions:
canAddEdge(aEdge, aStartNode, aEndNode)
- Note: this validation is potentially expensive, and should be avoided whenever possible.
-
canRemoveEdge
Description copied from interface:ILcdEditableGraph
Returnstrue
if the given edge can be removed from this graph,false
otherwise. More specifically, a edge can be remove from this graph if the following conditions are met:- the edge is not
null
- the edge is part of this graph
- Specified by:
canRemoveEdge
in interfaceILcdEditableGraph<N,
E> - Parameters:
aEdge
- the edge to be verified.- Returns:
true
if the edge can be removed from this graph,false
otherwise.
- the edge is not
-
removeEdge
Description copied from interface:ILcdEditableGraph
Removes an edge from this graph.- Specified by:
removeEdge
in interfaceILcdEditableGraph<N,
E> - Parameters:
aEdge
- the edge to be removed from this graph.aFireEventMode
- the mode for sending out the TLcdGraphChangedEvent. This can be one ofILcdFireEventMode.FIRE_NOW, ILcdFireEventMode.FIRE_LATER or ILcdFireEventMode.NO_EVENT
.- Preconditions:
canRemoveEdge(aEdge)
- Note: this validation is potentially expensive, and should be avoided whenever possible.- Returns:
- the edge which was removed from the graph.
-
removeEdges
public void removeEdges(int aFireEventMode) Description copied from interface:ILcdEditableGraph
Removes all edges from this graph - nodes will remain in the graph.- Specified by:
removeEdges
in interfaceILcdEditableGraph<N,
E> - Parameters:
aFireEventMode
- the mode for sending out the TLcdGraphChangedEvent. This can be one ofILcdFireEventMode.FIRE_NOW, ILcdFireEventMode.FIRE_LATER or ILcdFireEventMode.NO_EVENT
.
-
clear
public void clear(int aFireEventMode) Description copied from interface:ILcdEditableGraph
Clears the graph; all edges and nodes are removed.- Specified by:
clear
in interfaceILcdEditableGraph<N,
E> - Parameters:
aFireEventMode
- the mode for sending out the TLcdGraphChangedEvent. This can be one ofILcdFireEventMode.FIRE_NOW, ILcdFireEventMode.FIRE_LATER or ILcdFireEventMode.NO_EVENT
.
-
fireCollectedGraphChanges
public void fireCollectedGraphChanges()Description copied from interface:ILcdEditableGraph
Fires all the collected graph changes, i.e., all graph events that have been generated using the the ILcdFireEventMode.FIRE_LATER mode, after the previous call tofireCollectedGraphChanges()
. Note that afireCollectedGraphChanges()
call is made whenever a graph event is generated in theILcdFireEventMode.FIRE_NOW
, to guarantee the correct order of the events.- Specified by:
fireCollectedGraphChanges
in interfaceILcdEditableGraph<N,
E>
-
nodeChanged
Description copied from interface:ILcdEditableGraph
This method should be called when the given node has changed.- Preconditions:
containsPartition(aNode)
- Note: this validation is potentially expensive, and should be avoided whenever possible.- Specified by:
nodeChanged
in interfaceILcdEditableGraph<N,
E> - Parameters:
aNode
- the node that has changed.aEventMode
- the mode for sending out the TLcdGraphChangedEvent. This can be one ofILcdFireEventMode.FIRE_NOW, ILcdFireEventMode.FIRE_LATER or ILcdFireEventMode.NO_EVENT
.
-
nodesChanged
Description copied from interface:ILcdEditableGraph
This method should be called when the given nodes have changed.- Specified by:
nodesChanged
in interfaceILcdEditableGraph<N,
E> - Parameters:
aNodes
- a vector containing the nodes that have changed.aEventMode
- the mode for sending out the TLcdGraphChangedEvent. This can be one ofILcdFireEventMode.FIRE_NOW, ILcdFireEventMode.FIRE_LATER or ILcdFireEventMode.NO_EVENT
.- Preconditions:
- for each
node
object in the given vector should hold that:containsPartition(node)
- Note: this validation is potentially expensive, and should be avoided whenever possible.
-
edgeChanged
Description copied from interface:ILcdEditableGraph
This method should be called when the given edge has changed.- Specified by:
edgeChanged
in interfaceILcdEditableGraph<N,
E> - Parameters:
aEdge
- the edge that has changed.aEventMode
- the mode for sending out the TLcdGraphChangedEvent. This can be one ofILcdFireEventMode.FIRE_NOW, ILcdFireEventMode.FIRE_LATER or ILcdFireEventMode.NO_EVENT
.- Preconditions:
containsBoundaryEdge(aEdge)
- Note: this validation is potentially expensive, and should be avoided whenever possible.
-
edgesChanged
Description copied from interface:ILcdEditableGraph
This method should be called when the given edges have changed.- Specified by:
edgesChanged
in interfaceILcdEditableGraph<N,
E> - Parameters:
aEdges
- a vector containing the edges that have changed.aEventMode
- the mode for sending out the TLcdGraphChangedEvent. This can be one ofILcdFireEventMode.FIRE_NOW, ILcdFireEventMode.FIRE_LATER or ILcdFireEventMode.NO_EVENT
.- Preconditions:
- for each
edge
object in the given vector should hold that:containsBoundaryEdge(edge)
- Note: this validation is potentially expensive, and should be avoided whenever possible.
-
toString
Returns a general description of this graph, containing the number of nodes and edges contained in this graph. The exact details of the representation are unspecified and are subject to change.
-