Fix some of the warnings
[EMFCompare2.git] / plugins / org.eclipse.emf.compare.ide / src / org / eclipse / emf / compare / ide / utils / StorageTraversal.java
blob84fcb194cb776dc0ca4b318d66b44431bd3afbd3
1 /*******************************************************************************
2 * Copyright (c) 2011, 2015 Obeo.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * Obeo - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.emf.compare.ide.utils;
13 import com.google.common.annotations.Beta;
14 import com.google.common.base.Preconditions;
15 import com.google.common.collect.Lists;
17 import java.util.LinkedHashSet;
18 import java.util.List;
19 import java.util.Set;
21 import org.eclipse.core.resources.IFile;
22 import org.eclipse.core.resources.IResource;
23 import org.eclipse.core.resources.IStorage;
24 import org.eclipse.core.resources.ResourcesPlugin;
25 import org.eclipse.core.runtime.IAdaptable;
26 import org.eclipse.emf.common.util.BasicDiagnostic;
27 import org.eclipse.emf.common.util.Diagnostic;
28 import org.eclipse.emf.compare.ide.EMFCompareIDEPlugin;
29 import org.eclipse.emf.compare.utils.IDiagnosable;
31 /**
32 * A Resource Traversal is no more than a set of resources used by the synchronization model to determine
33 * which resources to load as part of a given logical model.
35 * @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
37 @Beta
38 public class StorageTraversal implements IAdaptable, IDiagnosable {
39 /** The set of storages that are part of this traversal. */
40 private Set<? extends IStorage> storages;
42 /** The diagnostic of the errors that may occur during loading of the storages. */
43 private Diagnostic diagnostic;
45 /**
46 * Creates our traversal given its set of resources.
48 * @param storages
49 * The set of resources that are part of this traversal.
51 public StorageTraversal(Set<? extends IStorage> storages) {
52 this(storages, new BasicDiagnostic(EMFCompareIDEPlugin.PLUGIN_ID, 0, null, new Object[] {storages, }));
55 /**
56 * Creates our traversal given its set of resources.
58 * @param storages
59 * The set of resources that are part of this traversal.
60 * @param diagnostic
61 * diagnostic of the errors that may occur during loading of the storages.
63 public StorageTraversal(Set<? extends IStorage> storages, Diagnostic diagnostic) {
64 this.storages = storages;
65 this.diagnostic = Preconditions.checkNotNull(diagnostic);
68 /**
69 * Returns the set of resources that are part of this traversal.
70 * <p>
71 * Note that this is the original set, and that any modification on the returned {@link Set} will affect
72 * this traversal.
73 * </p>
75 * @return The set of resources that are part of this traversal.
77 public Set<? extends IStorage> getStorages() {
78 return new LinkedHashSet<IStorage>(storages);
81 /**
82 * Removes the given storage from this traversal.
84 * @param storage
85 * The storage to be removed.
86 * @since 3.1
88 public void removeStorage(IStorage storage) {
89 storages.remove(storage);
92 /**
93 * Returns the diagnostic of the storages of this traversal.
95 * @return the diagnostic
97 public Diagnostic getDiagnostic() {
98 return diagnostic;
102 * {@inheritDoc}
104 * @see org.eclipse.emf.compare.utils.IDiagnosable#setDiagnostic(org.eclipse.emf.common.util.Diagnostic)
106 public void setDiagnostic(Diagnostic diagnostic) {
107 this.diagnostic = diagnostic;
111 * {@inheritDoc}
113 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
115 @SuppressWarnings("unchecked")
116 public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
117 if (adapter == org.eclipse.core.resources.mapping.ResourceTraversal.class) {
118 // Team's resource traversal only knows about IResources.
119 final List<IResource> resources = Lists.newArrayListWithCapacity(storages.size());
120 for (IStorage storage : storages) {
121 if (storage instanceof IFile) {
122 resources.add((IFile)storage);
123 } else {
125 * Use a file handle. Since files can be both local and remote, they might not even exist
126 * in the current workspace. It will be the responsibility of the user to either get the
127 * remote or local content. The traversal itself only tells "all" potential resources
128 * linked to the current.
130 resources.add(ResourcesPlugin.getWorkspace().getRoot().getFile(
131 ResourceUtil.getFixedPath(storage)));
134 final IResource[] resourceArray = resources.toArray(new IResource[resources.size()]);
135 return new org.eclipse.core.resources.mapping.ResourceTraversal(resourceArray,
136 IResource.DEPTH_ZERO, IResource.NONE);
138 return null;
141 /** {@inheritDoc} */
142 @Override
143 public boolean equals(Object obj) {
144 if (obj instanceof StorageTraversal) {
145 return storages.equals(((StorageTraversal)obj).storages);
147 return false;
150 /** {@inheritDoc} */
151 @Override
152 public int hashCode() {
153 return storages.hashCode();