Interface IGraph<E>

Type Parameters:
E - The type of the graph nodes
All Known Implementing Classes:
Graph

public interface IGraph<E>
Interface of a directed graph.
Since:
3.3
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    add(E element)
    Adds a new element to this graph, if it does not exists yet.
    void
    addChildren(E element, Set<E> newChildren)
    Connects the given set of elements to a given parent.
    void
    addParentData(E element, E parentData)
    Set the parent data for the given element.
    Returns a breadth-first iterator over this whole graph.
    void
    Clears this graph and goes back to a pristine state.
    boolean
    contains(E element)
    Checks whether this graph already contains the given element.
    Returns a depth first iterator created with the given element as root.
    Returns the direct parents of the given element.
    getParentData(E element)
    Get the parent data of the given element.
    Returns the set of all elements of the subgraph containing the given element.
    getSubgraphContaining(E element, Set<E> endPoints)
    Returns the set of all elements of the subgraph containing the given element and ending at the given boundaries.
    getTreeFrom(E root)
    Returns the tree starting from the given root element if it is contained in the graph.
    getTreeFrom(E root, Set<E> endPoints)
    Returns the tree starting from the given root element and ending at the given boundaries..
    boolean
    hasChild(E parent, E potentialChild)
    Checks if the given element is a parent of the given potential child, directly or not.
    void
    remove(E element)
    Removes the given element's node from this graph.
    void
    removeAll(Collection<E> elements)
    Removes the given elements' nodes from this graph.
  • Method Details

    • contains

      boolean contains(E element)
      Checks whether this graph already contains the given element.
      Parameters:
      element - Element we need to check.
      Returns:
      true if this graph already contains the given elment, false otherwise.
    • clear

      void clear()
      Clears this graph and goes back to a pristine state.
    • add

      boolean add(E element)
      Adds a new element to this graph, if it does not exists yet. Elements will initially have no connection to other elements, and can thus be considered "roots" of the graph.
      Parameters:
      element - The element to add as a new root to this graph.
      Returns:
      true if this element did not previously exist in the graph.
    • remove

      void remove(E element)
      Removes the given element's node from this graph. This will effectively break all connections to that node.
      Parameters:
      element - The element which is to be removed from this graph.
    • removeAll

      void removeAll(Collection<E> elements)
      Removes the given elements' nodes from this graph. This will effectively break all connections to these nodes.
      Parameters:
      elements - The elements which are to be removed from this graph.
    • addChildren

      void addChildren(E element, Set<E> newChildren)
      Connects the given set of elements to a given parent. Note that nodes will be created for all new elements if they do not exist yet.
      Parameters:
      element - The element that is to be connected with new children.
      newChildren - The set of elements to connect to the given parent.
    • hasChild

      boolean hasChild(E parent, E potentialChild)
      Checks if the given element is a parent of the given potential child, directly or not.
      Parameters:
      parent - Element that could be a parent of potentialChild.
      potentialChild - The potential child of parent.
      Returns:
      true if parent is an ancestor of potentialChild.
    • getDirectParents

      Set<E> getDirectParents(E element)
      Returns the direct parents of the given element.

      Note that the returned set is a view over a sub-graph of this graph, and that changes to it will not be reflected within the graph itself.

      Parameters:
      element - The element which parents we seek.
      Returns:
      The set of direct parents for the given element.
    • getTreeFrom

      Set<E> getTreeFrom(E root)
      Returns the tree starting from the given root element if it is contained in the graph.

      Contrarily to getSubgraphContaining(Object), this will only iterate over the children (and recursively) of the given node, without ever "going up" to parents of these children.

      Note that the returned set is a view over a sub-graph of this graph, and that changes to it will not be reflected within the graph itself.

      Parameters:
      root - The element we are to consider as the root of a tree.
      Returns:
      The tree starting from the given root element if it is contained in this graph, and empty set otherwise.
    • getTreeFrom

      Set<E> getTreeFrom(E root, Set<E> endPoints)
      Returns the tree starting from the given root element and ending at the given boundaries..

      Contrarily to getSubgraphContaining(Object, Set), this will only iterate over the children (and recursively) of the given node, without ever "going up" to parents of these children.

      Note that the returned set is a view over a sub-graph of this graph, and that changes to it will not be reflected within the graph itself.

      Parameters:
      root - The element we are to consider as the root of a tree.
      endPoints - Boundaries of the tree.
      Returns:
      The tree starting from the given root element if it is contained in this graph, and empty set otherwise.
    • getSubgraphContaining

      Set<E> getSubgraphContaining(E element)
      Returns the set of all elements of the subgraph containing the given element.

      Note that the returned set is a view over a sub-graph of this graph, and that changes to it will not be reflected within the graph itself.

      Parameters:
      element - Element we need the subgraph of.
      Returns:
      The set of all elements of the subgraph containing the given element, an empty set if that element is not present in this graph.
    • getSubgraphContaining

      Set<E> getSubgraphContaining(E element, Set<E> endPoints)
      Returns the set of all elements of the subgraph containing the given element and ending at the given boundaries.

      Note that the returned set is a view over a sub-graph of this graph, and that changes to it will not be reflected within the graph itself.

      Parameters:
      element - Element we need the subgraph of.
      endPoints - Boundaries of the needed subgraph.
      Returns:
      An iterable over all elements of the subgraph containing the given element, an empty set if that element is not present in this graph.
    • breadthFirstIterator

      PruningIterator<E> breadthFirstIterator()
      Returns a breadth-first iterator over this whole graph. This will begin iteration on this graph's roots (whether they are linked together (directly or indirectly) or not), then carry on over each depth level. This will never visit the same element twice, nor will it ever visit an element which parents haven't all been iterated over yet.

      The returned iterator does not support removal, and will fail or return undefined results if this graph is modified after the iterator's creation.

      Returns:
      A breadth-first iterator over this whole graph.
    • depthFirstIterator

      Iterator<E> depthFirstIterator(E root)
      Returns a depth first iterator created with the given element as root. If the graph contains cycles, the same node won't be returned twice.

      The root will be returned first, then the left-most child of that root, then the left-most child of that child if any, or the closest sibling to the right of the current element. For example, with the following tree:

           A
          / \
         B   C
        /   / \
       D   E   F
       
      The iteration order will be : A, B, D, C, E, F.

      The returned iterator does not support removal, and will fail or return undefined results if this graph is modified after the iterator's creation.

      Parameters:
      root - The root of the tree over which we need to iterate.
      Returns:
      An iterator over the tree starting from the given root.
    • getParentData

      E getParentData(E element)
      Get the parent data of the given element.

      The parent data, is the URI of the parent resource's object in case of a containment relationship between the given element and its parent.

      Parameters:
      element - Element we need the parent data of.
      Returns:
      A parent data of type E if this element has a parent data, null otherwise.
    • addParentData

      void addParentData(E element, E parentData)
      Set the parent data for the given element.

      The parent data, is the URI of the parent resource's object in case of a containment relationship between the given element and its parent.

      If the given element has several parents, then the addition of a new parent data results in delete the parent data. If the given element has no parents, then the addition of a new parent data results in delete the parent data.
      Parameters:
      element - Element for which we need to set the parent data.
      parentData - The parent data to set.