diff options
Diffstat (limited to 'plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/utils/ReadOnlyGraph.java')
-rw-r--r-- | plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/utils/ReadOnlyGraph.java | 109 |
1 files changed, 26 insertions, 83 deletions
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/utils/ReadOnlyGraph.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/utils/ReadOnlyGraph.java index 3083709b3..c3698c156 100644 --- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/utils/ReadOnlyGraph.java +++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/utils/ReadOnlyGraph.java @@ -14,6 +14,10 @@ import com.google.common.collect.ImmutableSet; import java.util.Set; +import org.eclipse.emf.compare.graph.IGraph; +import org.eclipse.emf.compare.graph.IGraphView; +import org.eclipse.emf.compare.graph.PruningIterator; + /** * Read-only version of an already existing {@link org.eclipse.emf.compare.internal.utils.Graph}. * @@ -21,10 +25,10 @@ import java.util.Set; * Kind of elements used as this graph's nodes. * @author <a href="mailto:axel.richard@obeo.fr">Axel Richard</a> */ -public final class ReadOnlyGraph<E> { +public final class ReadOnlyGraph<E> implements IGraphView<E> { /** The writable graph. */ - private final Graph<E> graph; + private final IGraph<E> graph; /** * Constructor. @@ -32,7 +36,7 @@ public final class ReadOnlyGraph<E> { * @param graph * the graph to convert. */ - private ReadOnlyGraph(Graph<E> graph) { + private ReadOnlyGraph(IGraph<E> graph) { this.graph = graph; } @@ -45,147 +49,86 @@ public final class ReadOnlyGraph<E> { * The writable graph to convert. * @return a read-only graph version of the given graph. */ - public static <E> ReadOnlyGraph<E> toReadOnlyGraph(Graph<E> graph) { + public static <E> ReadOnlyGraph<E> toReadOnlyGraph(IGraph<E> graph) { return new ReadOnlyGraph<E>(graph); } /** - * Checks whether this graph already contains the given element. + * {@inheritDoc} * - * @param element - * Element we need to check. - * @return <code>true</code> if this graph already contains the given elment, <code>false</code> - * otherwise. + * @see org.eclipse.emf.compare.graph.IGraphView#contains(Object) */ public boolean contains(E element) { return graph.contains(element); } /** - * Checks if the given element is a parent of the given potential child, directly or not. + * {@inheritDoc} * - * @param parent - * Element that could be a parent of <code>potentialChild</code>. - * @param potentialChild - * The potential child of <code>parent</code>. - * @return <code>true</code> if <code>parent</code> is an ancestor of <code>potentialChild</code>. + * @see org.eclipse.emf.compare.graph.IGraphView#hasChild(Object, Object) */ public boolean hasChild(E parent, E potentialChild) { return graph.hasChild(parent, potentialChild); } /** - * Returns the <u>direct</u> parents of the given <code>element</code>. - * <p> - * <b>Note</b> that the returned set is an immutable view over a sub-graph of this graph. - * </p> + * {@inheritDoc} * - * @param element - * The element which parents we seek. - * @return An immutable set of <u>direct</u> parents for the given <code>element</code>. + * @see org.eclipse.emf.compare.graph.IGraphView#getDirectParents(Object) */ public ImmutableSet<E> getDirectParents(E element) { return ImmutableSet.copyOf(graph.getDirectParents(element)); } /** - * Get the parent data of the given element. If the given element has several parents, then this method - * will return <code>null</code>. If the given element has no parents, then then this method will return - * <code>null</code> + * {@inheritDoc} * - * @param element - * Element we need the parent data of. - * @return A parent data of type <code>E</code> if this element has a parent data, <code>null</code> - * otherwise. + * @see org.eclipse.emf.compare.graph.IGraphView#getParentData(Object) */ public E getParentData(E element) { return graph.getParentData(element); } /** - * Returns the set of all elements of the subgraph containing the given element. - * <p> - * <b>Note</b> that the returned set is an immutable view over a sub-graph of this graph. - * </p> + * {@inheritDoc} * - * @param element - * Element we need the subgraph of. - * @return 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 org.eclipse.emf.compare.graph.IGraphView#getSubgraphContaining(Object) */ public ImmutableSet<E> getSubgraphContaining(E element) { return getSubgraphContaining(element, ImmutableSet.<E> of()); } /** - * Returns the set of all elements of the subgraph containing the given element and ending at the given - * boundaries. - * <p> - * <b>Note</b> that the returned set is an immutable view over a sub-graph of this graph. - * </p> + * {@inheritDoc} * - * @param element - * Element we need the subgraph of. - * @param endPoints - * Boundaries of the needed subgraph. - * @return 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 org.eclipse.emf.compare.graph.IGraphView#getSubgraphContaining(Object, ImmutableSet) */ public ImmutableSet<E> getSubgraphContaining(E element, ImmutableSet<E> endPoints) { return ImmutableSet.copyOf(graph.getSubgraphContaining(element, endPoints)); } /** - * Returns the tree starting from the given root element if it is contained in the graph. - * <p> - * Contrarily to {@link #getSubgraphContaining(Object)}, this will only iterate over the children (and - * recursively) of the given node, without ever "going up" to parents of these children. - * </p> - * <p> - * <b>Note</b> that the returned set is an immutable view over a sub-graph of this graph. - * </p> + * {@inheritDoc} * - * @param root - * The element we are to consider as the root of a tree. - * @return The immutable tree starting from the given root element if it is contained in this graph, and - * immutable empty set otherwise. + * @see org.eclipse.emf.compare.graph.IGraphView#getTreeFrom(Object) */ public ImmutableSet<E> getTreeFrom(E root) { return getTreeFrom(root, ImmutableSet.<E> of()); } /** - * Returns the tree starting from the given root element and ending at the given boundaries.. - * <p> - * Contrarily to {@link #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. - * </p> - * <p> - * <b>Note</b> that the returned set is an immutable view over a sub-graph of this graph. - * </p> + * {@inheritDoc} * - * @param root - * The element we are to consider as the root of a tree. - * @param endPoints - * Boundaries of the tree. - * @return The immutable tree starting from the given root element if it is contained in this graph, and - * immutable empty set otherwise. + * @see org.eclipse.emf.compare.graph.IGraphView#getTreeFrom(Object, Set) */ public ImmutableSet<E> getTreeFrom(E root, Set<E> endPoints) { return ImmutableSet.copyOf(graph.getTreeFrom(root, endPoints)); } /** - * 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. - * <p> - * The returned iterator does not support removal, and will fail or returned undefined results if this - * graph is modified after the iterator's creation. - * </p> + * {@inheritDoc} * - * @return A breadth-first iterator over this whole graph. + * @see org.eclipse.emf.compare.graph.IGraphView#breadthFirstIterator() */ public PruningIterator<E> breadthFirstIterator() { return graph.breadthFirstIterator(); |