org.dishevelled.graph.impl
Class AbstractGraphDecorator<N,E>

java.lang.Object
  extended by org.dishevelled.graph.impl.AbstractGraphDecorator<N,E>
Type Parameters:
N - node value type
E - edge value type
All Implemented Interfaces:
Graph<N,E>

public abstract class AbstractGraphDecorator<N,E>
extends Object
implements Graph<N,E>

Abstract graph that decorates an instance of Graph.

Version:
$Revision$ $Date$
Author:
Michael Heuer

Constructor Summary
protected AbstractGraphDecorator(Graph<N,E> graph)
          Create a new abstract graph that decorates the specified graph.
 
Method Summary
 void clear()
          Clear the nodes and edges in this graph (optional operation).
 Edge<N,E> createEdge(Node<N,E> source, Node<N,E> target, E value)
          Create and return a new edge in this graph with the specified value connecting the specified source and target nodes (optional operation).
 Node<N,E> createNode(N value)
          Create and return a new node in this graph with the specified value (optional operation).
 int edgeCount()
          Return the number of edges in this graph.
<T> Map<Edge<N,E>,T>
edgeMap(T defaultValue)
          Return a map of type <Edge<N, E>, T> with the edges in this graph as keys.
 Set<Edge<N,E>> edges()
          Return a read-only set view of the edges in this graph.
 Collection<E> edgeValues()
          Return a read-only collection view of the edge values in this graph.
 void forEachEdge(UnaryPredicate<Edge<N,E>> predicate, UnaryProcedure<Edge<N,E>> procedure)
          Apply the specified procedure to each edge in this graph accepted by the specified predicate.
 void forEachEdge(UnaryProcedure<Edge<N,E>> procedure)
          Apply the specified procedure to each edge in this graph.
 void forEachEdgeValue(UnaryPredicate<E> predicate, UnaryProcedure<E> procedure)
          Apply the specified procedure to each edge value in this graph accepted by the specified predicate.
 void forEachEdgeValue(UnaryProcedure<? super E> procedure)
          Apply the specified procedure to each edge value in this graph.
 void forEachNode(UnaryPredicate<Node<N,E>> predicate, UnaryProcedure<Node<N,E>> procedure)
          Apply the specified procedure to each node in this graph accepted by the specified predicate.
 void forEachNode(UnaryProcedure<Node<N,E>> procedure)
          Apply the specified procedure to each node in this graph.
 void forEachNodeValue(UnaryPredicate<N> predicate, UnaryProcedure<N> procedure)
          Apply the specified procedure to each node value in this graph accepted by the specified predicate.
 void forEachNodeValue(UnaryProcedure<? super N> procedure)
          Apply the specified procedure to each node value in this graph.
protected  Graph<N,E> getGraph()
          Return a reference to the graph this decorator decorates.
 boolean isEmpty()
          Return true if this graph is empty.
 int nodeCount()
          Return the number of nodes in this graph.
<T> Map<Node<N,E>,T>
nodeMap(T defaultValue)
          Return a map of type <Node<N, E>, T> with the nodes in this graph as keys.
 Set<Node<N,E>> nodes()
          Return a read-only set view of the nodes in this graph.
 Collection<N> nodeValues()
          Return a read-only collection view of the node values in this graph.
 void remove(Edge<N,E> edge)
          Remove the specified edge from this graph (optional operation).
 void remove(Node<N,E> node)
          Remove the specified node and any edges connecting the node from this graph (optional operation).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractGraphDecorator

protected AbstractGraphDecorator(Graph<N,E> graph)
Create a new abstract graph that decorates the specified graph.

Parameters:
graph - graph to decorate, must not be null
Method Detail

getGraph

protected final Graph<N,E> getGraph()
Return a reference to the graph this decorator decorates.

Returns:
a reference to the graph this decorator decorates

isEmpty

public boolean isEmpty()
Return true if this graph is empty.

Specified by:
isEmpty in interface Graph<N,E>
Returns:
true if this graph is empty

nodeCount

public int nodeCount()
Return the number of nodes in this graph.

Specified by:
nodeCount in interface Graph<N,E>
Returns:
the number of nodes in this graph

nodes

public Set<Node<N,E>> nodes()
Return a read-only set view of the nodes in this graph. The view may be empty (if nodeCount() == 0) but will not be null.

Specified by:
nodes in interface Graph<N,E>
Returns:
a read-only set view of the nodes in this graph

nodeValues

public Collection<N> nodeValues()
Return a read-only collection view of the node values in this graph. The view may be empty (if nodeCount() == 0) but will not be null.

Specified by:
nodeValues in interface Graph<N,E>
Returns:
a read-only collection view of the node values in this graph

nodeMap

public <T> Map<Node<N,E>,T> nodeMap(T defaultValue)
Return a map of type <Node<N, E>, T> with the nodes in this graph as keys. The keys in the returned map reference the nodes in this graph and are read-only. Each key maps to the specified default value, which may be null. The map may be empty (if nodeCount() == 0) but will not be null.

Specified by:
nodeMap in interface Graph<N,E>
Type Parameters:
T - node map value type
Parameters:
defaultValue - default value for each node mapping
Returns:
a map of type <Node<N, E>, T> with the nodes in this graph as keys

forEachNode

public void forEachNode(UnaryProcedure<Node<N,E>> procedure)
Apply the specified procedure to each node in this graph.

Specified by:
forEachNode in interface Graph<N,E>
Parameters:
procedure - procedure to apply, must not be null

forEachNode

public void forEachNode(UnaryPredicate<Node<N,E>> predicate,
                        UnaryProcedure<Node<N,E>> procedure)
Apply the specified procedure to each node in this graph accepted by the specified predicate.

Specified by:
forEachNode in interface Graph<N,E>
Parameters:
predicate - node predicate, must not be null
procedure - procedure to apply, must not be null

forEachNodeValue

public void forEachNodeValue(UnaryProcedure<? super N> procedure)
Apply the specified procedure to each node value in this graph.

Specified by:
forEachNodeValue in interface Graph<N,E>
Parameters:
procedure - procedure to apply, must not be null

forEachNodeValue

public void forEachNodeValue(UnaryPredicate<N> predicate,
                             UnaryProcedure<N> procedure)
Apply the specified procedure to each node value in this graph accepted by the specified predicate.

Specified by:
forEachNodeValue in interface Graph<N,E>
Parameters:
predicate - node value predicate, must not be null
procedure - procedure to apply, must not be null

edgeCount

public int edgeCount()
Return the number of edges in this graph.

Specified by:
edgeCount in interface Graph<N,E>
Returns:
the number of edges in this graph

edges

public Set<Edge<N,E>> edges()
Return a read-only set view of the edges in this graph. The view may be empty (if edgeCount() == 0) but will not be null.

Specified by:
edges in interface Graph<N,E>
Returns:
a read-only set view of the edges in this graph

edgeValues

public Collection<E> edgeValues()
Return a read-only collection view of the edge values in this graph. The view may be empty (if edgeCount() == 0) but will not be null.

Specified by:
edgeValues in interface Graph<N,E>
Returns:
a read-only collection view of the edge values in this graph

edgeMap

public <T> Map<Edge<N,E>,T> edgeMap(T defaultValue)
Return a map of type <Edge<N, E>, T> with the edges in this graph as keys. The keys in the returned map reference the edges in this graph and are read-only. Each key maps to the specified default value, which may be null. The map may be empty (if edgeCount() == 0) but will not be null.

Specified by:
edgeMap in interface Graph<N,E>
Type Parameters:
T - edge map value type
Parameters:
defaultValue - default value for each edge mapping
Returns:
a map of type <Edge<N, E>, T> with the edges in this graph as keys

forEachEdge

public void forEachEdge(UnaryProcedure<Edge<N,E>> procedure)
Apply the specified procedure to each edge in this graph.

Specified by:
forEachEdge in interface Graph<N,E>
Parameters:
procedure - procedure to apply, must not be null

forEachEdge

public void forEachEdge(UnaryPredicate<Edge<N,E>> predicate,
                        UnaryProcedure<Edge<N,E>> procedure)
Apply the specified procedure to each edge in this graph accepted by the specified predicate.

Specified by:
forEachEdge in interface Graph<N,E>
Parameters:
predicate - edge predicate, must not be null
procedure - procedure to apply, must not be null

forEachEdgeValue

public void forEachEdgeValue(UnaryProcedure<? super E> procedure)
Apply the specified procedure to each edge value in this graph.

Specified by:
forEachEdgeValue in interface Graph<N,E>
Parameters:
procedure - procedure to apply, must not be null

forEachEdgeValue

public void forEachEdgeValue(UnaryPredicate<E> predicate,
                             UnaryProcedure<E> procedure)
Apply the specified procedure to each edge value in this graph accepted by the specified predicate.

Specified by:
forEachEdgeValue in interface Graph<N,E>
Parameters:
predicate - edge value predicate, must not be null
procedure - procedure to apply, must not be null

clear

public void clear()
Clear the nodes and edges in this graph (optional operation).

Specified by:
clear in interface Graph<N,E>

createNode

public Node<N,E> createNode(N value)
Create and return a new node in this graph with the specified value (optional operation).

Specified by:
createNode in interface Graph<N,E>
Parameters:
value - value
Returns:
a new node in this graph with the specified value

remove

public void remove(Node<N,E> node)
Remove the specified node and any edges connecting the node from this graph (optional operation).

Specified by:
remove in interface Graph<N,E>
Parameters:
node - node to remove, must not be null and must be contained in this graph

createEdge

public Edge<N,E> createEdge(Node<N,E> source,
                            Node<N,E> target,
                            E value)
Create and return a new edge in this graph with the specified value connecting the specified source and target nodes (optional operation).

Specified by:
createEdge in interface Graph<N,E>
Parameters:
source - source node, must not be null and must be contained in this graph
target - target node, must not be null and must be contained in this graph
value - value
Returns:
a new edge in this graph with the specified value connecting the specified source and target nodes

remove

public void remove(Edge<N,E> edge)
Remove the specified edge from this graph (optional operation).

Specified by:
remove in interface Graph<N,E>
Parameters:
edge - edge to remove, must not be null and must be contained in this graph


Copyright (c) 2004-2012 held jointly by the individual authors. Licensed under the GNU Lesser General Public License (LGPL).