Package cdc.graphs

Interface GraphAdapter<N,​E>

  • Type Parameters:
    N - Node class.
    E - Edge class.

    public interface GraphAdapter<N,​E>
    Interface giving access to a heavy graph, where nodes and edges are represented as objects.

    Graph algorithms can be built using this interface without forcing a graph implementation to implement this interface.

    Author:
    Damien Carbonne
    • Method Detail

      • getNodes

        Iterable<? extends N> getNodes()
        Returns:
        an Iterable of all nodes.
      • getNodesStream

        default Stream<? extends N> getNodesStream()
      • getNodes

        default Iterable<? extends N> getNodes​(Predicate<? super N> predicate)
        Return an Iterable of all nodes that match a predicate.
        Parameters:
        predicate - The predicate.
        Returns:
        an Iterable of all nodes that match predicate.
      • getNodesCount

        default int getNodesCount()
        Returns:
        The number of nodes in the graph.
      • hasNodes

        default boolean hasNodes()
        Returns:
        true if the graph has nodes.
      • containsNode

        boolean containsNode​(N node)
        Returns true if a node belongs to this graph.
        Parameters:
        node - The node.
        Returns:
        true if node is member of this graph.
      • getEdges

        Iterable<? extends E> getEdges()
        Returns:
        an Iterable of all edges.
      • getEdgesStream

        default Stream<? extends E> getEdgesStream()
      • getEdges

        default Iterable<? extends E> getEdges​(Predicate<? super E> predicate)
        Parameters:
        predicate - The predicate.
        Returns:
        an Iterable of all edges that match predicate.
      • getEdgesCount

        default int getEdgesCount()
        Returns:
        The number of edges in the graph.
      • hasEdges

        default boolean hasEdges()
        Returns:
        true if the graph has edges.
      • containsEdge

        boolean containsEdge​(E edge)
        Returns true if an edge belongs to this graph.
        Parameters:
        edge - The edge.
        Returns:
        true if edge is member of graph.
      • getEdges

        Iterable<? extends E> getEdges​(N node,
                                       EdgeDirection direction)
        Returns an Iterable of edges attached to a node in a given direction.
        Parameters:
        node - The node. MUST NOT be null.
        direction - The direction. MAY be null. If null, then all edges are returned.
        Returns:
        An Iterable of edges attached to node in direction.
      • getEdges

        default Iterable<? extends E> getEdges​(N node,
                                               EdgeDirection direction,
                                               Predicate<? super E> predicate)
        Returns an Iterable of edges attached to a node in a given direction and matching a predicate.
        Parameters:
        node - The node. MUST NOT be null.
        direction - The direction. MAY be null. If null, then all edges are returned.
        predicate - The predicate to filter edges.
        Returns:
        An Iterable of edges attached to node in direction and matching predicate.
      • getConnectedNodes

        default Set<N> getConnectedNodes​(N node,
                                         EdgeDirection direction)
        Returns an Iterable of edges attached to a node in a given direction.
        Parameters:
        node - The node. MUST NOT be null.
        direction - The direction. MAY be null.
        Returns:
        A set of all nodes connected to node in direction.
      • getConnectedNodes

        default Set<N> getConnectedNodes​(N node)
        Returns a set of all nodes that are connected to a node.
        Parameters:
        node - The node.
        Returns:
        A set of all nodes that are connected to node.
      • getEdges

        default Iterable<? extends E> getEdges​(N node)
        Parameters:
        node - The node.
        Returns:
        An Iterable of all edges attached to node.
      • getEdges

        default Iterable<? extends E> getEdges​(N node,
                                               Predicate<? super E> predicate)
        Parameters:
        node - The node.
        predicate - The predicate.
        Returns:
        An Iterable of all edges attached to node and that match predicate.
      • getEdgesStream

        default Stream<? extends E> getEdgesStream​(N node)
      • getEdgesCount

        default int getEdgesCount​(N node,
                                  EdgeDirection direction)
        Returns the number of edges attached to a node, in one or any direction.
        Parameters:
        node - The node.
        direction - The optional direction. MAY be null to indicate that direction does not matter.
        Returns:
        The number of edges attached to node, in one (if not null) or any (if null) direction.
      • getEdgesCount

        default int getEdgesCount​(N node)
        Returns the number of edges attached to a node, in any direction.
        Parameters:
        node - The node.
        Returns:
        The number of edges attached to node, in any direction.
      • hasEdges

        default boolean hasEdges​(N node,
                                 EdgeDirection direction)
        Returns true when there are edges attached to a node, in one or any direction.
        Parameters:
        node - The node.
        direction - The optional direction. MAY be null to indicate that direction does not matter.
        Returns:
        true when there are edges attached to node, in one (if not null) or any (if null) direction.
      • hasEdges

        default boolean hasEdges​(N node)
        Returns true when there are edges attached to a node, in any direction.
        Parameters:
        node - The node.
        Returns:
        true when there are edges attached to node, in any direction.
      • getTip

        N getTip​(E edge,
                 EdgeTip tip)
        Returns a tip of an edge.
        Parameters:
        edge - The edge. MUST NOT be null.
        tip - The tip. MUST NOT be null.
        Returns:
        The node attached to edge for tip.
      • isRoot

        default boolean isRoot​(N node)
        Returns true when a node is a root: It has no ingoing edges.
        Parameters:
        node - The node.
        Returns:
        true when node is a root.
      • isLeaf

        default boolean isLeaf​(N node)
        Return true if a node is a leaf: It has no outgoing edges.
        Parameters:
        node - The node.
        Returns:
        true when node is a leaf.
      • getRoots

        default Set<N> getRoots()
        Returns:
        A Set of all root nodes.
      • getLeaves

        default Set<N> getLeaves()
        Returns:
        A Set of all leaf nodes.
      • getConnectivity

        default NodeConnectivity getConnectivity​(N node)
        Returns the connectivity of a node.
        Parameters:
        node - The node
        Returns:
        The connectivity of node.
      • hasEdge

        default boolean hasEdge​(N source,
                                N target)
        Returns true when there is an edge between a source node and target node.

        WARNING: order of passed arguments matters.

        Parameters:
        source - The source node.
        target - The target node.
        Returns:
        true when there is an edge between source and target.