Class ReadOnlyGraph<E>

java.lang.Object
org.eclipse.emf.compare.internal.utils.ReadOnlyGraph<E>
Type Parameters:
E - Kind of elements used as this graph's nodes.
All Implemented Interfaces:
IGraphView<E>

public final class ReadOnlyGraph<E> extends Object implements IGraphView<E>
Read-only version of an already existing Graph.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns a breadth-first iterator over this whole graph.
    boolean
    contains(E element)
    Checks whether this graph already contains the given element.
    com.google.common.collect.ImmutableSet<E>
    Returns the direct parents of the given element.
    getParentData(E element)
    Get the parent data of the given element.
    com.google.common.collect.ImmutableSet<E>
    Returns the set of all elements of the subgraph containing the given element.
    com.google.common.collect.ImmutableSet<E>
    getSubgraphContaining(E element, com.google.common.collect.ImmutableSet<E> endPoints)
    Returns the set of all elements of the subgraph containing the given element and ending at the given boundaries.
    com.google.common.collect.ImmutableSet<E>
    getTreeFrom(E root)
    Returns the tree starting from the given root element if it is contained in the graph.
    com.google.common.collect.ImmutableSet<E>
    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.
    static <E> ReadOnlyGraph<E>
    Convert a graph to a read-only graph.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • toReadOnlyGraph

      public static <E> ReadOnlyGraph<E> toReadOnlyGraph(IGraph<E> graph)
      Convert a graph to a read-only graph.
      Type Parameters:
      E - Kind of elements used as this graph's nodes.
      Parameters:
      graph - The writable graph to convert.
      Returns:
      a read-only graph version of the given graph.
    • contains

      public boolean contains(E element)
      Checks whether this graph already contains the given element.
      Specified by:
      contains in interface IGraphView<E>
      Parameters:
      element - Element we need to check.
      Returns:
      true if this graph already contains the given elment, false otherwise.
      See Also:
    • hasChild

      public boolean hasChild(E parent, E potentialChild)
      Checks if the given element is a parent of the given potential child, directly or not.
      Specified by:
      hasChild in interface IGraphView<E>
      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.
      See Also:
    • getDirectParents

      public com.google.common.collect.ImmutableSet<E> getDirectParents(E element)
      Returns the direct parents of the given element.

      Note that the returned set is an immutable view over a sub-graph of this graph.

      Specified by:
      getDirectParents in interface IGraphView<E>
      Parameters:
      element - The element which parents we seek.
      Returns:
      An immutable set of direct parents for the given element.
      See Also:
    • getParentData

      public E getParentData(E element)
      Get the parent data of the given element. If the given element has several parents, then this method will return null. If the given element has no parents, then then this method will return null
      Specified by:
      getParentData in interface IGraphView<E>
      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.
      See Also:
    • getSubgraphContaining

      public com.google.common.collect.ImmutableSet<E> getSubgraphContaining(E element)
      Returns the set of all elements of the subgraph containing the given element.

      Note that the returned set is an immutable view over a sub-graph of this graph.

      Specified by:
      getSubgraphContaining in interface IGraphView<E>
      Parameters:
      element - Element we need the subgraph of.
      Returns:
      An immutable set of all elements of the subgraph containing the given element, an empty immutable set if that element is not present in this graph.
      See Also:
    • getSubgraphContaining

      public com.google.common.collect.ImmutableSet<E> getSubgraphContaining(E element, com.google.common.collect.ImmutableSet<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 an immutable view over a sub-graph of this graph.

      Specified by:
      getSubgraphContaining in interface IGraphView<E>
      Parameters:
      element - Element we need the subgraph of.
      endPoints - Boundaries of the needed subgraph.
      Returns:
      An immutable set over all elements of the subgraph containing the given element, an immutable empty set if that element is not present in this graph.
      See Also:
    • getTreeFrom

      public com.google.common.collect.ImmutableSet<E> getTreeFrom(E root)
      Returns the tree starting from the given root element if it is contained in the graph.

      Contrarily to IGraphView.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 an immutable view over a sub-graph of this graph.

      Specified by:
      getTreeFrom in interface IGraphView<E>
      Parameters:
      root - The element we are to consider as the root of a tree.
      Returns:
      The immutable tree starting from the given root element if it is contained in this graph, and immutable empty set otherwise.
      See Also:
    • getTreeFrom

      public com.google.common.collect.ImmutableSet<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 an immutable view over a sub-graph of this graph.

      Specified by:
      getTreeFrom in interface IGraphView<E>
      Parameters:
      root - The element we are to consider as the root of a tree.
      endPoints - Boundaries of the tree.
      Returns:
      The immutable tree starting from the given root element if it is contained in this graph, and immutable empty set otherwise.
      See Also:
    • breadthFirstIterator

      public 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 returned undefined results if this graph is modified after the iterator's creation.

      Specified by:
      breadthFirstIterator in interface IGraphView<E>
      Returns:
      A breadth-first iterator over this whole graph.
      See Also: