/*******************************************************************************
 * Copyright (c) 2015 The University of York.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     Antonio Garcia-Dominguez - initial API and implementation
 ******************************************************************************/
package org.hawk.graph;

import java.util.HashSet;
import java.util.Set;

import org.hawk.core.graph.IGraphDatabase;
import org.hawk.core.graph.IGraphNode;
import org.hawk.core.graph.IGraphNodeIndex;

/**
 * Wraps an {@link IGraphDatabase} that has been updated by this plugin. This is
 * the starting point for the read-only abstraction of the graph populated by
 * this updater. Users of this class and any other classes of this package are
 * expected to manage their own transactions with
 * {@link IGraphDatabase#beginTransaction()}.
 *
 * TODO This is an incomplete WIP abstraction. More methods will be called as
 * the existing queries are moved into this API.
 */
public class GraphWrapper {

	private final IGraphDatabase graph;

	public GraphWrapper(IGraphDatabase graph) {
		this.graph = graph;
	}

	/**
	 * Convenience version of {@link #getRawFileNodes(Iterable)} that wraps all
	 * results as {@link FileNode}s.
	 */
	public Set<FileNode> getFileNodes(Iterable<String> patterns) {
		final IGraphNodeIndex fileIndex = graph.getFileIndex();

		final Set<FileNode> files = new HashSet<>();
		for (String s : patterns) {
			for (IGraphNode n : fileIndex.query("id", s)) {
				files.add(new FileNode(n));
			}
		}
		return files;
	}

}

@@ -584,16 +584,57 @@
 ashSet;%0A
+import java.util.NoSuchElementException;%0A
 import j
@@ -1818,10 +1818,507 @@
 es;%0A%09%7D%0A%0A
+%09/**%0A%09 * Returns the graph wrapped by this instance.%0A%09 */%0A%09public IGraphDatabase getGraph() %7B%0A%09%09return graph;%0A%09%7D%0A%0A%09/**%0A%09 * Retrieves a %7B@link ModelElementNode%7D by identifier.%0A%09 *%0A%09 * @throws NoSuchElementException%0A%09 *             No node with that identifier exists.%0A%09 */%0A%09public ModelElementNode getModelElementNodeById(String id) %7B%0A%09%09final IGraphNode rawNode = graph.getNodeById(id);%0A%09%09if (rawNode == null) %7B%0A%09%09%09throw new NoSuchElementException();%0A%09%09%7D%0A%09%09return new ModelElementNode(rawNode);%0A%09%7D%0A
 %7D%0A

add getGraph and getModelElementNodeById