gishur.graph.core
Class Graph

java.lang.Object
  |
  +--gishur.graph.core.GraphElement
        |
        +--gishur.graph.core.Node
              |
              +--gishur.graph.core.Graph
All Implemented Interfaces:
java.lang.Cloneable, Cloneable, ControlledCloneable, KeyValueHolder, Owner, java.io.Serializable

public class Graph
extends Node
implements Owner, ControlledCloneable

Version:
1.0
Author:
Thomas Wolf & Christoph Sachse
See Also:
Serialized Form

Field Summary
static boolean DIRECTED
          Graph type constant indicating a directed Graph
static boolean UNDIRECTED
          Graph type constant indicating an undirected Graph
 
Fields inherited from class gishur.graph.core.GraphElement
ACCESS_CONNECT, ACCESS_REMOVE, BOTH, DETAILED, IN, LINK_ALL, NORMAL, OUT, SET_KEY, SET_VALUE, SHORT, VERY_DETAILED
 
Fields inherited from interface gishur.core.ControlledCloneable
DEEP, FLAT
 
Constructor Summary
Graph()
          Constructor of an undirected empty Graph without a name.
Graph(boolean type)
          Constructor of Graph of given type
Graph(java.lang.String name)
          Constructor of an undirected Graph.
Graph(java.lang.String name, boolean type)
          Constructor for a Graph of given type type.
 
Method Summary
 void add(Edge e)
           
 void add(Edge e, Node a, Node b)
           
 void add(java.util.Enumeration enum)
           
 void add(Node n)
           
protected  boolean checkAccess(int access, java.lang.Object argument)
          Overridden GraphElement.checkAccess(int, java.lang.Object) method, working the same way.
 void clear()
           
 java.lang.Object clone(java.util.Hashtable h, int level)
          Clones this object.
 boolean contains(GraphElement e)
          Checks if the Graph contains the given Node.
static Graph createDirectedGraph()
          Creates and returns a new Graph which is preset to be directed.
static Graph createDirectedGraph(java.lang.String name)
          Creates and returns a new Graph which is preset to be directed and has the given name.
static Graph createUndirectedGraph()
          Creates and returns a new Graph which is preset to be undirected.
static Graph createUndirectedGraph(java.lang.String name)
          Creates and returns a new Graph which is preset to be undirected and has the given name.
 boolean directed()
          Returns DIRECTED if the graph is directed and UNDIRECTED otherwise.
 Edge edge(int i)
          Returns the i-th Edge of this Graph.
 GraphCursor edges()
          Creates and returns a GraphCursor which is able to navigate over the Edges of this Graph.
 GraphCursor edges(Edge e)
          Creates and returns a GraphCursor which is able to navigate over the Edges of this Graph and whose starting position is e.
 GraphCursor edges(Node u)
          Creates and returns a GraphCursor which is able to move over the Edges connected to u inside this Graph.
 GraphCursor edges(Node u, Edge e)
          Creates and returns a GraphCursor which is able to move over the Edges connected to u inside this Graph.
 int edgesLength()
          Returns the number of Edges of this Graph.
protected  java.lang.String edgesListToString(int level)
          Returns a list of the Edges of the Graph in the form "edge1,edge2,..." where "edgek" is the GraphElement.SHORT or GraphElement.NORMAL string representation of the k-th Edge.
 GraphCursor inEdges(Node u)
          Creates and returns a GraphCursor which is able to move over the igoing Edges of u inside this Graph.
 GraphCursor inEdges(Node u, Edge e)
          Creates and returns a GraphCursor which is able to move over the ingoing Edges of u inside this Graph.
 Node node(int i)
          Returns the i-th Node of this Graph.
 GraphCursor nodes()
          Creates and returns a GraphCursor which is able to navigate over the Nodes of this Graph.
 GraphCursor nodes(Node u)
          Creates and returns a GraphCursor which is able to navigate over the Nodes of this Graph and whose starting position is u.
 int nodesLength()
          Returns the number of Nodes of this Graph.
protected  java.lang.String nodesListToString(int level)
          Returns a list of the Nodes of the Graph in the form "node1,node2,..." where "nodek" is the GraphElement.SHORT string representation of the k-th Node.
 GraphCursor outEdges(Node u)
          Creates and returns a GraphCursor which is able to move over the outgoing Edges of u inside this Graph.
 GraphCursor outEdges(Node u, Edge e)
          Creates and returns a GraphCursor which is able to move over the outgoing Edges of u inside this Graph.
 void remove(Edge e)
           
 void remove(Node u)
           
 void removeEdgePropertiesStartingWith(java.lang.String key)
          Removes the properties stored under keys starting with substring key from all Edges of this Graph.
 void removeNodePropertiesStartingWith(java.lang.String key)
          Removes the properties stored under keys starting with substring key from all Nodes of this Graph.
 void removePropertyForAllEdges(java.lang.String key)
          Removes the property stored under key key from all Edges of this Graph.
 void removePropertyForAllNodes(java.lang.String key)
          Removes the property stored under key key from all Nodes of this Graph.
 boolean requestAccess(int access, java.lang.Object trigger, java.lang.Object obj)
          Decides if an action on the graph is permitted or denied.
 boolean setDirected(boolean direct)
          Makes the graph (un)directed.
 void setPropertyForAllEdges(java.lang.String key, java.lang.Object o)
          Sets the property defined by key for all contained Edges of the Graph to value o.
 void setPropertyForAllNodes(java.lang.String key, java.lang.Object o)
          Sets the property defined by key for all contained Nodes of the Graph to value o.
 void setSerialization(boolean serial)
          This method marks Graphs to be serialized while a serialization process.
protected  java.lang.String stateToString()
          Returns the state of the Graph as a string.
 java.lang.String toString()
          Returns a GraphElement.DETAILED string representation of the Graph.
 java.lang.String toString(int level, int nodeLevel, int edgeLevel)
          Overridden toString method.
 
Methods inherited from class gishur.graph.core.Node
degree, generateName, inDegree, outDegree, preferredPosition, setPreferredPosition, toString
 
Methods inherited from class gishur.graph.core.GraphElement
addOwner, checkState, checkStateCleared, clearState, clone, countConnectedElements, createFlow, createFlow, cursor, cursor, element, flow, getBoolProperty, getDoubleProperty, getEdgeProperty, getFloatProperty, getGraphElementProperty, getIntProperty, getLongProperty, getNodeProperty, getProperties, getProperty, getProperty, getShortProperty, getSortedProperties, getSortedProperties, hasProperty, isConnectedTo, isOwner, key, linkListToString, linkTypeToString, name, opposite, ownerListToString, propertiesToString, removeAllProperties, removeFlow, removePropertiesStartingWith, removeProperty, setKey, setName, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setProperty, setState, setValue, state, state, value
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface gishur.core.Cloneable
clone
 

Field Detail

DIRECTED

public static final boolean DIRECTED
Graph type constant indicating a directed Graph

UNDIRECTED

public static final boolean UNDIRECTED
Graph type constant indicating an undirected Graph
Constructor Detail

Graph

public Graph()
Constructor of an undirected empty Graph without a name.

Graph

public Graph(java.lang.String name)
Constructor of an undirected Graph.
Parameters:
name - name of the Graph

Graph

public Graph(boolean type)
Constructor of Graph of given type
Parameters:
type - type of the Graph which can be DIRECTED or UNDIRECTED

Graph

public Graph(java.lang.String name,
             boolean type)
Constructor for a Graph of given type type.
Parameters:
name - name of the Graph
type - type of the Graph which can be DIRECTED or UNDIRECTED
Method Detail

createDirectedGraph

public static Graph createDirectedGraph()
Creates and returns a new Graph which is preset to be directed.
Returns:
new directed Graph

createDirectedGraph

public static Graph createDirectedGraph(java.lang.String name)
Creates and returns a new Graph which is preset to be directed and has the given name.
Returns:
new directed Graph with name name

createUndirectedGraph

public static Graph createUndirectedGraph()
Creates and returns a new Graph which is preset to be undirected.
Returns:
new undirected Graph

createUndirectedGraph

public static Graph createUndirectedGraph(java.lang.String name)
Creates and returns a new Graph which is preset to be undirected and has the given name.
Returns:
new undirected Graph with name name

toString

public java.lang.String toString(int level,
                                 int nodeLevel,
                                 int edgeLevel)
Overridden toString method. It returns a String representing this Graph in a definable level of detail. The various aspects of the Graph which should be returned as a String can be defined by level. If level==GraphElement.SHORT, only the name of the Graph will be returned. level==GraphElement.NORMAL causes the method to return a string consistent of the name and the lists of Nodes and Edges of this Graph. level==GraphElement.DETAILED includes additionally a string representing the state, e.g. #DIRECTED_GRAPH. Finally, level==GraphElement.VERY_DETAILED includes a additional list of the properties. The argument edgeLevel may be either GraphElement.SHORT or GraphElement.NORMAL and determines the level of detail in which the list of Edges shall be printed out.
Parameters:
level - a level constant, GraphElement.SHORT,GraphElement.NORMAL, GraphElement.DETAILED or GraphElement.VERY_DETAILED, determining the requested level of detail
nodeLevel - a level constant, GraphElement.SHORT,GraphElement.NORMAL, GraphElement.DETAILED or GraphElement.VERY_DETAILED, determining the requested level of detail for Nodes
edgeLevel - a level constant, GraphElement.SHORT,GraphElement.NORMAL, GraphElement.DETAILED or GraphElement.VERY_DETAILED, determining the requested level of detail for Edges
Returns:
a descripting String for this Graph

toString

public java.lang.String toString()
Returns a GraphElement.DETAILED string representation of the Graph.
Overrides:
toString in class GraphElement
Returns:
a GraphElement.DETAILED string representation of the Graph
See Also:
#toString(int,int)

nodesListToString

protected java.lang.String nodesListToString(int level)
Returns a list of the Nodes of the Graph in the form "node1,node2,..." where "nodek" is the GraphElement.SHORT string representation of the k-th Node.
Parameters:
level - a level constant, GraphElement.SHORT,GraphElement.NORMAL, GraphElement.DETAILED or GraphElement.VERY_DETAILED, determining the requested level of detail
Returns:
the list of Nodes as a string

edgesListToString

protected java.lang.String edgesListToString(int level)
Returns a list of the Edges of the Graph in the form "edge1,edge2,..." where "edgek" is the GraphElement.SHORT or GraphElement.NORMAL string representation of the k-th Edge. The requested level of detail is defined by level, but only GraphElement.SHORT or GraphElement.NORMAL are valid values. An invalid value is set to GraphElement.SHORT.
Parameters:
level - a level constant, GraphElement.SHORT,GraphElement.NORMAL, GraphElement.DETAILED or GraphElement.VERY_DETAILED, determining the requested level of detail
Returns:
the list of Edges as a string

stateToString

protected java.lang.String stateToString()
Returns the state of the Graph as a string.
Returns:
the string representation of the state.

add

public void add(Node n)

add

public void add(Edge e)

add

public void add(Edge e,
                Node a,
                Node b)

remove

public void remove(Edge e)

remove

public void remove(Node u)

add

public void add(java.util.Enumeration enum)

clear

public void clear()

edges

public GraphCursor edges()
Creates and returns a GraphCursor which is able to navigate over the Edges of this Graph.
Returns:
an GraphCursor for this Graph
See Also:
GraphCursor

edges

public GraphCursor edges(Edge e)
Creates and returns a GraphCursor which is able to navigate over the Edges of this Graph and whose starting position is e.
Returns:
an GraphCursor for this Graph
See Also:
GraphCursor

nodes

public GraphCursor nodes()
Creates and returns a GraphCursor which is able to navigate over the Nodes of this Graph.
Returns:
an GraphCursor for this Graph
See Also:
GraphCursor

nodes

public GraphCursor nodes(Node u)
Creates and returns a GraphCursor which is able to navigate over the Nodes of this Graph and whose starting position is u.
Returns:
an GraphCursor for this Graph
See Also:
GraphCursor

outEdges

public GraphCursor outEdges(Node u)
Creates and returns a GraphCursor which is able to move over the outgoing Edges of u inside this Graph. The GraphCursor is initially set to the first outgoing Edge.
Parameters:
u - the Node whose outgoing Edges shall be traversed
Returns:
a GraphCursor on the outgoing Edges of u

outEdges

public GraphCursor outEdges(Node u,
                            Edge e)
Creates and returns a GraphCursor which is able to move over the outgoing Edges of u inside this Graph. The GraphCursor is initially set to e, which must thus be contained in this Graph and must itself be an outgoing Edge. If one of these conditions is not fulfilled, a GraphException will occur.
Parameters:
u - the Node whose outgoing Edges shall be traversed
e - the initial position of the GraphCursor
Returns:
a GraphCursor on the outgoing Edges of u

inEdges

public GraphCursor inEdges(Node u)
Creates and returns a GraphCursor which is able to move over the igoing Edges of u inside this Graph. The GraphCursor is initially set to the first igoing Edge.
Parameters:
u - the Node whose igoing Edges shall be traversed
Returns:
a GraphCursor on the ingoing Edges of u

inEdges

public GraphCursor inEdges(Node u,
                           Edge e)
Creates and returns a GraphCursor which is able to move over the ingoing Edges of u inside this Graph. The GraphCursor is initially set to e, which must thus be contained in this Graph and must itself be an ingoing Edge. If one of these conditions is not fulfilled, a GraphException will occur.
Parameters:
u - the Node whose ingoing Edges shall be traversed
e - the initial position of the GraphCursor
Returns:
a GraphCursor on the ingoing Edges of u

edges

public GraphCursor edges(Node u)
Creates and returns a GraphCursor which is able to move over the Edges connected to u inside this Graph. The GraphCursor is initially set to the first Edge.
Parameters:
u - the Node whose adjacent Edges shall be traversed
Returns:
a GraphCursor on the Edges adjacent to u

edges

public GraphCursor edges(Node u,
                         Edge e)
Creates and returns a GraphCursor which is able to move over the Edges connected to u inside this Graph. The GraphCursor is initially set to e, which must thus be contained in this Graph and must itself be an adjacent Edge. If one of these conditions is not fulfilled, a GraphException will occur.
Parameters:
u - the Node whose adjacent Edges shall be traversed
e - the initial position of the GraphCursor
Returns:
a GraphCursor on the Edges adjacent to u

contains

public boolean contains(GraphElement e)
Checks if the Graph contains the given Node.
Parameters:
Node - node to test
Returns:
true if the Graph contains the node

edgesLength

public int edgesLength()
Returns the number of Edges of this Graph.

nodesLength

public int nodesLength()
Returns the number of Nodes of this Graph.

edge

public Edge edge(int i)
Returns the i-th Edge of this Graph. If i represents an invalid index, null will be returned.
Parameters:
i - the index of the {link Edge} to return
Returns:
the i-th Edge of this Graph

node

public Node node(int i)
Returns the i-th Node of this Graph. If i represents an invalid index, null will be returned.
Parameters:
i - the index of the {link Node} to return
Returns:
the i-th Node of this Graph

directed

public boolean directed()
Returns DIRECTED if the graph is directed and UNDIRECTED otherwise.
Returns:
graph type

setDirected

public boolean setDirected(boolean direct)
Makes the graph (un)directed.
Parameters:
direct - if true, the graph will be directed, otherwise it will be undirected
Returns:
 

requestAccess

public boolean requestAccess(int access,
                             java.lang.Object trigger,
                             java.lang.Object obj)
Decides if an action on the graph is permitted or denied.
Specified by:
requestAccess in interface Owner
Parameters:
access - requested action
trigger - object which triggered the action.
obj - object on which the action should apply
Returns:
permittion return false, if the action is denied, but no Exeception should be thrown.

checkAccess

protected boolean checkAccess(int access,
                              java.lang.Object argument)
Overridden GraphElement.checkAccess(int, java.lang.Object) method, working the same way.
Overrides:
checkAccess in class Node
Following copied from class: gishur.graph.core.Node
Parameters:
access - an access constant specifying the requested operation
argument - the argument of the requested operation
Returns:
true, if the operation is allowed, false otherwise

setPropertyForAllNodes

public void setPropertyForAllNodes(java.lang.String key,
                                   java.lang.Object o)
Sets the property defined by key for all contained Nodes of the Graph to value o. The method returns effectiveless if key==null or o==null.
Parameters:
key - key string defining which propery to set
o - further value of property s

setPropertyForAllEdges

public void setPropertyForAllEdges(java.lang.String key,
                                   java.lang.Object o)
Sets the property defined by key for all contained Edges of the Graph to value o. The method returns effectiveless if key==null or o==null.
Parameters:
key - key string defining which propery to set
o - further value of property s

removePropertyForAllNodes

public void removePropertyForAllNodes(java.lang.String key)
Removes the property stored under key key from all Nodes of this Graph. The method returns effectiveless if key==null.
Parameters:
key - key string defining which property to remove

removePropertyForAllEdges

public void removePropertyForAllEdges(java.lang.String key)
Removes the property stored under key key from all Edges of this Graph. The method returns effectiveless if key==null.
Parameters:
key - key string defining which property to remove

removeNodePropertiesStartingWith

public void removeNodePropertiesStartingWith(java.lang.String key)
Removes the properties stored under keys starting with substring key from all Nodes of this Graph. The method returns effectiveless if key==null.
Parameters:
key - key string defining which properties to remove

removeEdgePropertiesStartingWith

public void removeEdgePropertiesStartingWith(java.lang.String key)
Removes the properties stored under keys starting with substring key from all Edges of this Graph. The method returns effectiveless if key==null.
Parameters:
key - key string defining which properties to remove

clone

public java.lang.Object clone(java.util.Hashtable h,
                              int level)
Clones this object. According to the parameter level, this object will be cloned down to level levels. That means, the object will be cloned. If level==-1(==DEEP), every object, which can be reached by traversing the references beginning with /this object will be cloned if possible. This recursion stopps, if there are no more objects to clone, or no reachable object implements Cloneable. If level==1(==FLAT), no object contained by this object will be cloned, but this will be cloned. Only the references will be maintained. If level>=0, no objects will be cloned at all and this will be returned.
The recursive cloning stopps, if there's a ring structure. In this case, all Objects implementing Cloneable are cloned, and connected properly, so that even ring structures are cloned as rings. A GraphElement's cloning behaviour is somewhat special: The lists containing the Owners, linked GraphElements and their link types are not cloned, but set to null in the cloned object. But the properties are cloned, i.e. all cloneable values they are containing are cloned (not the keys!). The values which are not cloneable, will be only referenced in the cloned properties list.
Specified by:
clone in interface ControlledCloneable
Overrides:
clone in class GraphElement
Parameters:
h - Hastable which containes all objects already cloned (with their original objects as keys), to avoid multiple cloning of the same object (if h==null a new Hashtable will be created - you can use null to start a clone recursion)
level - indicates how many generations should be cloned recursive at most
Returns:
the cloned Object
Throws:
InternalError - - if the Object could not be cloned properly

setSerialization

public void setSerialization(boolean serial)
This method marks Graphs to be serialized while a serialization process. On writing a Graph to a stream, this Graph will be marked (with serial=true). But all connected Graphs (like additional owners of some elements) will not be written, except they are marked for serialization too (this may be the case if they are already written to streams). To enable a Graph to be serialized or to prevent serialization, one may use this method to mark/unmark Graphs for serialization.
Parameters:
serial - if true, the Graph will be serialized otherwise it prevents serialization