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
  • Constructor Details

  • Method Details

    • 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 - When node is null or 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 - When node is null or 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 - When edge is null or is already contained in this graph, or edge source 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 - When edge is null or is not contained in this graph.
      cdc.util.lang.InvalidStateException - When this graph is locked.
    • removeEdges

      public void removeEdges(Collection<? extends E> edges)
    • getNodes

      public final Set<N> getNodes()
      Specified by:
      getNodes in interface GraphAdapter<N,E extends GraphEdge<N>>
    • containsNode

      public final boolean containsNode(N node)
      Specified by:
      containsNode in interface GraphAdapter<N,E extends GraphEdge<N>>
    • getEdges

      public final Set<E> getEdges()
      Specified by:
      getEdges in interface GraphAdapter<N,E extends GraphEdge<N>>
    • containsEdge

      public final boolean containsEdge(E edge)
      Specified by:
      containsEdge in interface GraphAdapter<N,E extends GraphEdge<N>>
    • containsEdge

      public boolean containsEdge(N source, N target)
      Return true if 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:
      true if this graph contains at least one edge between source and target.
    • getEdges

      public final Iterable<? extends E> getEdges(N node, EdgeDirection direction)
      Specified by:
      getEdges in interface GraphAdapter<N,E extends GraphEdge<N>>
    • getTip

      public final N getTip(E edge, EdgeTip tip)
      Specified by:
      getTip in interface GraphAdapter<N,E extends GraphEdge<N>>