Replace Guava with Java 8
Change-Id: I6ea95640fae46cbe38645df215424062db13be9b
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/conflict/DefaultConflictDetector.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/conflict/DefaultConflictDetector.java
index 300b684..6430feb 100644
--- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/conflict/DefaultConflictDetector.java
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/conflict/DefaultConflictDetector.java
@@ -15,13 +15,12 @@
import static org.eclipse.emf.compare.internal.utils.ComparisonUtil.isAddOrSetDiff;
import static org.eclipse.emf.compare.internal.utils.ComparisonUtil.isDeleteOrUnsetDiff;
import static org.eclipse.emf.compare.internal.utils.ComparisonUtil.isFeatureMapContainment;
-import static org.eclipse.emf.compare.utils.EMFComparePredicates.possiblyConflictingWith;
+import static org.eclipse.emf.compare.utils.EMFCompareJavaPredicates.possiblyConflictingWith;
import static org.eclipse.emf.compare.utils.MatchUtil.matchingIndices;
-import com.google.common.base.Predicate;
-
import java.util.ArrayList;
import java.util.List;
+import java.util.function.Predicate;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
@@ -252,7 +251,7 @@
*/
private Predicate<? super Match> isContainmentDelete() {
return new Predicate<Match>() {
- public boolean apply(Match input) {
+ public boolean test(Match input) {
return input.getOrigin() != null && (input.getLeft() == null || input.getRight() == null);
}
};
@@ -481,7 +480,7 @@
final Iterable<Diff> refinedCandidates = StreamSupport.stream(candidates.spliterator(), false)
.filter(new Predicate<Diff>() {
- public boolean apply(Diff input) {
+ public boolean test(Diff input) {
boolean apply = false;
if (input != null && input.getKind() == DifferenceKind.CHANGE) {
if (input instanceof ReferenceChange) {
@@ -666,7 +665,7 @@
final Iterable<Diff> refinedCandidates = StreamSupport.stream(candidates.spliterator(), false)
.filter(new Predicate<Diff>() {
- public boolean apply(Diff input) {
+ public boolean test(Diff input) {
boolean apply = false;
if (input != null && input.getKind() == DifferenceKind.MOVE) {
if (input instanceof ReferenceChange) {
@@ -734,7 +733,7 @@
*/
final Iterable<Diff> refinedCandidates = StreamSupport.stream(candidates.spliterator(), false)
.filter(new Predicate<Diff>() {
- public boolean apply(Diff input) {
+ public boolean test(Diff input) {
boolean apply = false;
if (input != null && (input.getKind() == DifferenceKind.MOVE
|| input.getKind() == DifferenceKind.DELETE)) {
@@ -802,7 +801,7 @@
*/
final Iterable<Diff> refinedCandidates = StreamSupport.stream(candidates.spliterator(), false)
.filter(new Predicate<Diff>() {
- public boolean apply(Diff input) {
+ public boolean test(Diff input) {
boolean apply = false;
if (input != null && (input.getKind() == DifferenceKind.ADD
&& diff.getMatch() == input.getMatch())) {
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/equi/DefaultEquiEngine.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/equi/DefaultEquiEngine.java
index bfef8fa..87ac0b6 100644
--- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/equi/DefaultEquiEngine.java
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/equi/DefaultEquiEngine.java
@@ -11,10 +11,9 @@
*******************************************************************************/
package org.eclipse.emf.compare.equi;
-import com.google.common.base.Predicate;
-
import java.util.LinkedHashSet;
import java.util.Set;
+import java.util.function.Predicate;
import org.apache.log4j.Logger;
import org.eclipse.emf.common.util.Monitor;
@@ -133,7 +132,7 @@
if (eOpposite != null && valueMatch != null) {
final Predicate<? super Diff> candidateFilter = new Predicate<Diff>() {
- public boolean apply(Diff input) {
+ public boolean test(Diff input) {
if (input instanceof ReferenceChange
&& ((ReferenceChange)input).getReference() == eOpposite) {
final Match candidateMatch = comparison
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/conflict/AbstractConflictSearch.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/conflict/AbstractConflictSearch.java
index c462108..9c02e32 100644
--- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/conflict/AbstractConflictSearch.java
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/conflict/AbstractConflictSearch.java
@@ -11,19 +11,16 @@
*******************************************************************************/
package org.eclipse.emf.compare.internal.conflict;
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.base.Preconditions.checkState;
import static org.eclipse.emf.compare.ConflictKind.PSEUDO;
import static org.eclipse.emf.compare.ConflictKind.REAL;
-import com.google.common.base.Predicate;
-
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Objects;
import java.util.Set;
+import java.util.function.Predicate;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.common.util.Monitor;
@@ -84,15 +81,17 @@
* the monitor to report progress to, must not be null
*/
public AbstractConflictSearch(T diff, ComparisonIndex index, Monitor monitor) {
- checkNotNull(diff);
+ Objects.requireNonNull(diff);
if (diff.getMatch() == null || diff.getMatch().getComparison() == null) {
throw new IllegalArgumentException();
}
comparison = diff.getMatch().getComparison();
- checkArgument(diff.getKind() != null && diff.getSource() != null);
+ if (diff.getKind() == null || diff.getSource() == null) {
+ throw new IllegalArgumentException();
+ }
this.diff = diff;
- this.index = checkNotNull(index);
- this.monitor = checkNotNull(monitor);
+ this.index = Objects.requireNonNull(index);
+ this.monitor = Objects.requireNonNull(monitor);
}
/**
@@ -350,8 +349,10 @@
soughtMatch = matchRes;
}
}
- checkState(soughtMatch != null, EMFCompareMessages
- .getString("ResourceAttachmentChangeSpec.MissingMatch", resource.getURI().lastSegment())); //$NON-NLS-1$
+ if (soughtMatch == null) {
+ throw new IllegalStateException(EMFCompareMessages
+ .getString("ResourceAttachmentChangeSpec.MissingMatch", resource.getURI().lastSegment())); //$NON-NLS-1$
+ }
return soughtMatch;
}
@@ -411,7 +412,9 @@
default:
throw new IllegalStateException();
}
- checkState(o != null);
+ if (o == null) {
+ throw new IllegalStateException();
+ }
return o;
}
@@ -423,7 +426,7 @@
*/
protected Predicate<? super Match> isContainmentDelete() {
return new Predicate<Match>() {
- public boolean apply(Match input) {
+ public boolean test(Match input) {
return input.getOrigin() != null && (input.getLeft() == null || input.getRight() == null);
}
};
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/conflict/AttributeChangeConflictSearch.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/conflict/AttributeChangeConflictSearch.java
index 1bda5f3..23f6861 100644
--- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/conflict/AttributeChangeConflictSearch.java
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/conflict/AttributeChangeConflictSearch.java
@@ -16,9 +16,9 @@
import static org.eclipse.emf.compare.DifferenceKind.CHANGE;
import static org.eclipse.emf.compare.DifferenceKind.DELETE;
import static org.eclipse.emf.compare.DifferenceKind.MOVE;
-import static org.eclipse.emf.compare.utils.EMFComparePredicates.ofKind;
-import static org.eclipse.emf.compare.utils.EMFComparePredicates.onFeature;
-import static org.eclipse.emf.compare.utils.EMFComparePredicates.possiblyConflictingWith;
+import static org.eclipse.emf.compare.utils.EMFCompareJavaPredicates.ofKind;
+import static org.eclipse.emf.compare.utils.EMFCompareJavaPredicates.onFeature;
+import static org.eclipse.emf.compare.utils.EMFCompareJavaPredicates.possiblyConflictingWith;
import static org.eclipse.emf.compare.utils.MatchUtil.matchingIndices;
import org.eclipse.emf.common.util.EList;
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/conflict/ContainmentRefChangeConflictSearch.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/conflict/ContainmentRefChangeConflictSearch.java
index b912ab7..d240eb7 100644
--- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/conflict/ContainmentRefChangeConflictSearch.java
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/conflict/ContainmentRefChangeConflictSearch.java
@@ -17,10 +17,10 @@
import static org.eclipse.emf.compare.DifferenceKind.MOVE;
import static org.eclipse.emf.compare.internal.utils.ComparisonUtil.isAddOrSetDiff;
import static org.eclipse.emf.compare.internal.utils.ComparisonUtil.isDeleteOrUnsetDiff;
-import static org.eclipse.emf.compare.utils.EMFComparePredicates.ofKind;
-import static org.eclipse.emf.compare.utils.EMFComparePredicates.onFeature;
-import static org.eclipse.emf.compare.utils.EMFComparePredicates.possiblyConflictingWith;
-import static org.eclipse.emf.compare.utils.EMFComparePredicates.valueMatches;
+import static org.eclipse.emf.compare.utils.EMFCompareJavaPredicates.ofKind;
+import static org.eclipse.emf.compare.utils.EMFCompareJavaPredicates.onFeature;
+import static org.eclipse.emf.compare.utils.EMFCompareJavaPredicates.possiblyConflictingWith;
+import static org.eclipse.emf.compare.utils.EMFCompareJavaPredicates.valueMatches;
import static org.eclipse.emf.compare.utils.MatchUtil.matchingIndices;
import java.util.Collection;
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/conflict/DiffTreeIterator.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/conflict/DiffTreeIterator.java
index 4ae1279..45ffac4 100644
--- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/conflict/DiffTreeIterator.java
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/conflict/DiffTreeIterator.java
@@ -10,11 +10,9 @@
*******************************************************************************/
package org.eclipse.emf.compare.internal.conflict;
-import com.google.common.base.Predicate;
-import com.google.common.base.Predicates;
-
import java.util.Iterator;
import java.util.NoSuchElementException;
+import java.util.function.Predicate;
import org.eclipse.emf.common.util.TreeIterator;
import org.eclipse.emf.compare.Diff;
@@ -49,13 +47,13 @@
private Diff nextDiff;
/** Only Diffs that meet this criterion will be returned by this iterator. */
- private Predicate<? super Diff> filter = Predicates.alwaysTrue();
+ private Predicate<? super Diff> filter = x -> true;
/**
* This particular filter can be used in order to prune a given Match and all of its differences and
* sub-differences.
*/
- private Predicate<? super Match> pruningFilter = Predicates.alwaysFalse();
+ private Predicate<? super Match> pruningFilter = x -> false;
/**
* Constructs our iterator given the root of the Match tree to iterate over.
@@ -104,7 +102,7 @@
}
while (nextDiff == null && diffIterator.hasNext()) {
final Diff next = diffIterator.next();
- if (filter.apply(next)) {
+ if (filter.test(next)) {
nextDiff = next;
}
}
@@ -118,7 +116,7 @@
final Match old = current;
while (current == old && subMatchIterator.hasNext()) {
final Match next = subMatchIterator.next();
- if (pruningFilter.apply(next)) {
+ if (pruningFilter.test(next)) {
subMatchIterator.prune();
} else {
current = next;
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/conflict/FeatureMapChangeConflictSearch.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/conflict/FeatureMapChangeConflictSearch.java
index 8cf4568..8d382d6 100644
--- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/conflict/FeatureMapChangeConflictSearch.java
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/conflict/FeatureMapChangeConflictSearch.java
@@ -16,10 +16,10 @@
import static org.eclipse.emf.compare.DifferenceKind.CHANGE;
import static org.eclipse.emf.compare.DifferenceKind.DELETE;
import static org.eclipse.emf.compare.DifferenceKind.MOVE;
-import static org.eclipse.emf.compare.utils.EMFComparePredicates.ofKind;
-import static org.eclipse.emf.compare.utils.EMFComparePredicates.onFeature;
-import static org.eclipse.emf.compare.utils.EMFComparePredicates.possiblyConflictingWith;
-import static org.eclipse.emf.compare.utils.EMFComparePredicates.valueMatches;
+import static org.eclipse.emf.compare.utils.EMFCompareJavaPredicates.ofKind;
+import static org.eclipse.emf.compare.utils.EMFCompareJavaPredicates.onFeature;
+import static org.eclipse.emf.compare.utils.EMFCompareJavaPredicates.possiblyConflictingWith;
+import static org.eclipse.emf.compare.utils.EMFCompareJavaPredicates.valueMatches;
import static org.eclipse.emf.compare.utils.MatchUtil.matchingIndices;
import org.eclipse.emf.common.util.EList;
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/conflict/NonContainmentRefChangeConflictSearch.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/conflict/NonContainmentRefChangeConflictSearch.java
index f179fd2..b7dac31 100644
--- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/conflict/NonContainmentRefChangeConflictSearch.java
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/conflict/NonContainmentRefChangeConflictSearch.java
@@ -16,9 +16,9 @@
import static org.eclipse.emf.compare.DifferenceKind.CHANGE;
import static org.eclipse.emf.compare.DifferenceKind.DELETE;
import static org.eclipse.emf.compare.DifferenceKind.MOVE;
-import static org.eclipse.emf.compare.utils.EMFComparePredicates.ofKind;
-import static org.eclipse.emf.compare.utils.EMFComparePredicates.onFeature;
-import static org.eclipse.emf.compare.utils.EMFComparePredicates.possiblyConflictingWith;
+import static org.eclipse.emf.compare.utils.EMFCompareJavaPredicates.ofKind;
+import static org.eclipse.emf.compare.utils.EMFCompareJavaPredicates.onFeature;
+import static org.eclipse.emf.compare.utils.EMFCompareJavaPredicates.possiblyConflictingWith;
import static org.eclipse.emf.compare.utils.MatchUtil.matchingIndices;
import org.eclipse.emf.common.util.EList;
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/conflict/ResourceAttachmentChangeConflictSearch.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/conflict/ResourceAttachmentChangeConflictSearch.java
index 290b4fc..a442ca4 100644
--- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/conflict/ResourceAttachmentChangeConflictSearch.java
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/internal/conflict/ResourceAttachmentChangeConflictSearch.java
@@ -10,14 +10,13 @@
*******************************************************************************/
package org.eclipse.emf.compare.internal.conflict;
-import static com.google.common.base.Predicates.instanceOf;
import static org.eclipse.emf.compare.ConflictKind.PSEUDO;
import static org.eclipse.emf.compare.ConflictKind.REAL;
import static org.eclipse.emf.compare.DifferenceKind.ADD;
import static org.eclipse.emf.compare.DifferenceKind.DELETE;
import static org.eclipse.emf.compare.DifferenceKind.MOVE;
import static org.eclipse.emf.compare.internal.utils.ComparisonUtil.isDeleteOrUnsetDiff;
-import static org.eclipse.emf.compare.utils.EMFComparePredicates.possiblyConflictingWith;
+import static org.eclipse.emf.compare.utils.EMFCompareJavaPredicates.possiblyConflictingWith;
import java.util.Collection;
@@ -96,7 +95,7 @@
// Then let's see if there's a conflict with another ResourceAttachmentChange
EList<Diff> diffsInSameMatch = diff.getMatch().getDifferences();
Iterable<Diff> racCandidates = diffsInSameMatch.stream().filter(
- possiblyConflictingWith(diff).and(instanceOf(ResourceAttachmentChange.class)))::iterator;
+ possiblyConflictingWith(diff).and(ResourceAttachmentChange.class::isInstance))::iterator;
for (Diff candidate : racCandidates) {
ConflictKind kind = REAL;
if (candidate.getKind() == ADD) {
@@ -198,7 +197,7 @@
// Then let's see if there's a conflict with another ResourceAttachmentChange
EList<Diff> diffsInSameMatch = diff.getMatch().getDifferences();
Iterable<Diff> racCandidates = diffsInSameMatch.stream().filter(
- possiblyConflictingWith(diff).and(instanceOf(ResourceAttachmentChange.class)))::iterator;
+ possiblyConflictingWith(diff).and(ResourceAttachmentChange.class::isInstance))::iterator;
for (Diff candidate : racCandidates) {
ConflictKind kind = REAL;
if (candidate.getKind() == DELETE) {
@@ -283,7 +282,7 @@
EList<Diff> diffsInSameMatch = diff.getMatch().getDifferences();
Iterable<Diff> candidates = diffsInSameMatch.stream().filter(
- possiblyConflictingWith(diff).and(instanceOf(ResourceAttachmentChange.class)))::iterator;
+ possiblyConflictingWith(diff).and(ResourceAttachmentChange.class::isInstance))::iterator;
for (Diff candidate : candidates) {
ConflictKind kind = REAL;
if (candidate.getKind() == MOVE) {
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/utils/EMFCompareJavaPredicates.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/utils/EMFCompareJavaPredicates.java
new file mode 100644
index 0000000..ae1314e
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/utils/EMFCompareJavaPredicates.java
@@ -0,0 +1,208 @@
+/*******************************************************************************
+ * Copyright (c) 2019 Obeo.
+ * 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:
+ * Obeo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.utils;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.eclipse.emf.compare.internal.utils.ComparisonUtil.isDeleteOrUnsetDiff;
+
+import java.util.Arrays;
+import java.util.Objects;
+import java.util.function.Predicate;
+
+import org.eclipse.emf.compare.AttributeChange;
+import org.eclipse.emf.compare.Conflict;
+import org.eclipse.emf.compare.Diff;
+import org.eclipse.emf.compare.DifferenceKind;
+import org.eclipse.emf.compare.FeatureMapChange;
+import org.eclipse.emf.compare.ReferenceChange;
+import org.eclipse.emf.compare.ResourceLocationChange;
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.eclipse.emf.ecore.util.FeatureMap;
+
+/**
+ * This class will provide a number of Predicates that can be used to retrieve particular {@link Diff}s from
+ * an iterable.
+ *
+ * @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
+ */
+public final class EMFCompareJavaPredicates {
+
+ /**
+ * Predicate builder for diffs that can conflict with the given diff.
+ *
+ * @param diff
+ * The diff
+ * @return A predicate that accepts diffs that might conflict with the given diff.
+ */
+ public static Predicate<Diff> possiblyConflictingWith(Diff diff) {
+ return new ConflictCandidateFilter(diff);
+ }
+
+ /**
+ * This predicate can be used to check whether a particular diff is of the given {@code kind}. This is
+ * mainly used to differentiate additions from deletions.
+ *
+ * @param kind
+ * The kind we expect this diff to have.
+ * @return The created predicate.
+ */
+ public static Predicate<? super Diff> ofKind(DifferenceKind... kind) {
+ return new Predicate<Diff>() {
+ public boolean test(Diff input) {
+ if (input != null) {
+ return Arrays.asList(kind).contains(input.getKind());
+ }
+ return false;
+ }
+ };
+ }
+
+ /**
+ * Accept only diffs that inherit either AttributeChange, ReferenceChange, or FeatureMapChange that
+ * concern the given feature.
+ *
+ * @param feature
+ * Feature to deal with
+ * @return a new predicate that accepts diffs that concern the given feature.
+ */
+ public static Predicate<Diff> onFeature(EStructuralFeature feature) {
+ return new OnFeature(feature);
+ }
+
+ /**
+ * Accept only diffs whose value matches the given value.
+ *
+ * @param helper
+ * The helper to match values
+ * @param value
+ * The value to match
+ * @return The created predicate.
+ */
+ public static Predicate<Diff> valueMatches(final IEqualityHelper helper, final Object value) {
+ return new Predicate<Diff>() {
+ public boolean test(Diff input) {
+ if (input instanceof ReferenceChange) {
+ return helper.matchingValues(value, ((ReferenceChange)input).getValue());
+ } else if (input instanceof AttributeChange) {
+ return helper.matchingValues(value, ((AttributeChange)input).getValue());
+ } else if (input instanceof FeatureMapChange) {
+ return helper.matchingValues(value,
+ ((FeatureMap.Entry)((FeatureMapChange)input).getValue()).getValue());
+ }
+ return false;
+ }
+ };
+ }
+
+ /**
+ * This will be used to filter out the list of potential candidates for conflict with a given Diff.
+ *
+ * @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
+ */
+ private static final class ConflictCandidateFilter implements Predicate<Diff> {
+ /** The Diff for which we seek conflict candidates. */
+ private final Diff diff;
+
+ /**
+ * Instantiates our filtering Predicate given the reference Diff for which to seek potential
+ * conflicts.
+ *
+ * @param diff
+ * The Diff for which we seek conflict candidates, must not be null.
+ */
+ ConflictCandidateFilter(Diff diff) {
+ this.diff = Objects.requireNonNull(diff);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see com.google.common.base.Predicate#apply(java.lang.Object)
+ */
+ public boolean test(Diff input) {
+ return !(input instanceof ResourceLocationChange) && canConflictWith(input);
+ }
+
+ /**
+ * Checks if the given {@link Diff diff1} can be in conflict with the given {@link Diff diff2}.
+ * <p>
+ * Notably, we don't need to try and detect a conflict between two diffs if they're one and the same
+ * or if they have already been detected as a conflicting couple. Likewise, there can be no conflict
+ * if the two diffs originate from the same side.
+ * </p>
+ * <p>
+ * bug 381143 : we'll also remove any containment deletion diff on other Matches from here.
+ * </p>
+ *
+ * @param other
+ * candidate difference to consider for conflict detection.
+ * @return {@code true} if the two given diffs can conflict, {@code false} otherwise.
+ */
+ private boolean canConflictWith(Diff other) {
+ if (diff == other || diff.getSource() == other.getSource()) {
+ return false;
+ }
+ Conflict conflict = diff.getConflict();
+ boolean canConflict = false;
+ if (conflict == null || !conflict.getDifferences().contains(other)) {
+ if (diff.getMatch() != other.getMatch() && other instanceof ReferenceChange
+ && ((ReferenceChange)other).getReference().isContainment()) {
+ canConflict = !isDeleteOrUnsetDiff(other);
+ } else {
+ canConflict = true;
+ }
+ }
+ return canConflict;
+ }
+ }
+
+ /**
+ * Predicate for diffs taht concern a given feature.
+ *
+ * @author <a href="mailto:laurent.delaigue@obeo.fr">Laurent Delaigue</a>
+ */
+ private static class OnFeature implements Predicate<Diff> {
+ /** The feature. */
+ private final EStructuralFeature feature;
+
+ /**
+ * Constructor.
+ *
+ * @param feature
+ * the feature
+ */
+ OnFeature(EStructuralFeature feature) {
+ this.feature = checkNotNull(feature);
+ }
+
+ /**
+ * Apply the predicate.
+ *
+ * @param input
+ * The diff to filter.
+ * @return true if and only if input concerns the given feature.
+ */
+ public boolean test(Diff input) {
+ if (input == null) {
+ return false;
+ }
+ boolean apply = false;
+ if (input instanceof ReferenceChange) {
+ apply = ((ReferenceChange)input).getReference() == feature;
+ } else if (input instanceof AttributeChange) {
+ apply = ((AttributeChange)input).getAttribute() == feature;
+ } else if (input instanceof FeatureMapChange) {
+ apply = ((FeatureMapChange)input).getAttribute() == feature;
+ }
+ return apply;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/utils/EMFComparePredicates.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/utils/EMFComparePredicates.java
index 02f8091..4d3a975 100644
--- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/utils/EMFComparePredicates.java
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/utils/EMFComparePredicates.java
@@ -60,7 +60,9 @@
* an iterable.
*
* @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
+ * @deprecated this class provides Guava predicates. Please consider using EMFCompareJavaPredicates instead.
*/
+@Deprecated
public final class EMFComparePredicates {
/**
* This can be used to test whether a given Diff has no conflict object associated.