com.kuka.graph.impl
Class AbstractGraph<N,E>

java.lang.Object
  extended by com.kuka.graph.impl.AbstractGraph<N,E>
Type Parameters:
N - the node type.
E - the edge type.
All Implemented Interfaces:
Graph<N,E>, Iterable<N>
Direct Known Subclasses:
AbstractBaseGraph, FastUncheckedGraph, TransposeGraph

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

Abstract superclass for all graphs, implementing base functionality common to all graphs.


Constructor Summary
AbstractGraph()
           
 
Method Summary
 boolean addAllEdges(Collection<E> edges)
          Adds all of the edges in the specified collection to this graph if they are not already present (optional operation).
 boolean addAllNodes(Collection<N> nodes)
          Adds all of the nodes in the specified collection to this graph if they are not already present (optional operation).
 void clear()
          Removes all nodes and all edges from this graph (optional operation).
 boolean containsAllEdges(Collection<E> edges)
          Returns true if this graph contains all of the edges of the specified collection.
 boolean containsAllNodes(Collection<N> nodes)
          Returns true if this graph contains all of the nodes of the specified collection.
 boolean containsEdge(N source, N target)
          Returns true if this graph contains the specified edge e=(source,target).
 Set<E> edges(GraphElementFilter<? super E> filter)
          Returns an unmodifiable Set view of the edges contained in this graph that satisfy the specified filter.
 int edgeSize()
          Returns the number of edges in this graph, i.e. the cardinality of the set of edges.
 boolean isEmpty()
          Returns true if this graph contains no elements.
 Iterator<N> iterator()
           
 Set<N> nodes(GraphElementFilter<? super N> filter)
          Returns an unmodifiable Set view of the nodes contained in this graph that satisfy the specified filter.
 int nodeSize()
          Returns the number of nodes in this graph, i.e. the cardinality of the set of nodes.
 boolean removeAllEdges(Collection<E> edges)
          Removes from this graph all of its edges that are contained in the specified collection (optional operation).
 boolean removeAllNodes(Collection<N> nodes)
          Removes from this graph all of its nodes that are contained in the specified collection (optional operation).
 boolean removeEdge(N source, N target)
          Removes the edge e=(source,target) connecting the specified source and target node from this graph if it is present (optional operation).
 boolean retainAllEdges(Collection<E> edges)
          Retains only the edges in this graph that are contained in the specified collection (optional operation).
 boolean retainAllNodes(Collection<N> nodes)
          Retains only the nodes in this graph that are contained in the specified collection (optional operation).
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.kuka.graph.Graph
addEdge, addNode, containsEdge, containsNode, createEdge, createNode, edges, getEdge, incomingEdges, neighbors, nodes, outgoingEdges, removeEdge, removeNode
 

Constructor Detail

AbstractGraph

public AbstractGraph()
Method Detail

iterator

public Iterator<N> iterator()
Specified by:
iterator in interface Iterable<N>

nodeSize

public int nodeSize()
Description copied from interface: Graph
Returns the number of nodes in this graph, i.e. the cardinality of the set of nodes. If this set contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

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

edgeSize

public int edgeSize()
Description copied from interface: Graph
Returns the number of edges in this graph, i.e. the cardinality of the set of edges. If this set contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

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

isEmpty

public boolean isEmpty()
Description copied from interface: Graph
Returns true if this graph contains no elements.

Specified by:
isEmpty in interface Graph<N,E>
Returns:
true if this graph contains no elements

containsEdge

public boolean containsEdge(N source,
                            N target)
Description copied from interface: Graph
Returns true if this graph contains the specified edge e=(source,target). More formally, returns true if and only if this graph contains an edge e* such that e.equals(e*).

Specified by:
containsEdge in interface Graph<N,E>
Parameters:
source - the source node of the edge whose presence in this graph is to be tested
target - the target node of the edge whose presence in this graph is to be tested
Returns:
true if this graph contains the specified edge (source,target)

containsAllNodes

public final boolean containsAllNodes(Collection<N> nodes)
Description copied from interface: Graph
Returns true if this graph contains all of the nodes of the specified collection. If the specified collection is a set, this method returns true if it is a subset of the node set of this graph.

Specified by:
containsAllNodes in interface Graph<N,E>
Parameters:
nodes - collection of nodes to be checked for containment in this graph
Returns:
true if this graph contains all of the nodes of the specified collection
See Also:
Graph.containsNode(Object)

containsAllEdges

public final boolean containsAllEdges(Collection<E> edges)
Description copied from interface: Graph
Returns true if this graph contains all of the edges of the specified collection. If the specified collection is a set, this method returns true if it is a subset of the edge set of this graph.

Specified by:
containsAllEdges in interface Graph<N,E>
Parameters:
edges - collection of edges to be checked for containment in this graph
Returns:
true if this graph contains all of the edges of the specified collection
See Also:
Graph.containsEdge(Object)

nodes

public final Set<N> nodes(GraphElementFilter<? super N> filter)
Description copied from interface: Graph
Returns an unmodifiable Set view of the nodes contained in this graph that satisfy the specified filter. The behavior of this method is the same as that of the Graph.nodes() method, except that the nodes in the returned set must satisfy the filter and the set is not backed by the graph, i.e. changes to the graph are not reflected in the set. If the given filter is null then all nodes are accepted. Otherwise, a node satisfies the filter if and only if the value true results when the GraphElementFilter.accept(E) method of the filter is invoked on the node.

Specified by:
nodes in interface Graph<N,E>
Parameters:
filter - a node filter
Returns:
a set view of the nodes contained in this graph that satisfy the specified filter

edges

public final Set<E> edges(GraphElementFilter<? super E> filter)
Description copied from interface: Graph
Returns an unmodifiable Set view of the edges contained in this graph that satisfy the specified filter. The behavior of this method is the same as that of the Graph.edges() method, except that the edges in the returned set must satisfy the filter and the set is not backed by the graph, i.e. changes to the graph are not reflected in the set. If the given filter is null then all edges are accepted. Otherwise, an edge satisfies the filter if and only if the value true results when the GraphElementFilter.accept(E) method of the filter is invoked on the edge.

Specified by:
edges in interface Graph<N,E>
Parameters:
filter - an edge filter
Returns:
a set view of the edges contained in this graph that satisfy the specified filter

addAllNodes

public final boolean addAllNodes(Collection<N> nodes)
Description copied from interface: Graph
Adds all of the nodes in the specified collection to this graph if they are not already present (optional operation).

If the specified collection is a set, the addAllNodes operation effectively modifies the set of nodes so that its value is the union of the two sets. The behavior of this operation is undefined if the specified collection is modified while the operation is in progress.

Specified by:
addAllNodes in interface Graph<N,E>
Parameters:
nodes - collection containing nodes to be added to this graph
Returns:
true if this graph changed as a result of the call
See Also:
Graph.addNode(Object)

addAllEdges

public final boolean addAllEdges(Collection<E> edges)
Description copied from interface: Graph
Adds all of the edges in the specified collection to this graph if they are not already present (optional operation).

If the specified collection is a set, the addAllEdges operation effectively modifies the set of edges so that its value is the union of the two sets. The behavior of this operation is undefined if the specified collection is modified while the operation is in progress.

Specified by:
addAllEdges in interface Graph<N,E>
Parameters:
edges - collection containing edges to be added to this graph
Returns:
true if this graph changed as a result of the call
See Also:
Graph.addEdge(Object)

removeEdge

public final boolean removeEdge(N source,
                                N target)
Description copied from interface: Graph
Removes the edge e=(source,target) connecting the specified source and target node from this graph if it is present (optional operation).

More formally, removes an edge e* such that e.equals(e*), where e=(source,target), if this graph contains such an edge. Returns true if this graph contained the edge (or equivalently, if this graph changed as a result of the call).

Specified by:
removeEdge in interface Graph<N,E>
Parameters:
source - the source node of the edge that is to be removed
target - the target node of the edge that is to be removed
Returns:
true if this graph contained the specified edge

removeAllNodes

public final boolean removeAllNodes(Collection<N> nodes)
Description copied from interface: Graph
Removes from this graph all of its nodes that are contained in the specified collection (optional operation).

If the specified collection is a set, this operation effectively modifies the set of nodes so that its value is the asymmetric set difference of the two sets.

Specified by:
removeAllNodes in interface Graph<N,E>
Parameters:
nodes - collection containing nodes to be removed from this graph
Returns:
true if this graph changed as a result of the call
See Also:
Graph.removeNode(Object)

removeAllEdges

public final boolean removeAllEdges(Collection<E> edges)
Description copied from interface: Graph
Removes from this graph all of its edges that are contained in the specified collection (optional operation).

If the specified collection is a set, this operation effectively modifies the set of edges so that its value is the asymmetric set difference of the two sets.

Specified by:
removeAllEdges in interface Graph<N,E>
Parameters:
edges - collection containing edges to be removed from this graph
Returns:
true if this graph changed as a result of the call
See Also:
Graph.removeEdge(Object)

retainAllNodes

public final boolean retainAllNodes(Collection<N> nodes)
Description copied from interface: Graph
Retains only the nodes in this graph that are contained in the specified collection (optional operation).

In other words, removes from this graph all of its nodes that are not contained in the specified collection. If the specified collection is a set, this operation effectively modifies the set of nodes so that its value is the intersection of the two sets.

Specified by:
retainAllNodes in interface Graph<N,E>
Parameters:
nodes - collection containing nodes to be retained in this graph
Returns:
true if this graph changed as a result of the call
See Also:
Graph.removeNode(Object), Graph.removeAllNodes(Collection)

retainAllEdges

public final boolean retainAllEdges(Collection<E> edges)
Description copied from interface: Graph
Retains only the edges in this graph that are contained in the specified collection (optional operation).

In other words, removes from this graph all of its edges that are not contained in the specified collection. If the specified collection is a set, this operation effectively modifies the set of edges so that its value is the intersection of the two sets.

Specified by:
retainAllEdges in interface Graph<N,E>
Parameters:
edges - collection containing edges to be retained in this graph
Returns:
true if this graph changed as a result of the call
See Also:
Graph.removeEdge(Object), Graph.removeAllEdges(Collection)

clear

public final void clear()
Description copied from interface: Graph
Removes all nodes and all edges from this graph (optional operation). The graph will be empty after this call returns.

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

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2019. All rights reserved.