Package cdc.graphs.impl
Class BasicLightGraph<N,E extends GraphEdge<N>>
- java.lang.Object
-
- cdc.graphs.impl.BasicLightGraph<N,E>
-
- Type Parameters:
N- Node type.E- Edge type.
- All Implemented Interfaces:
GraphAdapter<N,E>
- Direct Known Subclasses:
BasicSuperLightGraph,TestLightGraph
public class BasicLightGraph<N,E extends GraphEdge<N>> extends Object implements GraphAdapter<N,E>
Basic and naive graph implementation using light nodes.Node can be any object.
- Author:
- Damien Carbonne
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBasicLightGraph.CollectionKind
-
Constructor Summary
Constructors Constructor Description BasicLightGraph()BasicLightGraph(boolean sorted, BasicLightGraph.CollectionKind collectionKind)BasicLightGraph(BasicLightGraph.CollectionKind collectionKind)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <X extends E>
XaddEdge(X edge)Adds an edge to this graph.<X extends E>
voidaddEdgeIfMissing(X edge)Adds an edge if not already contained.voidaddEdges(Collection<? extends E> edges)voidaddEdgesIfMissing(Collection<? extends E> edges)<X extends N>
XaddNode(X node)Adds a node to this graph.<X extends N>
voidaddNodeIfMissing(X node)Ads a node if not already contained.voidaddNodes(Collection<? extends N> nodes)voidaddNodesIfMissing(Collection<? extends N> nodes)voidclear()Clears this graph.voidclearEdges()Clears all edges of this graph.booleancontainsEdge(E edge)booleancontainsEdge(N source, N target)Returntrueif this graph contains at least one edge between a source node and a target node.booleancontainsNode(N node)Set<E>getEdges()Iterable<? extends E>getEdges(N node, EdgeDirection direction)Set<N>getNodes()NgetTip(E edge, EdgeTip tip)booleanisLocked()voidremoveEdge(E edge)Removes an edge from this graph.voidremoveEdges(Collection<? extends E> edges)voidremoveNode(N node)Remove a node from this graph.voidremoveNodes(Collection<? extends N> nodes)voidsetChecksEnabled(boolean enabled)voidsetLocked(boolean locked)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface cdc.graphs.GraphAdapter
getConnectedNodes, getConnectedNodes, getConnectivity, getEdges, getEdges, getEdges, getEdges, getEdgesCount, getEdgesCount, getEdgesCount, getEdgesStream, getEdgesStream, getEdgesStream, getLeaves, getNodes, getNodesCount, getNodesStream, getRoots, hasEdge, hasEdges, hasEdges, hasEdges, hasNodes, isLeaf, isRoot
-
-
-
-
Constructor Detail
-
BasicLightGraph
public BasicLightGraph(boolean sorted, BasicLightGraph.CollectionKind collectionKind)
-
BasicLightGraph
public BasicLightGraph(BasicLightGraph.CollectionKind collectionKind)
-
BasicLightGraph
public BasicLightGraph()
-
-
Method Detail
-
setChecksEnabled
public void setChecksEnabled(boolean enabled)
-
setLocked
public void setLocked(boolean locked)
-
isLocked
public boolean isLocked()
-
clear
public void clear()
Clears this graph.- Throws:
cdc.util.lang.InvalidStateException- When this graph is locked.
-
clearEdges
public void clearEdges()
Clears all edges of this graph.- Throws:
cdc.util.lang.InvalidStateException- When this graph is locked.
-
addNode
public <X extends N> X addNode(X node)
Adds a node to this graph.- Type Parameters:
X- The node type.- Parameters:
node- The node.- Returns:
- The passed
node. - Throws:
IllegalArgumentException- Whennodeisnullor is already contained in this graph.cdc.util.lang.InvalidStateException- When this graph is locked.
-
addNodes
public void addNodes(Collection<? extends N> nodes)
-
addNodeIfMissing
public <X extends N> void addNodeIfMissing(X node)
Ads a node if not already contained.- Type Parameters:
X- The node type.- Parameters:
node- The node.
-
addNodesIfMissing
public void addNodesIfMissing(Collection<? extends N> nodes)
-
removeNode
public void removeNode(N node)
Remove a node from this graph.- Parameters:
node- The node.- Throws:
IllegalArgumentException- Whennodeisnullor is not contained in this graph.cdc.util.lang.InvalidStateException- When this graph is locked.
-
removeNodes
public void removeNodes(Collection<? extends N> nodes)
-
addEdge
public <X extends E> X addEdge(X edge)
Adds an edge to this graph.- Type Parameters:
X- The edge type.- Parameters:
edge- The edge.- Returns:
- The passed
edge. - Throws:
IllegalArgumentException- Whenedgeisnullor is already contained in this graph, oredgesource or target don't not belong to this graph.cdc.util.lang.InvalidStateException- When this graph is locked.
-
addEdges
public void addEdges(Collection<? extends E> edges)
-
addEdgeIfMissing
public <X extends E> void addEdgeIfMissing(X edge)
Adds an edge if not already contained.- Type Parameters:
X- The edge type.- Parameters:
edge- The edge.
-
addEdgesIfMissing
public void addEdgesIfMissing(Collection<? extends E> edges)
-
removeEdge
public void removeEdge(E edge)
Removes an edge from this graph.- Parameters:
edge- The edge.- Throws:
IllegalArgumentException- Whenedgeisnullor is not contained in this graph.cdc.util.lang.InvalidStateException- When this graph is locked.
-
removeEdges
public void removeEdges(Collection<? extends E> edges)
-
containsNode
public final boolean containsNode(N node)
- Specified by:
containsNodein interfaceGraphAdapter<N,E extends GraphEdge<N>>
-
containsEdge
public final boolean containsEdge(E edge)
- Specified by:
containsEdgein interfaceGraphAdapter<N,E extends GraphEdge<N>>
-
containsEdge
public boolean containsEdge(N source, N target)
Returntrueif this graph contains at least one edge between a source node and a target node.- Parameters:
source- The source node.target- The target node.- Returns:
trueif this graph contains at least one edge betweensourceandtarget.
-
getEdges
public final Iterable<? extends E> getEdges(N node, EdgeDirection direction)
-
-