public class TLcdGraph<N,E> extends Object implements ILcdEditableGraph<N,E>
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.Constructor and Description |
---|
TLcdGraph()
Constructs a new, empty graph.
|
Modifier and Type | Method and Description |
---|---|
void |
addEdge(E aEdge,
N aStartNode,
N aEndNode,
int aFireEventMode)
Adds an edge to this graph, connecting the two given nodes.
|
void |
addGraphListener(ILcdGraphListener<N,E> aGraphListener)
Registers the given
ILcdGraphListener with this graph. |
void |
addNode(N aNode,
int aFireEventMode)
Adds a node to this graph.
|
boolean |
canAddEdge(E aEdge,
N aStartNode,
N aEndNode)
Returns
true if the given edge can be added to this graph,
false otherwise. |
boolean |
canAddNode(N aNode)
Returns
true if the given node can be added to this graph,
false otherwise. |
boolean |
canRemoveEdge(E aEdge)
Returns
true if the given edge can be removed from this graph,
false otherwise. |
boolean |
canRemoveNode(N aNode)
Returns
true 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 if
aEdge is contained in this graph, false otherwise. |
boolean |
containsNode(N aNode)
Returns true if
aNode 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 |
fireCollectedGraphChanges()
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 to
fireCollectedGraphChanges() . |
Enumeration<E> |
getEdges()
Returns an Enumeration containing all edges in this graph.
|
Enumeration<E> |
getEdges(N aNode)
Returns an Enumeration containing all edges connected to the given node.
|
N |
getEndNode(E aEdge)
Returns the end node of the given edge in this graph.
|
Enumeration<N> |
getNodes()
Returns an Enumeration containing all nodes in this graph.
|
N |
getOppositeNode(E aEdge,
N aNode)
If
aNode is one of the two nodes connected by the given edge in this graph, returns the other node,
otherwise throws IllegalArgumentException . |
N |
getStartNode(E aEdge)
Returns the start node of the given edge in this graph.
|
boolean |
isConnected(E aEdge,
N aNode)
Returns true if
aNode 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.
|
E |
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 given
ILcdGraphListener from this graph. |
N |
removeNode(N aNode,
int aFireEventMode)
Removes a node from this graph.
|
String |
toString()
Returns a general description of this graph, containing the number of nodes and
edges contained in this graph.
|
public boolean containsNode(N aNode)
ILcdGraph
aNode
is part of this graph, false otherwise.containsNode
in interface ILcdGraph<N,E>
aNode
- the node to be checked.true
if aNode
is part of the graph, false
otherwise.public Enumeration<N> getNodes()
ILcdGraph
public boolean containsEdge(E aEdge)
ILcdGraph
aEdge
is contained in this graph, false otherwise.containsEdge
in interface ILcdGraph<N,E>
aEdge
- the edge to be checkedtrue
if aEdge
is part of the graph, false
otherwise.public Enumeration<E> getEdges()
ILcdGraph
public Enumeration<E> getEdges(N aNode)
ILcdGraph
public N getStartNode(E aEdge)
ILcdGraph
getStartNode
in interface ILcdGraph<N,E>
aEdge
- the edge whose start node should be returned.public N getEndNode(E aEdge)
ILcdGraph
getEndNode
in interface ILcdGraph<N,E>
aEdge
- the edge whose end node should be returned.public N getOppositeNode(E aEdge, N aNode)
ILcdGraph
aNode
is one of the two nodes connected by the given edge in this graph, returns the other node,
otherwise throws IllegalArgumentException
.getOppositeNode
in interface ILcdGraph<N,E>
aEdge
- the edge whose opposite node should be returned.aNode
- one of the two Object
's connected by the given edge.aNode
is one of the two nodes connected by this edge, returns the other
node connected by this edge.public boolean isConnected(E aEdge, N aNode)
ILcdGraph
aNode
is one the nodes to which this edge is connected.isConnected
in interface ILcdGraph<N,E>
aEdge
- the edge whose connectivity should be checked.aNode
- the node whose connectivity should be checked.aNode
is one the nodes to which this edge is connected.public void addGraphListener(ILcdGraphListener<N,E> aGraphListener)
ILcdGraph
ILcdGraphListener
with this graph. All events
generated by this graph afterwards will be sent to the given listener, until
it is removed from this graph.addGraphListener
in interface ILcdGraph<N,E>
aGraphListener
- the graph listener to be registered with this graph.public void removeGraphListener(ILcdGraphListener<N,E> aGraphListener)
ILcdGraph
ILcdGraphListener
from this graph. After it
has been unregistered, no events generated by this graph will be sent to the
given listener anymore.removeGraphListener
in interface ILcdGraph<N,E>
aGraphListener
- the graph listener to be unregistered from this graph.public boolean canAddNode(N aNode)
ILcdEditableGraph
true
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:
null
canAddNode
in interface ILcdEditableGraph<N,E>
aNode
- the node to be verified.true
if the node can be added to this graph,
false
otherwise.public void addNode(N aNode, int aFireEventMode)
ILcdEditableGraph
addNode
in interface ILcdEditableGraph<N,E>
aNode
- the node to be added to this graph.aFireEventMode
- the mode for sending out the TLcdGraphChangedEvent. This
can be one of ILcdFireEventMode.FIRE_NOW,
ILcdFireEventMode.FIRE_LATER or ILcdFireEventMode.NO_EVENT
.
canAddNode(aNode)
-
Note: this validation is potentially expensive, and should be avoided
whenever possible.public boolean canRemoveNode(N aNode)
ILcdEditableGraph
true
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:
null
canRemoveNode
in interface ILcdEditableGraph<N,E>
aNode
- the node to be verified.true
if the node can be removed from this graph,
false
otherwise.public N removeNode(N aNode, int aFireEventMode)
ILcdEditableGraph
removeNode
in interface ILcdEditableGraph<N,E>
aNode
- the node to be removed from this graph.aFireEventMode
- the mode for sending out the TLcdGraphChangedEvent. This
can be one of ILcdFireEventMode.FIRE_NOW,
ILcdFireEventMode.FIRE_LATER or ILcdFireEventMode.NO_EVENT
.
canRemoveNode(aNode)
-
Note: this validation is potentially expensive, and should be avoided
whenever possible.public boolean canAddEdge(E aEdge, N aStartNode, N aEndNode)
ILcdEditableGraph
true
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:
null
canAddEdge
in interface ILcdEditableGraph<N,E>
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.true
if the edge can be added to this graph,
false
otherwise.public void addEdge(E aEdge, N aStartNode, N aEndNode, int aFireEventMode)
ILcdEditableGraph
addEdge
in interface ILcdEditableGraph<N,E>
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 of ILcdFireEventMode.FIRE_NOW,
ILcdFireEventMode.FIRE_LATER or ILcdFireEventMode.NO_EVENT
.
canAddEdge(aEdge, aStartNode, aEndNode)
-
Note: this validation is potentially expensive, and should be avoided
whenever possible.public boolean canRemoveEdge(E aEdge)
ILcdEditableGraph
true
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:
null
canRemoveEdge
in interface ILcdEditableGraph<N,E>
aEdge
- the edge to be verified.true
if the edge can be removed from this graph,
false
otherwise.public E removeEdge(E aEdge, int aFireEventMode)
ILcdEditableGraph
removeEdge
in interface ILcdEditableGraph<N,E>
aEdge
- the edge to be removed from this graph.aFireEventMode
- the mode for sending out the TLcdGraphChangedEvent. This
can be one of ILcdFireEventMode.FIRE_NOW,
ILcdFireEventMode.FIRE_LATER or ILcdFireEventMode.NO_EVENT
.
canRemoveEdge(aEdge)
-
Note: this validation is potentially expensive, and should be avoided
whenever possible.public void removeEdges(int aFireEventMode)
ILcdEditableGraph
removeEdges
in interface ILcdEditableGraph<N,E>
aFireEventMode
- the mode for sending out the TLcdGraphChangedEvent. This
can be one of ILcdFireEventMode.FIRE_NOW,
ILcdFireEventMode.FIRE_LATER or ILcdFireEventMode.NO_EVENT
.public void clear(int aFireEventMode)
ILcdEditableGraph
clear
in interface ILcdEditableGraph<N,E>
aFireEventMode
- the mode for sending out the TLcdGraphChangedEvent. This
can be one of ILcdFireEventMode.FIRE_NOW,
ILcdFireEventMode.FIRE_LATER or ILcdFireEventMode.NO_EVENT
.public void fireCollectedGraphChanges()
ILcdEditableGraph
fireCollectedGraphChanges()
.
Note that a fireCollectedGraphChanges()
call is made whenever
a graph event is generated in the ILcdFireEventMode.FIRE_NOW
,
to guarantee the correct order of the events.fireCollectedGraphChanges
in interface ILcdEditableGraph<N,E>
public void nodeChanged(N aNode, int aEventMode)
ILcdEditableGraph
containsPartition(aNode)
-
Note: this validation is potentially expensive, and should be avoided
whenever possible.nodeChanged
in interface ILcdEditableGraph<N,E>
aNode
- the node that has changed.aEventMode
- the mode for sending out the TLcdGraphChangedEvent. This
can be one of ILcdFireEventMode.FIRE_NOW,
ILcdFireEventMode.FIRE_LATER or ILcdFireEventMode.NO_EVENT
.public void nodesChanged(Vector<N> aNodes, int aEventMode)
ILcdEditableGraph
nodesChanged
in interface ILcdEditableGraph<N,E>
aNodes
- a vector containing the nodes that have changed.aEventMode
- the mode for sending out the TLcdGraphChangedEvent. This
can be one of ILcdFireEventMode.FIRE_NOW,
ILcdFireEventMode.FIRE_LATER or ILcdFireEventMode.NO_EVENT
.
node
object in the given vector should hold that:
containsPartition(node)
-
Note: this validation is potentially expensive, and should be avoided
whenever possible.public void edgeChanged(E aEdge, int aEventMode)
ILcdEditableGraph
edgeChanged
in interface ILcdEditableGraph<N,E>
aEdge
- the edge that has changed.aEventMode
- the mode for sending out the TLcdGraphChangedEvent. This
can be one of ILcdFireEventMode.FIRE_NOW,
ILcdFireEventMode.FIRE_LATER or ILcdFireEventMode.NO_EVENT
.
containsBoundaryEdge(aEdge)
-
Note: this validation is potentially expensive, and should be avoided
whenever possible.public void edgesChanged(Vector<E> aEdges, int aEventMode)
ILcdEditableGraph
edgesChanged
in interface ILcdEditableGraph<N,E>
aEdges
- a vector containing the edges that have changed.aEventMode
- the mode for sending out the TLcdGraphChangedEvent. This
can be one of ILcdFireEventMode.FIRE_NOW,
ILcdFireEventMode.FIRE_LATER or ILcdFireEventMode.NO_EVENT
.
edge
object in the given vector should hold that:
containsBoundaryEdge(edge)
-
Note: this validation is potentially expensive, and should be avoided
whenever possible.