public abstract class AbstractGraph extends AbstractElement implements Graph, Replayable
This class provides a basic implementation of
Graph interface, to minimize the effort
required to implement this interface. It provides event management
implementing all the methods of Pipe. It also
manages strict checking and auto-creation policies, as well as other services
as displaying, reading and writing.
Subclasses have to maintain data structures allowing to efficiently access
graph elements by their id or index and iterating on them. They also have to
maintain coherent indices of the graph elements. When AbstractGraph decides
to add or remove elements, it calls one of the "callbacks"
addNodeCallback(AbstractNode),
addEdgeCallback(AbstractEdge),
removeNodeCallback(AbstractNode),
removeEdgeCallback(AbstractEdge), clearCallback(). The role
of these callbacks is to update the data structures and to re-index elements
if necessary.
AbstractElement.AttributeChangeEventReplayable.Controller| Constructor and Description |
|---|
AbstractGraph(java.lang.String id)
The same as
AbstractGraph(id, true, false) |
AbstractGraph(java.lang.String id,
boolean strictChecking,
boolean autoCreate)
Creates a new graph.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addAttributeSink(AttributeSink sink)
Add a sink for attribute events only.
|
Edge |
addEdge(java.lang.String id,
Node from,
Node to,
boolean directed)
Like
Graph.addEdge(String, String, String, boolean) but the node
references are given instead of node identifiers. |
void |
addElementSink(ElementSink sink)
Add a sink for elements events only.
|
Node |
addNode(java.lang.String id)
Add a node in the graph.
|
void |
addSink(Sink sink)
Add a sink for all graph events (attributes and graph elements) coming from
this source.
|
java.lang.Iterable<AttributeSink> |
attributeSinks()
Returns an "iterable" of
AttributeSink objects registered to this
graph. |
void |
clear()
Empty the graph completely by removing any references to nodes or edges.
|
void |
clearAttributeSinks()
Remove all listener attribute sinks.
|
void |
clearElementSinks()
Remove all listener element sinks.
|
void |
clearSinks()
Remove all listener sinks.
|
Viewer |
display()
Utility method that creates a new graph viewer, and register the graph in it.
|
Viewer |
display(boolean autoLayout)
Utility method that creates a new graph viewer, and register the graph in it.
|
void |
edgeAdded(java.lang.String sourceId,
long timeId,
java.lang.String edgeId,
java.lang.String fromNodeId,
java.lang.String toNodeId,
boolean directed)
An edge was inserted in graph.
|
void |
edgeAttributeAdded(java.lang.String sourceId,
long timeId,
java.lang.String edgeId,
java.lang.String attribute,
java.lang.Object value)
A edge attribute was added.
|
void |
edgeAttributeChanged(java.lang.String sourceId,
long timeId,
java.lang.String edgeId,
java.lang.String attribute,
java.lang.Object oldValue,
java.lang.Object newValue)
A edge attribute was changed.
|
void |
edgeAttributeRemoved(java.lang.String sourceId,
long timeId,
java.lang.String edgeId,
java.lang.String attribute)
A edge attribute was removed.
|
EdgeFactory<? extends Edge> |
edgeFactory()
The factory used to create edge instances.
|
void |
edgeRemoved(java.lang.String sourceId,
long timeId,
java.lang.String edgeId)
An edge of graph was removed.The nodes the edge connects may already have
been removed from the graph.
|
java.lang.Iterable<ElementSink> |
elementSinks()
Returns an "iterable" of
ElementSink objects registered to this
graph. |
Replayable.Controller |
getReplayController()
Get a controller to replay the graph.
|
double |
getStep()
The current step.
|
void |
graphAttributeAdded(java.lang.String sourceId,
long timeId,
java.lang.String attribute,
java.lang.Object value)
A graph attribute was added.
|
void |
graphAttributeChanged(java.lang.String sourceId,
long timeId,
java.lang.String attribute,
java.lang.Object oldValue,
java.lang.Object newValue)
A graph attribute was changed.
|
void |
graphAttributeRemoved(java.lang.String sourceId,
long timeId,
java.lang.String attribute)
A graph attribute was removed.
|
void |
graphCleared(java.lang.String sourceId,
long timeId)
The whole graph was cleared.
|
boolean |
isAutoCreationEnabled()
Is the automatic creation of missing elements enabled?.
|
boolean |
isStrict()
Is strict checking enabled?
|
java.util.Iterator<Node> |
iterator()
This implementation returns an iterator over nodes.
|
void |
nodeAdded(java.lang.String sourceId,
long timeId,
java.lang.String nodeId)
A node was inserted in the given graph.
|
void |
nodeAttributeAdded(java.lang.String sourceId,
long timeId,
java.lang.String nodeId,
java.lang.String attribute,
java.lang.Object value)
A node attribute was added.
|
void |
nodeAttributeChanged(java.lang.String sourceId,
long timeId,
java.lang.String nodeId,
java.lang.String attribute,
java.lang.Object oldValue,
java.lang.Object newValue)
A node attribute was changed.
|
void |
nodeAttributeRemoved(java.lang.String sourceId,
long timeId,
java.lang.String nodeId,
java.lang.String attribute)
A node attribute was removed.
|
NodeFactory<? extends Node> |
nodeFactory()
The factory used to create node instances.
|
void |
nodeRemoved(java.lang.String sourceId,
long timeId,
java.lang.String nodeId)
A node was removed from the graph.
|
void |
removeAttributeSink(AttributeSink sink)
Remove an attribute sink.
|
Edge |
removeEdge(Edge edge)
Removes an edge.
|
Edge |
removeEdge(Node node1,
Node node2)
Removes an edge between two nodes.
|
void |
removeElementSink(ElementSink sink)
Remove an element sink.
|
Node |
removeNode(Node node)
Removes a node.
|
void |
removeSink(Sink sink)
Remove a sink.
|
void |
setAutoCreate(boolean on)
Enable or disable the automatic creation of missing elements.
|
void |
setEdgeFactory(EdgeFactory<? extends Edge> ef)
Set the edge factory used to create edges.
|
void |
setNodeFactory(NodeFactory<? extends Node> nf)
Set the node factory used to create nodes.
|
void |
setStrict(boolean on)
Enable or disable strict checking.
|
void |
stepBegins(double time)
Since dynamic graphs are based on discrete event modifications, the notion of
step is defined to simulate elapsed time between events.
|
void |
stepBegins(java.lang.String sourceId,
long timeId,
double step)
Since dynamic graphs are based on discrete event modifications, the notion of
step is defined to simulate elapsed time between events.
|
attributeKeys, clearAttributes, getAttribute, getAttribute, getAttributeCount, getFirstAttributeOf, getFirstAttributeOf, getId, getIndex, hasAttribute, hasAttribute, removeAttribute, setAttribute, toStringequals, getClass, hashCode, notify, notifyAll, wait, wait, waitaddEdge, addEdge, addEdge, addEdge, addEdge, getEdge, getEdge, getNode, getNode, read, read, removeEdge, removeEdge, removeEdge, removeEdge, removeNode, removeNode, write, writeattributeKeys, clearAttributes, getArray, getAttribute, getAttribute, getAttributeCount, getFirstAttributeOf, getFirstAttributeOf, getId, getIndex, getLabel, getMap, getNumber, getVector, hasArray, hasAttribute, hasAttribute, hasLabel, hasMap, hasNumber, hasVector, removeAttribute, setAttribute, setAttributesedges, getEdgeCount, getNodeCount, nodesreplay, tryReplaypublic AbstractGraph(java.lang.String id)
AbstractGraph(id, true, false)id - Identifier of the graphAbstractGraph(String, boolean, boolean)public AbstractGraph(java.lang.String id,
boolean strictChecking,
boolean autoCreate)
id - strictChecking - autoCreate - public java.util.Iterator<Node> iterator()
iterator in interface java.lang.Iterable<Node>Iterable.iterator()public NodeFactory<? extends Node> nodeFactory()
GraphnodeFactory in interface GraphGraph.setNodeFactory(NodeFactory),
Graph.edgeFactory()public EdgeFactory<? extends Edge> edgeFactory()
GraphedgeFactory in interface GraphGraph.setEdgeFactory(EdgeFactory),
Graph.nodeFactory()public void setNodeFactory(NodeFactory<? extends Node> nf)
GraphsetNodeFactory in interface Graphnf - the new NodeFactorypublic void setEdgeFactory(EdgeFactory<? extends Edge> ef)
GraphsetEdgeFactory in interface Graphef - the new EdgeFactorypublic boolean isStrict()
Graphpublic void setStrict(boolean on)
GraphsetStrict in interface Graphon - True or false.Graph.isStrict()public boolean isAutoCreationEnabled()
GraphisAutoCreationEnabled in interface Graphpublic double getStep()
Graphpublic void setAutoCreate(boolean on)
GraphsetAutoCreate in interface Graphon - True or false.Graph.isAutoCreationEnabled()public void stepBegins(double time)
GraphSince dynamic graphs are based on discrete event modifications, the notion of step is defined to simulate elapsed time between events. So a step is a event that occurs in the graph, it does not modify it but it gives a kind of timestamp that allows the tracking of the progress of the graph over the time.
This kind of event is useful for dynamic algorithms that listen to the dynamic graph and need to measure the time in the graph's evolution.
stepBegins in interface Graphtime - A numerical value that may give a timestamp to track the evolution
of the graph over the time.public Viewer display()
Graphdisplay in interface GraphViewer,
Graph.display(boolean )public Viewer display(boolean autoLayout)
Graphdisplay in interface GraphautoLayout - If true a layout algorithm is launched in its own thread to
compute best node positions.Viewer,
Graph.display()public void clear()
Graphclear in interface GraphSource.clearSinks()public Node addNode(java.lang.String id)
Graph
This acts as a factory, creating the node instance automatically (and
eventually using the node factory provided). An event is generated toward the
listeners. If strict checking is enabled, and a node already exists with this
identifier, an IdAlreadyInUseException is
raised. Else the error is silently ignored and the already existing node is
returned.
This method is implicitly generic and returns something which extends Node. The return type is the one of the left part of the assignment. For example, in the following call :
ExtendedNode n = graph.addNode("...");
the method will return an ExtendedNode. If no left part exists, method will just return a Node.
public Edge addEdge(java.lang.String id, Node from, Node to, boolean directed)
GraphGraph.addEdge(String, String, String, boolean) but the node
references are given instead of node identifiers.addEdge in interface Graphid - Unique and arbitrary string identifying the edge.from - The first nodeto - The second nodedirected - Is the edge directed?nullGraph.addEdge(String, String, String)public Node removeNode(Node node)
GraphAn event is generated toward the listeners. Note that removing a node may remove all edges it is connected to. In this case corresponding events will also be generated toward the listeners.
This method is implicitly generic and return something which extends Node. The return type is the one of the left part of the assignment. For example, in the following call :
ExtendedNode n = graph.removeNode(...);
the method will return an ExtendedNode. If no left part exists, method will just return a Node.
removeNode in interface Graphnode - The node to be removedpublic Edge removeEdge(Edge edge)
GraphThis method is implicitly generic and returns something which extends Edge. The return type is the one of the left part of the assignment. For example, in the following call :
ExtendedEdge e = graph.removeEdge(...);
the method will return an ExtendedEdge. If no left part exists, method will just return an Edge.
removeEdge in interface Graphedge - The edge to be removedpublic Edge removeEdge(Node node1, Node node2)
GraphGraph.removeEdge(String, String)
but node references are given instead of node identifiers.removeEdge in interface Graphnode1 - the first nodenode2 - the second nodenull if no edge is removedGraph.removeEdge(String, String)public java.lang.Iterable<AttributeSink> attributeSinks()
GraphAttributeSink objects registered to this
graph.attributeSinks in interface GraphAttributeSink under the form of an iterable
object.public java.lang.Iterable<ElementSink> elementSinks()
GraphElementSink objects registered to this
graph.elementSinks in interface GraphElementSink under the form of an iterable object.public void addAttributeSink(AttributeSink sink)
SourceaddAttributeSink in interface Sourcesink - The sink to register.public void addElementSink(ElementSink sink)
SourceaddElementSink in interface Sourcesink - The sink to register.public void addSink(Sink sink)
Sourcepublic void clearAttributeSinks()
SourceclearAttributeSinks in interface Sourcepublic void clearElementSinks()
SourceclearElementSinks in interface Sourcepublic void clearSinks()
SourceclearSinks in interface Sourcepublic void removeAttributeSink(AttributeSink sink)
SourceremoveAttributeSink in interface Sourcesink - The sink to remove, if it does not exist, this is ignored
silently.public void removeElementSink(ElementSink sink)
SourceremoveElementSink in interface Sourcesink - The sink to remove, if it does not exist, this is ignored
silently.public void removeSink(Sink sink)
SourceremoveSink in interface Sourcesink - The sink to remove, if it does not exist, this is ignored
silently.public void edgeAttributeAdded(java.lang.String sourceId,
long timeId,
java.lang.String edgeId,
java.lang.String attribute,
java.lang.Object value)
AttributeSinkedgeAttributeAdded in interface AttributeSinksourceId - Identifier of the graph where the change occurred.edgeId - Identifier of the edge whose attribute changed.attribute - The attribute name.value - The attribute new value.public void edgeAttributeChanged(java.lang.String sourceId,
long timeId,
java.lang.String edgeId,
java.lang.String attribute,
java.lang.Object oldValue,
java.lang.Object newValue)
AttributeSinkedgeAttributeChanged in interface AttributeSinksourceId - Identifier of the graph where the change occurred.edgeId - Identifier of the edge whose attribute changed.attribute - The attribute name.oldValue - The attribute old value.newValue - The attribute new value.public void edgeAttributeRemoved(java.lang.String sourceId,
long timeId,
java.lang.String edgeId,
java.lang.String attribute)
AttributeSinkedgeAttributeRemoved in interface AttributeSinksourceId - Identifier of the graph where the attribute was removed.edgeId - Identifier of the edge whose attribute was removed.attribute - The removed attribute name.public void graphAttributeAdded(java.lang.String sourceId,
long timeId,
java.lang.String attribute,
java.lang.Object value)
AttributeSinkgraphAttributeAdded in interface AttributeSinksourceId - Identifier of the graph where the attribute changed.attribute - The attribute name.value - The attribute new value.public void graphAttributeChanged(java.lang.String sourceId,
long timeId,
java.lang.String attribute,
java.lang.Object oldValue,
java.lang.Object newValue)
AttributeSinkgraphAttributeChanged in interface AttributeSinksourceId - Identifier of the graph where the attribute changed.attribute - The attribute name.oldValue - The attribute old value.newValue - The attribute new value.public void graphAttributeRemoved(java.lang.String sourceId,
long timeId,
java.lang.String attribute)
AttributeSinkgraphAttributeRemoved in interface AttributeSinksourceId - Identifier of the graph where the attribute was removed.attribute - The removed attribute name.public void nodeAttributeAdded(java.lang.String sourceId,
long timeId,
java.lang.String nodeId,
java.lang.String attribute,
java.lang.Object value)
AttributeSinknodeAttributeAdded in interface AttributeSinksourceId - Identifier of the graph where the change occurred.nodeId - Identifier of the node whose attribute changed.attribute - The attribute name.value - The attribute new value.public void nodeAttributeChanged(java.lang.String sourceId,
long timeId,
java.lang.String nodeId,
java.lang.String attribute,
java.lang.Object oldValue,
java.lang.Object newValue)
AttributeSinknodeAttributeChanged in interface AttributeSinksourceId - Identifier of the graph where the change occurred.nodeId - Identifier of the node whose attribute changed.attribute - The attribute name.oldValue - The attribute old value.newValue - The attribute new value.public void nodeAttributeRemoved(java.lang.String sourceId,
long timeId,
java.lang.String nodeId,
java.lang.String attribute)
AttributeSinknodeAttributeRemoved in interface AttributeSinksourceId - Identifier of the graph where the attribute was removed.nodeId - Identifier of the node whose attribute was removed.attribute - The removed attribute name.public void edgeAdded(java.lang.String sourceId,
long timeId,
java.lang.String edgeId,
java.lang.String fromNodeId,
java.lang.String toNodeId,
boolean directed)
ElementSinkedgeAdded in interface ElementSinksourceId - Identifier of the graph where the edge was added.edgeId - Identifier of the added edge.fromNodeId - Identifier of the first node of the edge.toNodeId - Identifier of the second node of the edge.directed - If true, the edge is directed.public void edgeRemoved(java.lang.String sourceId,
long timeId,
java.lang.String edgeId)
ElementSinkedgeRemoved in interface ElementSinksourceId - The graph where the edge will be removed.edgeId - The edge that will be removed.public void graphCleared(java.lang.String sourceId,
long timeId)
ElementSinkgraphCleared in interface ElementSinksourceId - The graph cleared.public void nodeAdded(java.lang.String sourceId,
long timeId,
java.lang.String nodeId)
ElementSinknodeAdded in interface ElementSinksourceId - Identifier of the graph where the node was added.nodeId - Identifier of the added node.public void nodeRemoved(java.lang.String sourceId,
long timeId,
java.lang.String nodeId)
ElementSinknodeRemoved in interface ElementSinksourceId - Identifier of the graph where the node will be removed.nodeId - Identifier of the removed node.public void stepBegins(java.lang.String sourceId,
long timeId,
double step)
ElementSinkSince dynamic graphs are based on discrete event modifications, the notion of step is defined to simulate elapsed time between events. So a step is a event that occurs in the graph, it does not modify it but it gives a kind of timestamp that allow the tracking of the progress of the graph over the time.
This kind of event is useful for dynamic algorithms that listen to the dynamic graph and need to measure the time in the graph's evolution.
stepBegins in interface ElementSinksourceId - Identifier of the graph where the step starts.timeId - A numerical value that may give a timestamp to track the evolution
of the graph over the time.public Replayable.Controller getReplayController()
ReplayablegetReplayController in interface Replayable