public class TLcdLimitedEditablePartitionedGraph<N,E> extends Object implements ILcdLimitedEditablePartitionedGraph<N,E>
ILcdLimitedEditablePartitionedGraph
. The
getPartitionForNode
and getPartitionForEdge
methods
can be overwritten by subclasses to improve the performance of this graph
(e.g. when the partition to which a node belongs can be retrieved based on
the geographical location of the node).Constructor and Description |
---|
TLcdLimitedEditablePartitionedGraph()
Constructs a new, empty
TLcdLimitedEditablePartitionedGraph . |
Modifier and Type | Method and Description |
---|---|
void |
addBoundaryEdge(E aEdge,
N aStartNode,
N aEndNode,
int aPartitionedGraphFireEventMode,
int aGraphFireEventMode)
Adds the given edge to the boundary graph of this partitioned graph.
|
void |
addGraphListener(ILcdGraphListener<N,E> aGraphListener)
Registers the given
ILcdGraphListener with this graph. |
void |
addPartition(ILcdGraph<N,E> aPartition,
int aPartitionedGraphFireEventMode,
int aGraphFireEventMode)
Adds a partition to this graph.
|
void |
addPartitionedGraphListener(ILcdPartitionedGraphListener aPartitionedGraphListener)
Registers the given
ILcdPartitionedGraphListener with this graph. |
void |
boundaryEdgeChanged(E aBoundaryEdge,
int aPartitionedGraphFireEventMode,
int aGraphFireEventMode)
This method should be called when the given boundary edge has changed.
|
void |
boundaryEdgesChanged(Vector<E> aBoundaryEdges,
int aPartitionedGraphFireEventMode,
int aGraphFireEventMode)
This method should be called when the given boundary edges have changed.
|
boolean |
canAddBoundaryEdge(E aEdge,
N aStartNode,
N aEndNode)
Returns
true if the given boundary edge can be added to this partitioned
graph, false otherwise. |
boolean |
canAddPartition(ILcdGraph<N,E> aPartition)
Returns
true if the given partition can be added to this partitioned
graph, false otherwise. |
boolean |
canRemoveBoundaryEdge(E aEdge)
Returns
true if the given boundary edge can be removed from
this graph, false otherwise. |
boolean |
canRemoveBoundaryEdges(ILcdGraph<N,E> aPartition)
Returns
true if the boundary edge connected to the given
partition can be removed from this graph, false otherwise. |
boolean |
canRemovePartition(ILcdGraph<N,E> aPartition)
Returns
true if the given partition can be removed from this
partitioned graph, false otherwise. |
void |
clear(int aPartitionedGraphFireEventMode,
int aGraphFireEventMode)
Clears the graph; all partitions are removed from this graph and the
boundary graph is cleared.
|
void |
clearBoundaryGraph(int aPartitionedGraphFireEventMode,
int aGraphFireEventMode)
Clears the boundary graph of this partitioned graph, i.e. all its boundary
edges and boundary nodes are removed from its boundary graph.
|
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. |
boolean |
containsPartition(ILcdGraph<N,E> aPartition)
Returns true if the given graph is a partition of this graph, false otherwise.
|
void |
fireCollectedGraphChanges()
Fires all the collected graph changes, i.e., all graph events that have been
generated using the ILcdFireEventMode.FIRE_LATER mode, after the
previous call to
fireCollectedGraphChanges() . |
void |
fireCollectedPartitionedGraphChanges()
Fires all the collected partitioned graph changes, i.e., all partitioned
graph events that have been generated using the ILcdFireEventMode.FIRE_LATER
mode, after the previous call to
fireCollectedPartitionedGraphChanges() . |
Enumeration<E> |
getBoundaryEdges(ILcdGraph<N,E> aPartition)
Returns an enumeration containing all boundary edges of the given partition.
|
ILcdGraph<N,E> |
getBoundaryGraph()
Returns the boundary graph of this graph.
|
Enumeration<N> |
getBoundaryNodes(ILcdGraph<N,E> aPartition)
Returns an enumeration containing all boundary nodes of the given partition.
|
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 . |
ILcdGraph<N,E> |
getPartitionForEdge(E aEdge)
Returns the partition of this partitioned graph that contains the given edge,
or
null if the given edge is not part of a partition in this graph. |
ILcdGraph<N,E> |
getPartitionForNode(N aNode)
Returns the partition of this partitioned graph that contains the given node,
or
null if the given node is not part of a partition in this graph. |
Enumeration<ILcdGraph<N,E>> |
getPartitions()
Returns an
Enumeration containing all partitions of this graph. |
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. |
E |
removeBoundaryEdge(E aEdge,
int aPartitionedGraphFireEventMode,
int aGraphFireEventMode)
Removes the given boundary edge from the boundary graph of this partitioned
graph.
|
Enumeration<E> |
removeBoundaryEdges(ILcdGraph<N,E> aPartition,
int aPartitionedGraphFireEventMode,
int aGraphFireEventMode)
Removes all boundary edges that are connected to the given partition.
|
void |
removeGraphListener(ILcdGraphListener<N,E> aGraphListener)
Unregisters the given
ILcdGraphListener from this graph. |
void |
removePartition(ILcdGraph<N,E> aPartition,
int aPartitionedGraphFireEventMode,
int aGraphFireEventMode)
Removes the given partition from this graph.
|
void |
removePartitionedGraphListener(ILcdPartitionedGraphListener aPartitionedGraphListener)
Unregisters the given
ILcdPartitionedGraphListener from this graph. |
public TLcdLimitedEditablePartitionedGraph()
TLcdLimitedEditablePartitionedGraph
.public boolean canAddBoundaryEdge(E aEdge, N aStartNode, N aEndNode)
true
if the given boundary edge can be added to this partitioned
graph, false
otherwise. More specifically, a boundary edge can be added to this
graph if the following conditions are met:
null
containsBoundaryEdge
method to test whether the given
edge is already part of this graph or not, and the getPartitionForNode
method to determine in which partition both given nodes are contained.canAddBoundaryEdge
in interface ILcdLimitedEditablePartitionedGraph<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 boundary edge can be added to this graph,
false
otherwise.public void addBoundaryEdge(E aEdge, N aStartNode, N aEndNode, int aPartitionedGraphFireEventMode, int aGraphFireEventMode)
ILcdLimitedEditablePartitionedGraph
addBoundaryEdge
in interface ILcdLimitedEditablePartitionedGraph<N,E>
aEdge
- the edge that should be added.aStartNode
- the start node of the edge.aEndNode
- the end node of the edge.aPartitionedGraphFireEventMode
- the mode for sending out the
TLcdPartitionedGraphChangedEvent This can be
one of ILcdFireEventMode.FIRE_NOW,
ILcdFireEventMode.FIRE_LATER or
ILcdFireEventMode.NO_EVENT
.aGraphFireEventMode
- the mode for sending out the
TLcdGraphChangedEvent This can be
one of ILcdFireEventMode.FIRE_NOW,
ILcdFireEventMode.FIRE_LATER or
ILcdFireEventMode.NO_EVENT
.
canAddBoundaryEdge(aEdge,
aStartNode, aEndNode)
- Note:
this validation is potentially
expensive, and should be avoided
whenever possible.public boolean canRemoveBoundaryEdge(E aEdge)
ILcdLimitedEditablePartitionedGraph
true
if the given boundary edge can be removed from
this graph, false
otherwise. More specifically, a boundary
edge can be remove from this graph if the following conditions are met:
null
canRemoveBoundaryEdge
in interface ILcdLimitedEditablePartitionedGraph<N,E>
aEdge
- the boundary edge to be verified.true
if the boundary edge can be removed from this
graph, false
otherwise.public E removeBoundaryEdge(E aEdge, int aPartitionedGraphFireEventMode, int aGraphFireEventMode)
ILcdLimitedEditablePartitionedGraph
removeBoundaryEdge
in interface ILcdLimitedEditablePartitionedGraph<N,E>
aEdge
- the boundary edge that should be
removed.aPartitionedGraphFireEventMode
- the mode for sending out the
TLcdPartitionedGraphChangedEvent This can be
one of ILcdFireEventMode.FIRE_NOW,
ILcdFireEventMode.FIRE_LATER or
ILcdFireEventMode.NO_EVENT
.aGraphFireEventMode
- the mode for sending out the
TLcdGraphChangedEvent This can be
one of ILcdFireEventMode.FIRE_NOW,
ILcdFireEventMode.FIRE_LATER or
ILcdFireEventMode.NO_EVENT
.
canRemoveBoundaryEdge(aEdge)
- Note: this validation is
potentially expensive, and should be
avoided whenever possible.public boolean canRemoveBoundaryEdges(ILcdGraph<N,E> aPartition)
ILcdLimitedEditablePartitionedGraph
true
if the boundary edge connected to the given
partition can be removed from this graph, false
otherwise.
More specifically, the boundary edges connected to the given partition can
be removed from this graph if the following conditions are met: null
canRemoveBoundaryEdges
in interface ILcdLimitedEditablePartitionedGraph<N,E>
aPartition
- the partition to be verified.true
if the boundary edges connected to the given
partition can be removed from this graph, false
otherwise.public Enumeration<E> removeBoundaryEdges(ILcdGraph<N,E> aPartition, int aPartitionedGraphFireEventMode, int aGraphFireEventMode)
ILcdLimitedEditablePartitionedGraph
removeBoundaryEdges
in interface ILcdLimitedEditablePartitionedGraph<N,E>
aPartition
- the partition whose boundary edges
should be removed.aPartitionedGraphFireEventMode
- the mode for sending out the
TLcdPartitionedGraphChangedEvent This can be
one of ILcdFireEventMode.FIRE_NOW,
ILcdFireEventMode.FIRE_LATER or
ILcdFireEventMode.NO_EVENT
.aGraphFireEventMode
- the mode for sending out the
TLcdGraphChangedEvent This can be
one of ILcdFireEventMode.FIRE_NOW,
ILcdFireEventMode.FIRE_LATER or
ILcdFireEventMode.NO_EVENT
.
canRemoveBoundaryEdges(aPartition)
- Note: this validation is
potentially expensive, and should be
avoided whenever possible.public void clearBoundaryGraph(int aPartitionedGraphFireEventMode, int aGraphFireEventMode)
ILcdLimitedEditablePartitionedGraph
clearBoundaryGraph
in interface ILcdLimitedEditablePartitionedGraph<N,E>
aPartitionedGraphFireEventMode
- the mode for sending out the
TLcdPartitionedGraphChangedEvent.
This can be one of ILcdFireEventMode.FIRE_NOW,
ILcdFireEventMode.FIRE_LATER or
ILcdFireEventMode.NO_EVENT
.aGraphFireEventMode
- the mode for sending out the
TLcdGraphChangedEvent. This can be
one of ILcdFireEventMode.FIRE_NOW,
ILcdFireEventMode.FIRE_LATER or
ILcdFireEventMode.NO_EVENT
.public boolean canAddPartition(ILcdGraph<N,E> aPartition)
true
if the given partition can be added to this partitioned
graph, false
otherwise. More specifically, a partition can be added to this
graph if the following conditions are met:
null
containsPartition
method to determine
whether the given partition is already part of this graph or not. The
implementation iterates over all nodes and edges, using respectively the
containsPartition
and containsBoundaryEdge
methods to verify
that no node or edge is already part of this graph.canAddPartition
in interface ILcdLimitedEditablePartitionedGraph<N,E>
aPartition
- the partition to be verified.true
if the partition can be added to this graph,
false
otherwise.public void addPartition(ILcdGraph<N,E> aPartition, int aPartitionedGraphFireEventMode, int aGraphFireEventMode)
ILcdLimitedEditablePartitionedGraph
addPartition
in interface ILcdLimitedEditablePartitionedGraph<N,E>
aPartition
- the partition to be added to this
graph.aPartitionedGraphFireEventMode
- the mode for sending out the
TLcdPartitionedGraphChangedEvent.
This can be one of ILcdFireEventMode.FIRE_NOW,
ILcdFireEventMode.FIRE_LATER or
ILcdFireEventMode.NO_EVENT
.aGraphFireEventMode
- the mode for sending out the
TLcdGraphChangedEvent. This can be
one of ILcdFireEventMode.FIRE_NOW,
ILcdFireEventMode.FIRE_LATER or
ILcdFireEventMode.NO_EVENT
.
canAddPartition(aPartition)
- Note: this validation is
potentially expensive, and should be
avoided whenever possible.public boolean canRemovePartition(ILcdGraph<N,E> aPartition)
true
if the given partition can be removed from this
partitioned graph, false
otherwise. More specifically, a
partition can be removed from this graph if the following conditions are met:
null
containsPartition
method to determine
whether the given partition is part of this graph.canRemovePartition
in interface ILcdLimitedEditablePartitionedGraph<N,E>
aPartition
- the partition to be verified.true
if the partition can be removed from this graph,
false
otherwise.public void removePartition(ILcdGraph<N,E> aPartition, int aPartitionedGraphFireEventMode, int aGraphFireEventMode)
ILcdLimitedEditablePartitionedGraph
removePartition
in interface ILcdLimitedEditablePartitionedGraph<N,E>
aPartition
- the partition to be removed from this
graph.aPartitionedGraphFireEventMode
- the mode for sending out the
TLcdPartitionedGraphChangedEvent.
This can be one of ILcdFireEventMode.FIRE_NOW,
ILcdFireEventMode.FIRE_LATER or
ILcdFireEventMode.NO_EVENT
.aGraphFireEventMode
- the mode for sending out the
TLcdGraphChangedEvent. This can be
one of ILcdFireEventMode.FIRE_NOW,
ILcdFireEventMode.FIRE_LATER or
ILcdFireEventMode.NO_EVENT
.
canRemovePartition(aPartition)
- Note: this validation is
potentially expensive, and should be
avoided whenever possible.public void clear(int aPartitionedGraphFireEventMode, int aGraphFireEventMode)
ILcdLimitedEditablePartitionedGraph
clear
in interface ILcdLimitedEditablePartitionedGraph<N,E>
aPartitionedGraphFireEventMode
- the mode for sending out the
TLcdPartitionedGraphChangedEvent.
This can be one of ILcdFireEventMode.FIRE_NOW,
ILcdFireEventMode.FIRE_LATER or
ILcdFireEventMode.NO_EVENT
.aGraphFireEventMode
- the mode for sending out the
TLcdGraphChangedEvent. This can be
one of ILcdFireEventMode.FIRE_NOW,
ILcdFireEventMode.FIRE_LATER or
ILcdFireEventMode.NO_EVENT
.public void fireCollectedPartitionedGraphChanges()
ILcdLimitedEditablePartitionedGraph
fireCollectedPartitionedGraphChanges()
.
Note that afireCollectedPartitionedGraphChanges()
call is made whenever a
partitioned graph event is generated in the ILcdFireEventMode.FIRE_NOW
,
to guarantee the correct order of the events.fireCollectedPartitionedGraphChanges
in interface ILcdLimitedEditablePartitionedGraph<N,E>
public void boundaryEdgeChanged(E aBoundaryEdge, int aPartitionedGraphFireEventMode, int aGraphFireEventMode)
ILcdLimitedEditablePartitionedGraph
boundaryEdgeChanged
in interface ILcdLimitedEditablePartitionedGraph<N,E>
aBoundaryEdge
- the boundary edge that has changed.aPartitionedGraphFireEventMode
- the mode for sending out the
TLcdPartitionedGraphChangedEvent This can be
one of ILcdFireEventMode.FIRE_NOW,
ILcdFireEventMode.FIRE_LATER or
ILcdFireEventMode.NO_EVENT
.aGraphFireEventMode
- the mode for sending out the
TLcdGraphChangedEvent This can be
one of ILcdFireEventMode.FIRE_NOW,
ILcdFireEventMode.FIRE_LATER or
ILcdFireEventMode.NO_EVENT
.
getBoundaryGraph().containsBoundaryEdge(aBoundaryEdge)
- Note: this validation is
potentially expensive, and should be
avoided whenever possible.public void boundaryEdgesChanged(Vector<E> aBoundaryEdges, int aPartitionedGraphFireEventMode, int aGraphFireEventMode)
ILcdLimitedEditablePartitionedGraph
boundaryEdgesChanged
in interface ILcdLimitedEditablePartitionedGraph<N,E>
aBoundaryEdges
- a vector containing the boundary
edges that have changed.aPartitionedGraphFireEventMode
- the mode for sending out the
TLcdPartitionedGraphChangedEvent This can be
one of ILcdFireEventMode.FIRE_NOW,
ILcdFireEventMode.FIRE_LATER or
ILcdFireEventMode.NO_EVENT
.aGraphFireEventMode
- the mode for sending out the
TLcdGraphChangedEvent This can be
one of ILcdFireEventMode.FIRE_NOW,
ILcdFireEventMode.FIRE_LATER or
ILcdFireEventMode.NO_EVENT
.
boundaryEdge
in the given vector should hold that:
getBoundaryGraph().containsBoundaryEdge(boundaryEdge)
- Note: this validation is
potentially expensive, and should be
avoided whenever possible.public Enumeration<ILcdGraph<N,E>> getPartitions()
ILcdPartitionedGraph
Enumeration
containing all partitions of this graph.getPartitions
in interface ILcdPartitionedGraph<N,E>
Enumeration
containing all the partitions of this graph.public boolean containsPartition(ILcdGraph<N,E> aPartition)
ILcdPartitionedGraph
containsPartition
in interface ILcdPartitionedGraph<N,E>
aPartition
- the partition to be checked for.public ILcdGraph<N,E> getPartitionForNode(N aNode)
ILcdPartitionedGraph
null
if the given node is not part of a partition in this graph.getPartitionForNode
in interface ILcdPartitionedGraph<N,E>
aNode
- the node whose graph should be returned.public ILcdGraph<N,E> getPartitionForEdge(E aEdge)
ILcdPartitionedGraph
null
if the given edge is not part of a partition in this graph.
The partitions connected by a boundary edge should be retrieved by calling the
getPartitionForNode
method with as argument one of the two nodes
connected by this edge.getPartitionForEdge
in interface ILcdPartitionedGraph<N,E>
aEdge
- the edge whose graph should be returned.public Enumeration<N> getBoundaryNodes(ILcdGraph<N,E> aPartition)
ILcdPartitionedGraph
getBoundaryNodes
in interface ILcdPartitionedGraph<N,E>
aPartition
- the partition from which the boundary should be part.public Enumeration<E> getBoundaryEdges(ILcdGraph<N,E> aPartition)
ILcdPartitionedGraph
getBoundaryEdges
in interface ILcdPartitionedGraph<N,E>
aPartition
- the partition to which the boundary edges should be connected.public ILcdGraph<N,E> getBoundaryGraph()
ILcdPartitionedGraph
getBoundaryGraph
in interface ILcdPartitionedGraph<N,E>
public void addPartitionedGraphListener(ILcdPartitionedGraphListener aPartitionedGraphListener)
ILcdPartitionedGraph
ILcdPartitionedGraphListener
with this graph. All events
generated by this graph afterwards will be sent to the given listener, until
it is removed from this graph.addPartitionedGraphListener
in interface ILcdPartitionedGraph<N,E>
aPartitionedGraphListener
- the graph listener to be registered with this graph.public void removePartitionedGraphListener(ILcdPartitionedGraphListener aPartitionedGraphListener)
ILcdPartitionedGraph
ILcdPartitionedGraphListener
from this graph. After it
has been unregistered, no events generated by this graph will be sent to the
given listener anymore.removePartitionedGraphListener
in interface ILcdPartitionedGraph<N,E>
aPartitionedGraphListener
- the graph listener to be unregistered from 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)
getPartitionForNode
method to determine
the partition in which the given node is contained.getEdges
in interface ILcdGraph<N,E>
aNode
- the node whose connected edges should be returned.IllegalArgumentException
- aNode
is not part of this graph.NullPointerException
- if the node is null
.public N getStartNode(E aEdge)
getPartitionForEdge
method to determine
the partition in which the given edge is contained.getStartNode
in interface ILcdGraph<N,E>
aEdge
- the edge whose start node should be returned.IllegalArgumentException
- aEdge
is not part of this graph.NullPointerException
- if the edge is null
.public N getEndNode(E aEdge)
getPartitionForEdge
method to determine
the partition in which the given edge is contained.getEndNode
in interface ILcdGraph<N,E>
aEdge
- the edge whose end node should be returned.IllegalArgumentException
- aEdge
is not part of this graph.NullPointerException
- if the edge is null
.public N getOppositeNode(E aEdge, N aNode)
aNode
is one of the two nodes connected by the given edge in this graph, returns the other node,
otherwise throws IllegalArgumentException
.
This implementation uses the getPartitionForEdge
method to determine
the partition in which the given edge is contained.getOppositeNode
in interface ILcdGraph<N,E>
aNode
- one of the two Object
's connected by the given edge.aEdge
- the edge whose opposite node should be returned.aNode
is one of the two nodes connected by this edge, returns the other
node connected by this edge.IllegalArgumentException
- aNode
is not connected by this edge or
aEdge
is not part of this graph.NullPointerException
- if one of the arguments is null
.public boolean isConnected(E aEdge, N aNode)
aNode
is one the nodes to which this edge is connected.
This implementation uses the getPartitionForEdge
method to determine
the partition in which the given edge is contained.isConnected
in interface ILcdGraph<N,E>
aNode
- the node which connectivity should be checked.aEdge
- the edge whose connectivity should be checked.aNode
is one the nodes to which this edge is connected.IllegalArgumentException
- aEdge
is not part of this graph.NullPointerException
- if one of the arguments is null
.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 void fireCollectedGraphChanges()
ILcdLimitedEditablePartitionedGraph
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 ILcdLimitedEditablePartitionedGraph<N,E>