|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--y.base.Graph
This class implements a directed graph structure.
Basically a directed graph consists of a set of objects called nodes
(represented by instances of class Node
) and
a set of node pairs which are called edges (represented by instances of
class Edge
).
This class fires notification events that signal structural
changes of the graph. Classes that implement the GraphListener
interface can be added to this class in order to receive such
events.
Field Summary | |
static int |
AFTER
Object insertion specifier. |
static int |
BEFORE
Object insertion specifier. |
protected Vector |
listeners
A vector of graph listeners. listeners references null |
Constructor Summary | |
Graph()
Instantiates an empty Graph. |
|
Graph(Graph argGraph)
Instantiates a new Graph object as a copy of argGraph. |
|
Graph(Graph graph,
YCursor subNodes)
Instantiates a new Graph object as a partial copy of the argument graph. |
Method Summary | |
void |
addDataProvider(Object providerKey,
DataProvider data)
Registers the given data provider under the given lookup key. |
void |
addGraphListener(GraphListener listener)
Adds the given graph listener to this graph. |
void |
changeEdge(Edge e,
Edge e1,
Edge e2,
int d1,
int d2)
This method redefines the endpoints of e .
|
void |
changeEdge(Edge e,
Node newSource,
Edge sourceReference,
int sourceD,
Node newTarget,
Edge targetReference,
int targetD)
This method redefines the endpoints of e .
|
void |
changeEdge(Edge e,
Node newSource,
Node newTarget)
This method redefines the endpoints of e .
|
void |
clear()
Removes all nodes and edges from this graph. |
boolean |
contains(Edge e)
Whether or not this graph contains the given edge. |
boolean |
contains(Node v)
Whether or not this graph contains the given node. |
boolean |
containsEdge(Node source,
Node target)
Returns whether or not this grpah contains an edge from node source to node target . |
Graph |
createCopy()
Creates a copy of this graph. |
Edge |
createEdge(Node v,
Edge e1,
Node w,
Edge e2,
int d1,
int d2)
Creates a new edge in this graph The new edge e has source node v and target node w. |
Edge |
createEdge(Node v,
Node w)
Creates a new edge in this graph. |
EdgeMap |
createEdgeMap()
Returns a newly created edge map that is valid for the edges in this graph. |
Graph |
createGraph()
Creates an empty.base object of the same type as this graph. |
Node |
createNode()
Creates a new node in this graph. |
NodeMap |
createNodeMap()
Returns a newly created node map that is valid for the nodes in this graph. |
void |
disposeEdgeMap(EdgeMap map)
Informs the graph that the given edge map is not needed any longer. |
void |
disposeNodeMap(NodeMap map)
Informs the graph that the given node map is not needed any longer. |
int |
E()
Same as Graph.edgeCount() |
int |
edgeCount()
Returns the number of edges in this graph. |
Iterator |
edgeObjects()
Returns an iterator that provides access to all edges residing in this graph. |
EdgeCursor |
edges()
Provides access to the edges of the graph. |
protected void |
fireGraphEvent(GraphEvent e)
Propagates the given graph event to all registered graph listeners. |
void |
firePostEvent()
Propagates a post event to all registered graph listeners. |
void |
firePostEvent(Object id)
Like Graph.firePostEvent() . |
void |
firePreEvent()
Propagates a pre event to all registered graph listeners. |
void |
firePreEvent(Object id)
Like Graph.firePreEvent() . |
Edge |
firstEdge()
Returns the first edge in this graph. |
Node |
firstNode()
Returns the first node in this graph. |
protected static Edge |
firstOutEdge(Node v)
Low level iteration support for adj edges. |
DataProvider |
getDataProvider(Object providerKey)
Returns a data provider that is registered with the graph under the given key. |
Object[] |
getDataProviderKeys()
Returns an array of all data provider keys that are registered with this graph. |
Edge[] |
getEdgeArray()
Returns an array containing all edges of this graph. |
Iterator |
getGraphListeners()
Returns an iterator that grants access to all registered GraphListeners. |
Node[] |
getNodeArray()
Returns an array containing all nodes of this graph. |
EdgeMap[] |
getRegisteredEdgeMaps()
Returns all undisposed edge maps that have been created by this graph. |
NodeMap[] |
getRegisteredNodeMaps()
Returns all undisposed node maps that have been created by this graph. |
Object |
getSource(Object edge)
Returns the source node associated with the given edge. |
Object |
getTarget(Object edge)
Returns the target node associated with the given edge. |
void |
hide(Edge e)
Hides the given edge from this graph. |
void |
hide(Node v)
Hides the given node from this graph. |
boolean |
isEmpty()
Returns true if this graph contains no nodes. |
Edge |
lastEdge()
Returns the first edge in this graph. |
Node |
lastNode()
Returns the last node in this graph. |
EdgeList |
moveSubGraph(NodeList subNodes,
Graph targetGraph)
Moves the subgraph induced by subNodes to target. |
void |
moveToFirst(Edge e)
Moves the given edge to the first position within the sequence of edges in this graph. |
void |
moveToFirst(Node v)
Moves the given node to the first position within the sequence of nodes in this graph. |
void |
moveToLast(Edge e)
Moves the given edge to the last position within the sequence of edges in this graph. |
void |
moveToLast(Node v)
Moves the given node to the last position within the sequence of nodes in this graph. |
int |
N()
Same as Graph.nodeCount() . |
int |
nodeCount()
Returns the number of nodes in this graph. |
Iterator |
nodeObjects()
Returns an iterator that provides access to all nodes residing in this graph. |
NodeCursor |
nodes()
Provides access to the nodes of the graph. |
void |
printNodeSlotSize()
For internal debugging purposes only. |
void |
reInsertEdge(Edge e)
Reinsert an Edge in this graph that was formerly removed. |
void |
reInsertNode(Node v)
Reinsert a Node in this graph that was formerly removed. |
void |
removeDataProvider(Object providerKey)
Removes a data provider that is registered under the given key. |
void |
removeEdge(Edge e)
Remove Edge e in this graph. |
void |
removeGraphListener(GraphListener listener)
Removes the given graph listener from this graph. |
void |
removeNode(Node v)
Remove Node v in this graph. |
void |
reverseEdge(Edge e)
Reverses the given Edge. |
void |
sortEdges(Comparator inComp,
Comparator outComp)
Sorts the out- and ingoing edges at each node of the graph. |
String |
toString()
Returns a string representation of this graph. |
void |
unhide(Edge e)
Unhides the given edge in this graph. |
void |
unhide(Node v)
Unhides the given node in this graph. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected Vector listeners
null iff
no listeners are registered.
public static final int BEFORE
public static final int AFTER
Constructor Detail |
public Graph()
public Graph(Graph argGraph)
argGraph
- Graph to be copiedpublic Graph(Graph graph, YCursor subNodes)
Method Detail |
public Graph createCopy()
public Node createNode()
public Edge createEdge(Node v, Node w)
v
- the source node of the edgew
- the target node of the edge
public Edge createEdge(Node v, Edge e1, Node w, Edge e2, int d1, int d2)
d1 == AFTER (d1 == BEFORE)
and an iteration over the edges at w return e after (before)
e2 if d2 == AFTER (d2 == BEFORE)
.
Precondition: Edge e1 must have source node v and edge e2 must have target node w
v
- the source node of the edgee1
- an edge with source node vw
- the target node of the edgee2
- an edge with target node wd1
- one of the object insertion specifiers BEFORE or AFTERd2
- one of the object insertion specifiers BEFORE or AFTERpublic void removeNode(Node v)
v
- node to be removed in this graphpublic void removeEdge(Edge e)
e
- edge to be removedpublic void reInsertNode(Node v)
v
- a node to be reinsertedpublic void reInsertEdge(Edge e)
e
- an edge to be reinsertedpublic void changeEdge(Edge e, Edge e1, Edge e2, int d1, int d2)
e
.
Edge e
v := e1.source()
and target node w := e2.target(). Edge e
is inserted in such a way that an iteration over the edges at
v
returns e
after (before)
e1
if d1 == AFTER (d1 == BEFORE)
and an iteration over the edges at w
return
e
after (before)
e2
if d2 == AFTER (d2 == BEFORE)
.
Precondition: Edges e, e1, e2
must be contained in this graph.
- Parameters:
e
- the edge to be changede1
- reference edge for insertion at a new source nodee2
- reference edge for insertion at a new target noded1
- one of the object insertion specifiers BEFORE or AFTERd2
- one of the object insertion specifiers BEFORE or AFTER
public void changeEdge(Edge e, Node newSource, Edge sourceReference, int sourceD, Node newTarget, Edge targetReference, int targetD)
e
.
Edge e
v := sourceReference.source()
or v := newSource
if sourceReference == null
and target node w := targetReference.target().
or w := newTarget
if targetReference == null
Edge e
is inserted in such a way that an iteration over the edges at
v
returns e
after (before)
sourceReference
if sourceD == AFTER (sourceD == BEFORE)
and an iteration over the edges at w
return
e
after (before)
targetReference
if targetD == AFTER (targetD == BEFORE)
.
Precondition: Edges e
must be contained in this graph and either
sourceReference
or newSource
must be non-null and
contained in the graph as well
as targetReference
or newTarget
.
- Parameters:
e
- the edge to be changednewSource
- the new sourcesourceReference
- reference edge for insertion at the new source nodesourceD
- one of the object insertion specifiers BEFORE or AFTERnewTarget
- the new targettargetReference
- reference edge for insertion at the new target nodetargetD
- one of the object insertion specifiers BEFORE or AFTER
public void changeEdge(Edge e, Node newSource, Node newTarget)
e
.
Precondition: newSource, newTarget
must be contained in this graph.
e
- the edge to be changednewSource
- the new source node of the given edgenewTarget
- the new target node of the given edgepublic void reverseEdge(Edge e)
public void hide(Edge e)
The difference to a proper object removal as performed by
Graph.removeEdge(Edge)
or Graph.removeNode(Node)
is that
no GraphEvents will be emitted that signal object removal.
Hiding should be used in the sense of temporarily removing an
object that will be reinserted shortly after.
To reinsert a hidden object again use unhide(edge)
or unhide(Node)
.
public void unhide(Edge e)
Graph.hide(Edge)
.
The difference to a proper object reinsertion as performed by
Graph.reInsertEdge(Edge)
or Graph.reInsertNode(Node)
is that
no GraphEvents will be emitted that signal object reinsertion.
To reinsert a hidden object again use unhide(edge)
or unhide(Node)
.
public void hide(Node v)
The difference to a proper object removal as performed by
Graph.removeEdge(Edge)
or Graph.removeNode(Node)
is that
no GraphEvents will be emitted that signal object removal.
Hiding should be used in the sense of temporarily removing an
object that will be reinserted shortly after.
To reinsert a hidden object again use unhide(edge)
or unhide(Node)
.
public void unhide(Node v)
Graph.hide(Node)
.
The difference to a proper object reinsertion as performed by
Graph.reInsertEdge(Edge)
or Graph.reInsertNode(Node)
is that
no GraphEvents will be emitted that signal object reinsertion.
To reinsert a hidden object again use unhide(edge)
or unhide(Node)
.
public void moveToLast(Node v)
public void moveToFirst(Node v)
public void moveToLast(Edge e)
public void moveToFirst(Edge e)
public int N()
Graph.nodeCount()
.
public int nodeCount()
public int E()
Graph.edgeCount()
public int edgeCount()
public boolean isEmpty()
true
if graph contains no nodes, otherwise
false
public void clear()
public boolean contains(Node v)
public boolean contains(Edge e)
public boolean containsEdge(Node source, Node target)
source
to node target
.
Node.getEdgeTo(Node)
,
Node.getEdgeFrom(Node)
,
Node.getEdge(Node)
public Node firstNode()
Precondition: !isEmpty()
public Edge firstEdge()
Precondition: edgeCount() > 0
public Node lastNode()
Precondition: !isEmpty()
public Edge lastEdge()
Precondition: edgeCount() > 0
public Node[] getNodeArray()
public Edge[] getEdgeArray()
public NodeCursor nodes()
public EdgeCursor edges()
public EdgeList moveSubGraph(NodeList subNodes, Graph targetGraph)
public Graph createGraph()
public void sortEdges(Comparator inComp, Comparator outComp)
null
then outedges, inedges resp.,
will not be sorted.
inComp
- the edge comparator used for the ingoing edges at a node.outComp
- the edge comparator used for the outgoing edges at a node.public void addGraphListener(GraphListener listener)
public void removeGraphListener(GraphListener listener)
public Iterator getGraphListeners()
public void firePreEvent()
firePostEvent
follows.
public void firePreEvent(Object id)
Graph.firePreEvent()
. Additionally an event id may be specified.
public void firePostEvent()
firePreEvent
was made.
public void firePostEvent(Object id)
Graph.firePostEvent()
. Additionally an event id may be specified.
protected void fireGraphEvent(GraphEvent e)
public NodeMap createNodeMap()
O(n)
memory at all times and
provides true O(1)
read and write access for each node.
In order to release the resources held by this map, Graph.disposeNodeMap(NodeMap)
has to be called.
public EdgeMap createEdgeMap()
O(m)
memory at all times and
provides true O(1)
read and write access for each node.
In order to release the resources held by this map, Graph.disposeEdgeMap(EdgeMap)
has to be called.
public void disposeNodeMap(NodeMap map)
Graph.createNodeMap()
factory method.
Calling this method will destroy the node map and associated
resources can be freed. It is strongly suggested to dispose all node maps
that are not needed anymore using this method.
public void disposeEdgeMap(EdgeMap map)
Graph.createEdgeMap()
factory method.
Calling this method will destroy the edge map and associated
resources can be freed. It is strongly suggested to dispose all edge maps
that are not needed anymore using this method.
public NodeMap[] getRegisteredNodeMaps()
Graph.createNodeMap()
,
Graph.disposeNodeMap(NodeMap)
public EdgeMap[] getRegisteredEdgeMaps()
Graph.createEdgeMap()
,
Graph.disposeEdgeMap(EdgeMap)
public Object getSource(Object edge)
getSource
in interface GraphInterface
public Object getTarget(Object edge)
getTarget
in interface GraphInterface
public Iterator nodeObjects()
nodeObjects
in interface GraphInterface
public Iterator edgeObjects()
edgeObjects
in interface GraphInterface
public DataProvider getDataProvider(Object providerKey)
getDataProvider
in interface GraphInterface
public void addDataProvider(Object providerKey, DataProvider data)
public void removeDataProvider(Object providerKey)
public Object[] getDataProviderKeys()
getDataProviderKeys
in interface GraphInterface
protected static final Edge firstOutEdge(Node v)
public void printNodeSlotSize()
public String toString()
toString
in class Object
|
© Copyright 2000-2003, yWorks GmbH. All rights reserved. 2003 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |