de.fhstralsund.vinets.structure
Class SimpleGraph

java.lang.Object
  extended by de.fhstralsund.vinets.structure.DefaultNetElement
      extended by de.fhstralsund.vinets.structure.AbstractGraph
          extended by de.fhstralsund.vinets.structure.SimpleGraph
All Implemented Interfaces:
Graph, NetElement, java.io.Serializable, java.lang.Cloneable

public class SimpleGraph
extends AbstractGraph

The standard implementation of the Graph interface. Directed, undirected or mixed graphs are supported. There cannot exist loops and parallel edges, and no hyperedges. The factory methods deliver nodes or edges with this Graph as host.

See Also:
Serialized Form

Nested Class Summary
protected  class SimpleGraph.ParallelEdgeException
           
protected  class SimpleGraph.SimpleEdge
          The standard implementation of the Edge interface.
protected  class SimpleGraph.SimpleNode
          The standard implementation of the Node interface, an atomar Node.
 
Field Summary
 
Fields inherited from class de.fhstralsund.vinets.structure.AbstractGraph
E, gType, V
 
Fields inherited from class de.fhstralsund.vinets.structure.DefaultNetElement
host, labelMap, original
 
Constructor Summary
SimpleGraph()
           
SimpleGraph(GraphType type)
           
SimpleGraph(GraphType type, java.lang.String name)
           
SimpleGraph(GraphType type, java.lang.String name, java.lang.Object data)
           
 
Method Summary
 java.lang.Object clone()
          Creates and returns a special copy of this NetElement.
 java.lang.Object convert(GraphType toType)
          Delivers a new SimpleGraph that is almost a copy of this one, but transformed to the given GraphType.
protected  void copyEdges(SimpleGraph copy, java.util.Map nodeMap)
          Supplies the copy of this SimpleGraph with a new edge set containing copies of all its Edges.
protected  java.util.HashMap copyNodes(SimpleGraph copy)
          Clones all Nodes of this SimpleGraph into the vertex set of the parameter and supplies the assignment (oldNode, newNode) as HashSet.
 Link createEdge(Node start, Node end)
          Constructs and returns a new (un)directed SimpleEdge corresponding to the type of this SimpleGraph.
 Link createEdge(Node start, Node end, boolean directed)
          Constructs and returns a new directed or undirected SimpleEdge.
 Link createEdge(Node start, Node end, boolean directed, java.lang.Object data)
          Constructs and returns a new directed or undirected SimpleEdge.
 Node createNode()
          Creates and returns a new SimpleNode contained in this SimpleGraph.
 Node createNode(java.lang.String name)
          Creates and returns a new SimpleNode contained in this SimpleGraph.
 Node createNode(java.lang.String name, java.lang.Object data)
          Creates and returns a new SimpleNode contained in this SimpleGraph.
 boolean remove(NetElement n)
          Removes a SimpleNode or SimpleEdge from this SimpleGraph.
protected  boolean removeEdge(SimpleGraph.SimpleEdge e)
          Remove an Edge from this SimpleGraph.
protected  boolean removeNode(SimpleGraph.SimpleNode v)
          A Node is removed together with all its incident Edges.
 
Methods inherited from class de.fhstralsund.vinets.structure.AbstractGraph
countEdges, countNodes, edges, edgeSet, equals, getGraphType, hashCode, isDirected, isHyperGraph, isMixed, isUndirected, nodes, nodeSet, toString
 
Methods inherited from class de.fhstralsund.vinets.structure.DefaultNetElement
clearLabels, containsLabel, getBooleanLabel, getData, getDoubleLabel, getGeometry, getHost, getID, getIntLabel, getLabel, getLabelKeySet, getName, getOriginal, getRepresentation, removeLabel, setBooleanLabel, setData, setDoubleLabel, setGeometry, setIntLabel, setLabel, setName, setRepresentation
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface de.fhstralsund.vinets.structure.NetElement
clearLabels, containsLabel, getBooleanLabel, getData, getDoubleLabel, getGeometry, getHost, getID, getIntLabel, getLabel, getLabelKeySet, getName, getOriginal, getRepresentation, removeLabel, setBooleanLabel, setData, setDoubleLabel, setGeometry, setIntLabel, setLabel, setName, setRepresentation
 

Constructor Detail

SimpleGraph

public SimpleGraph()

SimpleGraph

public SimpleGraph(GraphType type)

SimpleGraph

public SimpleGraph(GraphType type,
                   java.lang.String name)

SimpleGraph

public SimpleGraph(GraphType type,
                   java.lang.String name,
                   java.lang.Object data)
Method Detail

createNode

public Node createNode(java.lang.String name,
                       java.lang.Object data)
Creates and returns a new SimpleNode contained in this SimpleGraph.

Parameters:
name - a name used to identify this Node for the user.
data - external data of any kind that an application may need.
Returns:
a new SimpleNode instance.

createNode

public Node createNode(java.lang.String name)
Creates and returns a new SimpleNode contained in this SimpleGraph.

Parameters:
name - a name used to identify this Node for the user.
Returns:
a new SimpleNode instance.

createNode

public Node createNode()
Creates and returns a new SimpleNode contained in this SimpleGraph.

Returns:
a new SimpleNode instance.

createEdge

public Link createEdge(Node start,
                       Node end,
                       boolean directed,
                       java.lang.Object data)
Constructs and returns a new directed or undirected SimpleEdge. The source and target nodes should be contained in this SimpleGraph. If this SimpleGraph is (UN)DIRECTED, only (UN)DIRECTED edges can be created.

Parameters:
start - source Node.
end - target Node.
directed - true if the Edge is directed, false otherwise.
data - external data of any kind that an application may need.
Returns:
a new SimpleEdge instance or null if an equal Edge already exists.
Throws:
java.lang.IllegalArgumentException - if start or end have a wrong host or the edge type is not feasible for this SimpleGraph.

createEdge

public Link createEdge(Node start,
                       Node end,
                       boolean directed)
Constructs and returns a new directed or undirected SimpleEdge. The source and target nodes should be contained in this SimpleGraph. If this SimpleGraph is (UN)DIRECTED, only (UN)DIRECTED edges can be created.

Parameters:
start - source Node.
end - target Node.
directed - true if the Edge is dirceted, false otherwise.
Returns:
a new SimpleEdge instance or null if an equal Edge already exists.
Throws:
java.lang.IllegalArgumentException - if start or end have a wrong host orthe edge type is not feasible for this SimpleGraph.

createEdge

public Link createEdge(Node start,
                       Node end)
Constructs and returns a new (un)directed SimpleEdge corresponding to the type of this SimpleGraph. If the type is MIXED, a directed edge is created. The source and target nodes should be contained in this SimpleGraph.

Parameters:
start - source Node.
end - target Node.
Returns:
a new SimpleEdge instance or null if an equal Edge already exists.
Throws:
java.lang.IllegalArgumentException - if start or end have a wrong host.

remove

public boolean remove(NetElement n)
Removes a SimpleNode or SimpleEdge from this SimpleGraph.

Parameters:
n - the NetElement to be removed.
Returns:
true (always).
Throws:
java.lang.IllegalArgumentException - if n has a wrong type or host.

convert

public java.lang.Object convert(GraphType toType)
Delivers a new SimpleGraph that is almost a copy of this one, but transformed to the given GraphType. That means that all nodes are cloned and the edges are replaced by copies of the desired type.
If this Graph already has the desired Type, this.clone() is called, actually.
If the desired GraphType is MIXED, all edges are cloned, too.
If the desired GraphType is UNDIRECTED, every directed edge is replaced by an undirected one, undirected edges are cloned.
If the desired GraphType is DIRECTED, every undirected edge is replaced by a pair of directed edges in opposite directions.
Any element of the result has a link to its original in this Graph.

Parameters:
toType - the GraphType to convert to.
Returns:
a new SimpleGraph of desired Type corresponding to this one.
Throws:
java.lang.IllegalArgumentException - if trying to convert to HYPERGRAPH.
See Also:
clone()

clone

public java.lang.Object clone()
Description copied from class: DefaultNetElement
Creates and returns a special copy of this NetElement. The copy has a new ID, its attribute original is set to this NetElement. The attributes name, host and data are shared by the copy and this original. The attributes geometry, representation and labelMap are cloned - but notice that the (key, value)-pairs for properties in the labelMap are shared. So, do not change a value Object associated to a key after cloning. Instead, remove the label and set a new one, if a change is needed.

Specified by:
clone in interface Graph
Overrides:
clone in class DefaultNetElement
Returns:
a new DefaultNetElement instance equal to this one.

removeEdge

protected boolean removeEdge(SimpleGraph.SimpleEdge e)
Remove an Edge from this SimpleGraph. The host of the Edge is set to null.

Parameters:
e - the Edge to remove.
Returns:
true (always).

removeNode

protected boolean removeNode(SimpleGraph.SimpleNode v)
A Node is removed together with all its incident Edges. The Node should have this SimpleGraph as its host.

Parameters:
v - the Node to remove.
Returns:
true (always)

copyNodes

protected java.util.HashMap copyNodes(SimpleGraph copy)
Clones all Nodes of this SimpleGraph into the vertex set of the parameter and supplies the assignment (oldNode, newNode) as HashSet.

Parameters:
copy - a skeleton copy of this SimpleGraph to which the new Nodes should be added.
Returns:
a HashMap that maps the old Nodes to their copies.

copyEdges

protected void copyEdges(SimpleGraph copy,
                         java.util.Map nodeMap)
Supplies the copy of this SimpleGraph with a new edge set containing copies of all its Edges. If the GraphType of this and copy are different, the direction of some edges is changed accordingly: If the copy GraphType is UNDIRECTED, every directed edge is replaced by an undirected one, undirected edges are cloned. If the copy GraphType is DIRECTED, every undirected edge is replaced by a pair of directed edges in opposite directions.

Parameters:
copy - a skeleton copy of this SimpleGraph to which the new Edges should be added.
nodeMap - the HashMap that maps the old Nodes to their copies.