Class BasicLightGraph<N,​E extends GraphEdge<N>>

  • 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
    • 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 - 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)
      • 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.