Package org.graffiti.graph
Class OptAdjListGraph
java.lang.Object
org.graffiti.attributes.AbstractAttributable
org.graffiti.graph.AbstractGraph
org.graffiti.graph.AdjListGraph
org.graffiti.graph.OptAdjListGraph
- All Implemented Interfaces:
Attributable
,DeepCopy
,Graph
public class OptAdjListGraph extends AdjListGraph implements Graph
Implements the
Graph
-interface using an adjacency list
representation of the graph. Requires AdjListNode
and
AdjListEdge
as implementations for nodes and edges. Every method
modifying the graph will inform the ListenerManager
about the
modification according to the description in Graph
.- Version:
- $Revision: 1.7 $
- See Also:
Graph
,AbstractGraph
,AdjListNode
,AdjListEdge
,AbstractNode
,AbstractEdge
-
Constructor Summary
Constructors Constructor Description OptAdjListGraph()
Constructs a new instance of anOptAdjListGraph
.OptAdjListGraph(CollectionAttribute coll)
Constructs a new instance of anOptAdjListGraph
.OptAdjListGraph(ListenerManager listenerManager)
Constructs a new instance of anOptAdjListGraph
.OptAdjListGraph(ListenerManager listenerManager, CollectionAttribute coll)
Constructs a new instance of anOptAdjListGraph
.OptAdjListGraph(Graph g, ListenerManager listenerManager)
Constructs a new instance of anOptAdjListGraph
from an instance of anyGraph
implementation.OptAdjListGraph(Graph g, ListenerManager listenerManager, CollectionAttribute coll)
Constructs a new instance of anOptAdjListGraph
from an instance of anyGraph
implementation. -
Method Summary
Modifier and Type Method Description boolean
containsEdge(Edge e)
Returnstrue
, if the graph contains the specified edge,false
otherwise.boolean
containsNode(Node n)
Returnstrue
, if the graph contains the specified node,false
otherwise.Object
copy()
Creates and returns a copy of the graph.Collection<Edge>
getEdges()
Returns ajava.util.Collection
containing all the edges of the current graph.Iterator<Edge>
getEdgesIterator()
Returns an iterator over the edges of the graph.List<Node>
getNodes()
Returns a list containing a copy of the node list of the graph.Iterator<Node>
getNodesIterator()
Returns an iterator over the nodes of the graph.int
getNumberOfDirectedEdges()
Returns the number of directed edges of the graph.int
getNumberOfEdges()
Returns the number of edges of the graph.int
getNumberOfNodes()
Returns the number of nodes in the graph.int
getNumberOfUndirectedEdges()
Returns the number of undirected edges in the graph.boolean
isDirected()
Indicates whether the graph is directed.boolean
isEmpty()
Returnstrue
if the graph is empty.boolean
isUndirected()
Indicates whether the graph is undirected.Methods inherited from class org.graffiti.graph.AdjListGraph
checkMaxGraphElementId, deleteAll, getEdges, getFileTypeDescription, getName, getName, isModified, numberGraphElements, setFileTypeDescription, setListenerManager, setModified, setName, setNodeFirst, setNodeLast, toString
Methods inherited from class org.graffiti.graph.AbstractGraph
addAttributeConsumer, addEdge, addEdge, addEdgeCopy, addGraph, addNode, addNode, addNodeCopy, areConnected, clear, deleteEdge, deleteNode, generateNextUniqueGraphElementId, getAttTypesManager, getCurrentMaxGraphElementId, getGraphElements, getListenerManager, removeAttributeConsumer, setDirected, setDirected
Methods inherited from class org.graffiti.attributes.AbstractAttributable
addAttribute, addBoolean, addByte, addDouble, addFloat, addInteger, addLong, addShort, addString, changeBoolean, changeByte, changeDouble, changeFloat, changeInteger, changeLong, changeShort, changeString, getAttribute, getAttributes, getBoolean, getByte, getDouble, getFloat, getInteger, getLong, getShort, getString, removeAttribute, setBoolean, setByte, setDouble, setFloat, setInteger, setLong, setShort, setString
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.graffiti.attributes.Attributable
addAttribute, addBoolean, addByte, addDouble, addFloat, addInteger, addLong, addShort, addString, changeBoolean, changeByte, changeDouble, changeFloat, changeInteger, changeLong, changeShort, changeString, getAttribute, getAttributes, getBoolean, getByte, getDouble, getFloat, getInteger, getListenerManager, getLong, getShort, getString, removeAttribute, setBoolean, setByte, setDouble, setFloat, setInteger, setLong, setShort, setString
Methods inherited from interface org.graffiti.graph.Graph
addAttributeConsumer, addEdge, addEdge, addEdgeCopy, addGraph, addNode, addNode, addNodeCopy, checkMaxGraphElementId, clear, deleteAll, deleteEdge, deleteNode, generateNextUniqueGraphElementId, getAttTypesManager, getCurrentMaxGraphElementId, getEdges, getFileTypeDescription, getGraphElements, getName, getName, isModified, numberGraphElements, removeAttributeConsumer, setDirected, setDirected, setFileTypeDescription, setListenerManager, setModified, setName
-
Constructor Details
-
OptAdjListGraph
public OptAdjListGraph()Constructs a new instance of anOptAdjListGraph
. Sets theListenerManager
of the new instance to the defaultListenerManager
. -
OptAdjListGraph
Constructs a new instance of anOptAdjListGraph
. Sets theListenerManager
of the new instance to the defaultListenerManager
.- Parameters:
coll
- theCollectionAttribute
of the currently createdOptAdjListGraph
instance.
-
OptAdjListGraph
Constructs a new instance of anOptAdjListGraph
. Sets theListenerManager
of the new instance to the specified one.- Parameters:
listenerManager
- listener manager for the graph.
-
OptAdjListGraph
Constructs a new instance of anOptAdjListGraph
. Sets theListenerManager
of the new instance to the specified one.- Parameters:
listenerManager
- listener manager for the graph.coll
- theCollectionAttribute
of the currently createdOptAdjListGraph
instance.
-
OptAdjListGraph
Constructs a new instance of anOptAdjListGraph
from an instance of anyGraph
implementation. Copies all nodes and edges from g into the new graph.- Parameters:
g
- anyGraph
implementation out of which anOptAdjListGraph
shall be generated.listenerManager
- listener manager for the graph.
-
OptAdjListGraph
Constructs a new instance of anOptAdjListGraph
from an instance of anyGraph
implementation. Copies all nodes and edges from g into the new graph.- Parameters:
g
- anyGraph
implementation out of which anOptAdjListGraph
shall be generated.listenerManager
- listener manager for the graph.coll
- theCollectionAttribute
of the currently createdOptAdjListGraph
instance.
-
-
Method Details
-
isDirected
public boolean isDirected()Indicates whether the graph is directed. A graph is directed if graph setting states this.- Specified by:
isDirected
in interfaceGraph
- Overrides:
isDirected
in classAbstractGraph
- Returns:
- a boolean indicating whether the graph is directed.
-
getEdges
Returns ajava.util.Collection
containing all the edges of the current graph.- Specified by:
getEdges
in interfaceGraph
- Overrides:
getEdges
in classAdjListGraph
- Returns:
- a
java.util.Collection
containing all the edges of the current graph.
-
getEdgesIterator
Returns an iterator over the edges of the graph. Note that the remove operation is not supported by this iterator.- Specified by:
getEdgesIterator
in interfaceGraph
- Overrides:
getEdgesIterator
in classAbstractGraph
- Returns:
- an iterator containing the edges of the graph.
-
isEmpty
public boolean isEmpty()Returnstrue
if the graph is empty. The graph is equal to a graph which has been cleared.- Specified by:
isEmpty
in interfaceGraph
- Overrides:
isEmpty
in classAbstractGraph
- Returns:
true
if the graph is empty,false
otherwise.
-
getNodes
Returns a list containing a copy of the node list of the graph. Removing elements from this collection will have no effect on the graph whereas nodes can be modified.- Specified by:
getNodes
in interfaceGraph
- Overrides:
getNodes
in classAdjListGraph
- Returns:
- a new
java.util.List
containing all the nodes of the graph.
-
getNodesIterator
Returns an iterator over the nodes of the graph. Note that the remove operation is not supported by this iterator.- Specified by:
getNodesIterator
in interfaceGraph
- Overrides:
getNodesIterator
in classAdjListGraph
- Returns:
- an iterator containing the nodes of the graph.
-
getNumberOfDirectedEdges
public int getNumberOfDirectedEdges()Returns the number of directed edges of the graph.- Specified by:
getNumberOfDirectedEdges
in interfaceGraph
- Overrides:
getNumberOfDirectedEdges
in classAbstractGraph
- Returns:
- the number of directed edges of the graph.
-
getNumberOfEdges
public int getNumberOfEdges()Returns the number of edges of the graph.- Specified by:
getNumberOfEdges
in interfaceGraph
- Overrides:
getNumberOfEdges
in classAdjListGraph
- Returns:
- the number of edges of the graph.
-
getNumberOfNodes
public int getNumberOfNodes()Returns the number of nodes in the graph.- Specified by:
getNumberOfNodes
in interfaceGraph
- Overrides:
getNumberOfNodes
in classAdjListGraph
- Returns:
- the number of nodes of the graph.
-
getNumberOfUndirectedEdges
public int getNumberOfUndirectedEdges()Returns the number of undirected edges in the graph.- Specified by:
getNumberOfUndirectedEdges
in interfaceGraph
- Overrides:
getNumberOfUndirectedEdges
in classAbstractGraph
- Returns:
- the number of undirected edges in the graph.
-
isUndirected
public boolean isUndirected()Indicates whether the graph is undirected. A graph is undirected if all the edges are undirected.- Specified by:
isUndirected
in interfaceGraph
- Overrides:
isUndirected
in classAbstractGraph
- Returns:
- A boolean indicating whether the graph is undirected.
-
containsEdge
Returnstrue
, if the graph contains the specified edge,false
otherwise.- Specified by:
containsEdge
in interfaceGraph
- Overrides:
containsEdge
in classAbstractGraph
- Parameters:
e
- the edge to search for.- Returns:
true
, if the graph contains the edge e,false
otherwise.
-
containsNode
Returnstrue
, if the graph contains the specified node,false
otherwise.- Specified by:
containsNode
in interfaceGraph
- Overrides:
containsNode
in classAbstractGraph
- Parameters:
n
- the node to search for.- Returns:
true
, if the graph contains the node n,false
otherwise.
-
copy
Creates and returns a copy of the graph. The attributes are copied as well as all nodes and edges.- Specified by:
copy
in interfaceDeepCopy
- Overrides:
copy
in classAdjListGraph
- Returns:
- a copy of the graph.
-