Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Dirix2015-08-27 11:52:24 +0000
committerAxel RICHARD2015-09-02 08:43:22 +0000
commit88d73ad228347f4d7790fb74c3b75990eec5d400 (patch)
tree2abbfa1309efa942a815d4a78f20f424deae8e5c /plugins
parentc1fc714f2410092dd77d6c1c225750aeb5227932 (diff)
downloadorg.eclipse.emf.compare-88d73ad228347f4d7790fb74c3b75990eec5d400.tar.gz
org.eclipse.emf.compare-88d73ad228347f4d7790fb74c3b75990eec5d400.tar.xz
org.eclipse.emf.compare-88d73ad228347f4d7790fb74c3b75990eec5d400.zip
[475401] Modify RootIDMatchingStrategy to only return unique mappings
The RootIDMatchingStrategy determines matching between resources by intersecting the IDs of their root objects. The RootIDMatchingStrategy now checks if a possible mapping is unique and does therefore not intersect with another possible mapping. The previous behavior of returning the first possible mapping creates "random" results, affected by the order the given iterators return their resources. Since this strategy can not determine which is the "better" mapping of multiple options it should not return any of them. This way the remaining EMFCompareFramework is not confused by "half-true" mappings. Includes two-way testcases. Bug: 475401 Signed-off-by: Stefan Dirix <sdirix@eclipsesource.com> Change-Id: I2cb886d088d6ce27cbc06ec2958fc02ef9253d36
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/RootIDMatchingTest.java141
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/MatchInputData.java87
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a1/left.nodes8
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a1/left2.nodes8
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a1/right.nodes8
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a1/right2.nodes8
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a2/left.nodes8
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a2/left2.nodes8
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a2/right.nodes8
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a2/right2.nodes8
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a3/left.nodes8
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a3/left2.nodes8
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a3/right.nodes8
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a3/right2.nodes8
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a4/left.nodes8
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a4/left2.nodes8
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a4/right.nodes8
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a4/right2.nodes8
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a5/left.nodes8
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a5/left2.nodes8
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a5/right.nodes8
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a5/right2.nodes8
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a6/left.nodes8
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a6/left2.nodes8
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a6/right.nodes8
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a6/right2.nodes8
-rw-r--r--plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllTests.java3
-rw-r--r--plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/resource/RootIDMatchingStrategy.java180
28 files changed, 582 insertions, 21 deletions
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/RootIDMatchingTest.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/RootIDMatchingTest.java
new file mode 100644
index 000000000..d15476139
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/RootIDMatchingTest.java
@@ -0,0 +1,141 @@
+/*******************************************************************************
+ * Copyright (c) 2015 EclipseSource Muenchen GmbH and others.
+ * 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:
+ * Stefan Dirix - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.emf.compare.tests.match;
+
+import static org.junit.Assert.assertEquals;
+
+import com.google.common.collect.Lists;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.eclipse.emf.compare.MatchResource;
+import org.eclipse.emf.compare.match.resource.RootIDMatchingStrategy;
+import org.eclipse.emf.compare.tests.match.data.MatchInputData;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.junit.Test;
+
+public class RootIDMatchingTest {
+
+ private MatchInputData input = new MatchInputData();
+
+ /**
+ * Tests a scenario in which all root ids are different and no match should be returned.
+ *
+ * @throws IOException
+ * if {@link MatchInputData} fails to load the test models.
+ */
+ @Test
+ public void testRootIDTwoWayA1() throws IOException {
+ List<Resource> left = input.getRootIDTwoWayA1Left();
+ List<Resource> right = input.getRootIDTwoWayA1Right();
+ List<Resource> origin = Lists.newLinkedList();
+
+ RootIDMatchingStrategy strategy = new RootIDMatchingStrategy();
+ List<MatchResource> matchResources = strategy.matchResources(left, right, origin);
+
+ assertEquals(0, matchResources.size());
+ }
+
+ /**
+ * Tests a scenario in which one pair of root ids intersect and one match should be returned.
+ *
+ * @throws IOException
+ * if {@link MatchInputData} fails to load the test models.
+ */
+ @Test
+ public void testRootIDTwoWayA2() throws IOException {
+ List<Resource> left = input.getRootIDTwoWayA2Left();
+ List<Resource> right = input.getRootIDTwoWayA2Right();
+ List<Resource> origin = Lists.newLinkedList();
+
+ RootIDMatchingStrategy strategy = new RootIDMatchingStrategy();
+ List<MatchResource> matchResources = strategy.matchResources(left, right, origin);
+
+ assertEquals(1, matchResources.size());
+ }
+
+ /**
+ * Tests a scenario in which each file has at least one root id which intersects and therefore two matches
+ * should be returned.
+ *
+ * @throws IOException
+ * if {@link MatchInputData} fails to load the test models.
+ */
+ @Test
+ public void testRootIDTwoWayA3() throws IOException {
+ List<Resource> left = input.getRootIDTwoWayA3Left();
+ List<Resource> right = input.getRootIDTwoWayA3Right();
+ List<Resource> origin = Lists.newLinkedList();
+
+ RootIDMatchingStrategy strategy = new RootIDMatchingStrategy();
+ List<MatchResource> matchResources = strategy.matchResources(left, right, origin);
+
+ assertEquals(2, matchResources.size());
+ }
+
+ /**
+ * Tests a scenario in which one resource from the left intersects with all files from the right,
+ * therefore no match should be returned.
+ *
+ * @throws IOException
+ * if {@link MatchInputData} fails to load the test models.
+ */
+ @Test
+ public void testRootIDTwoWayA4() throws IOException {
+ List<Resource> left = input.getRootIDTwoWayA4Left();
+ List<Resource> right = input.getRootIDTwoWayA4Right();
+ List<Resource> origin = Lists.newLinkedList();
+
+ RootIDMatchingStrategy strategy = new RootIDMatchingStrategy();
+ List<MatchResource> matchResources = strategy.matchResources(left, right, origin);
+
+ assertEquals(0, matchResources.size());
+ }
+
+ /**
+ * Tests a scenario in which one resource from the left intersects with both files from the right, while
+ * the other left file intersects with only one. Still no match should be returned.
+ *
+ * @throws IOException
+ * if {@link MatchInputData} fails to load the test models.
+ */
+ @Test
+ public void testRootIDTwoWayA5() throws IOException {
+ List<Resource> left = input.getRootIDTwoWayA5Left();
+ List<Resource> right = input.getRootIDTwoWayA5Right();
+ List<Resource> origin = Lists.newLinkedList();
+
+ RootIDMatchingStrategy strategy = new RootIDMatchingStrategy();
+ List<MatchResource> matchResources = strategy.matchResources(left, right, origin);
+
+ assertEquals(0, matchResources.size());
+ }
+
+ /**
+ * Tests a scenario in which one resource from the right intersects with both files from the left, while
+ * the other right file intersects with only one. Still no match should be returned.
+ *
+ * @throws IOException
+ * if {@link MatchInputData} fails to load the test models.
+ */
+ @Test
+ public void testRootIDTwoWayA6() throws IOException {
+ List<Resource> left = input.getRootIDTwoWayA6Left();
+ List<Resource> right = input.getRootIDTwoWayA6Right();
+ List<Resource> origin = Lists.newLinkedList();
+
+ RootIDMatchingStrategy strategy = new RootIDMatchingStrategy();
+ List<MatchResource> matchResources = strategy.matchResources(left, right, origin);
+
+ assertEquals(0, matchResources.size());
+ }
+}
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/MatchInputData.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/MatchInputData.java
index b8350ae33..8cf854278 100644
--- a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/MatchInputData.java
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/MatchInputData.java
@@ -10,7 +10,10 @@
*******************************************************************************/
package org.eclipse.emf.compare.tests.match.data;
+import com.google.common.collect.Lists;
+
import java.io.IOException;
+import java.util.List;
import org.eclipse.emf.compare.tests.framework.AbstractInputData;
import org.eclipse.emf.ecore.resource.Resource;
@@ -35,6 +38,90 @@ public class MatchInputData extends AbstractInputData {
return loadFromClassLoader("proxy/a2/right.nodes", new ResourceSetImpl());
}
+ public List<Resource> getRootIDTwoWayA1Left() throws IOException {
+ List<Resource> result = Lists.newLinkedList();
+ result.add(loadFromClassLoader("rootid/twoway/a1/left.nodes"));
+ result.add(loadFromClassLoader("rootid/twoway/a1/left2.nodes"));
+ return result;
+ }
+
+ public List<Resource> getRootIDTwoWayA1Right() throws IOException {
+ List<Resource> result = Lists.newLinkedList();
+ result.add(loadFromClassLoader("rootid/twoway/a1/right.nodes"));
+ result.add(loadFromClassLoader("rootid/twoway/a1/right2.nodes"));
+ return result;
+ }
+
+ public List<Resource> getRootIDTwoWayA2Left() throws IOException {
+ List<Resource> result = Lists.newLinkedList();
+ result.add(loadFromClassLoader("rootid/twoway/a2/left.nodes"));
+ result.add(loadFromClassLoader("rootid/twoway/a2/left2.nodes"));
+ return result;
+ }
+
+ public List<Resource> getRootIDTwoWayA2Right() throws IOException {
+ List<Resource> result = Lists.newLinkedList();
+ result.add(loadFromClassLoader("rootid/twoway/a2/right.nodes"));
+ result.add(loadFromClassLoader("rootid/twoway/a2/right2.nodes"));
+ return result;
+ }
+
+ public List<Resource> getRootIDTwoWayA3Left() throws IOException {
+ List<Resource> result = Lists.newLinkedList();
+ result.add(loadFromClassLoader("rootid/twoway/a3/left.nodes"));
+ result.add(loadFromClassLoader("rootid/twoway/a3/left2.nodes"));
+ return result;
+ }
+
+ public List<Resource> getRootIDTwoWayA3Right() throws IOException {
+ List<Resource> result = Lists.newLinkedList();
+ result.add(loadFromClassLoader("rootid/twoway/a3/right.nodes"));
+ result.add(loadFromClassLoader("rootid/twoway/a3/right2.nodes"));
+ return result;
+ }
+
+ public List<Resource> getRootIDTwoWayA4Left() throws IOException {
+ List<Resource> result = Lists.newLinkedList();
+ result.add(loadFromClassLoader("rootid/twoway/a4/left.nodes"));
+ result.add(loadFromClassLoader("rootid/twoway/a4/left2.nodes"));
+ return result;
+ }
+
+ public List<Resource> getRootIDTwoWayA4Right() throws IOException {
+ List<Resource> result = Lists.newLinkedList();
+ result.add(loadFromClassLoader("rootid/twoway/a4/right.nodes"));
+ result.add(loadFromClassLoader("rootid/twoway/a4/right2.nodes"));
+ return result;
+ }
+
+ public List<Resource> getRootIDTwoWayA5Left() throws IOException {
+ List<Resource> result = Lists.newLinkedList();
+ result.add(loadFromClassLoader("rootid/twoway/a5/left.nodes"));
+ result.add(loadFromClassLoader("rootid/twoway/a5/left2.nodes"));
+ return result;
+ }
+
+ public List<Resource> getRootIDTwoWayA5Right() throws IOException {
+ List<Resource> result = Lists.newLinkedList();
+ result.add(loadFromClassLoader("rootid/twoway/a5/right.nodes"));
+ result.add(loadFromClassLoader("rootid/twoway/a5/right2.nodes"));
+ return result;
+ }
+
+ public List<Resource> getRootIDTwoWayA6Left() throws IOException {
+ List<Resource> result = Lists.newLinkedList();
+ result.add(loadFromClassLoader("rootid/twoway/a6/left.nodes"));
+ result.add(loadFromClassLoader("rootid/twoway/a6/left2.nodes"));
+ return result;
+ }
+
+ public List<Resource> getRootIDTwoWayA6Right() throws IOException {
+ List<Resource> result = Lists.newLinkedList();
+ result.add(loadFromClassLoader("rootid/twoway/a6/right.nodes"));
+ result.add(loadFromClassLoader("rootid/twoway/a6/right2.nodes"));
+ return result;
+ }
+
public Resource getSetIDAttributeLeft() throws IOException {
return loadFromClassLoader("setidattribute/left.nodes");
}
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a1/left.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a1/left.nodes
new file mode 100644
index 000000000..35c9bc1f2
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a1/left.nodes
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xmi:XMI
+ xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI"
+ xmlns:nodes="http://www.eclipse.org/emf/compare/tests/nodes">
+ <nodes:Node xmi:id="_a" name="a"/>
+ <nodes:Node xmi:id="_b" name="b"/>
+</xmi:XMI> \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a1/left2.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a1/left2.nodes
new file mode 100644
index 000000000..f8d367253
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a1/left2.nodes
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xmi:XMI
+ xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI"
+ xmlns:nodes="http://www.eclipse.org/emf/compare/tests/nodes">
+ <nodes:Node xmi:id="_c" name="c"/>
+ <nodes:Node xmi:id="_d" name="d"/>
+</xmi:XMI> \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a1/right.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a1/right.nodes
new file mode 100644
index 000000000..1af0046cf
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a1/right.nodes
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xmi:XMI
+ xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI"
+ xmlns:nodes="http://www.eclipse.org/emf/compare/tests/nodes">
+ <nodes:Node xmi:id="_e" name="e"/>
+ <nodes:Node xmi:id="_f" name="f"/>
+</xmi:XMI> \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a1/right2.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a1/right2.nodes
new file mode 100644
index 000000000..26c53552a
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a1/right2.nodes
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xmi:XMI
+ xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI"
+ xmlns:nodes="http://www.eclipse.org/emf/compare/tests/nodes">
+ <nodes:Node xmi:id="_g" name="g"/>
+ <nodes:Node xmi:id="_h" name="h"/>
+</xmi:XMI> \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a2/left.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a2/left.nodes
new file mode 100644
index 000000000..35c9bc1f2
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a2/left.nodes
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xmi:XMI
+ xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI"
+ xmlns:nodes="http://www.eclipse.org/emf/compare/tests/nodes">
+ <nodes:Node xmi:id="_a" name="a"/>
+ <nodes:Node xmi:id="_b" name="b"/>
+</xmi:XMI> \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a2/left2.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a2/left2.nodes
new file mode 100644
index 000000000..f8d367253
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a2/left2.nodes
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xmi:XMI
+ xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI"
+ xmlns:nodes="http://www.eclipse.org/emf/compare/tests/nodes">
+ <nodes:Node xmi:id="_c" name="c"/>
+ <nodes:Node xmi:id="_d" name="d"/>
+</xmi:XMI> \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a2/right.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a2/right.nodes
new file mode 100644
index 000000000..204743178
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a2/right.nodes
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xmi:XMI
+ xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI"
+ xmlns:nodes="http://www.eclipse.org/emf/compare/tests/nodes">
+ <nodes:Node xmi:id="_a" name="a"/>
+ <nodes:Node xmi:id="_f" name="f"/>
+</xmi:XMI> \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a2/right2.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a2/right2.nodes
new file mode 100644
index 000000000..26c53552a
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a2/right2.nodes
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xmi:XMI
+ xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI"
+ xmlns:nodes="http://www.eclipse.org/emf/compare/tests/nodes">
+ <nodes:Node xmi:id="_g" name="g"/>
+ <nodes:Node xmi:id="_h" name="h"/>
+</xmi:XMI> \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a3/left.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a3/left.nodes
new file mode 100644
index 000000000..35c9bc1f2
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a3/left.nodes
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xmi:XMI
+ xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI"
+ xmlns:nodes="http://www.eclipse.org/emf/compare/tests/nodes">
+ <nodes:Node xmi:id="_a" name="a"/>
+ <nodes:Node xmi:id="_b" name="b"/>
+</xmi:XMI> \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a3/left2.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a3/left2.nodes
new file mode 100644
index 000000000..f8d367253
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a3/left2.nodes
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xmi:XMI
+ xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI"
+ xmlns:nodes="http://www.eclipse.org/emf/compare/tests/nodes">
+ <nodes:Node xmi:id="_c" name="c"/>
+ <nodes:Node xmi:id="_d" name="d"/>
+</xmi:XMI> \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a3/right.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a3/right.nodes
new file mode 100644
index 000000000..b70e22860
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a3/right.nodes
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xmi:XMI
+ xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI"
+ xmlns:nodes="http://www.eclipse.org/emf/compare/tests/nodes">
+ <nodes:Node xmi:id="_b" name="b"/>
+ <nodes:Node xmi:id="_a" name="a"/>
+</xmi:XMI> \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a3/right2.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a3/right2.nodes
new file mode 100644
index 000000000..01d0f90cb
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a3/right2.nodes
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xmi:XMI
+ xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI"
+ xmlns:nodes="http://www.eclipse.org/emf/compare/tests/nodes">
+ <nodes:Node xmi:id="_g" name="g"/>
+ <nodes:Node xmi:id="_d" name="d"/>
+</xmi:XMI> \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a4/left.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a4/left.nodes
new file mode 100644
index 000000000..35c9bc1f2
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a4/left.nodes
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xmi:XMI
+ xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI"
+ xmlns:nodes="http://www.eclipse.org/emf/compare/tests/nodes">
+ <nodes:Node xmi:id="_a" name="a"/>
+ <nodes:Node xmi:id="_b" name="b"/>
+</xmi:XMI> \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a4/left2.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a4/left2.nodes
new file mode 100644
index 000000000..f8d367253
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a4/left2.nodes
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xmi:XMI
+ xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI"
+ xmlns:nodes="http://www.eclipse.org/emf/compare/tests/nodes">
+ <nodes:Node xmi:id="_c" name="c"/>
+ <nodes:Node xmi:id="_d" name="d"/>
+</xmi:XMI> \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a4/right.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a4/right.nodes
new file mode 100644
index 000000000..204743178
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a4/right.nodes
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xmi:XMI
+ xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI"
+ xmlns:nodes="http://www.eclipse.org/emf/compare/tests/nodes">
+ <nodes:Node xmi:id="_a" name="a"/>
+ <nodes:Node xmi:id="_f" name="f"/>
+</xmi:XMI> \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a4/right2.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a4/right2.nodes
new file mode 100644
index 000000000..6bb2d61b7
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a4/right2.nodes
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xmi:XMI
+ xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI"
+ xmlns:nodes="http://www.eclipse.org/emf/compare/tests/nodes">
+ <nodes:Node xmi:id="_g" name="g"/>
+ <nodes:Node xmi:id="_b" name="b"/>
+</xmi:XMI> \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a5/left.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a5/left.nodes
new file mode 100644
index 000000000..35c9bc1f2
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a5/left.nodes
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xmi:XMI
+ xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI"
+ xmlns:nodes="http://www.eclipse.org/emf/compare/tests/nodes">
+ <nodes:Node xmi:id="_a" name="a"/>
+ <nodes:Node xmi:id="_b" name="b"/>
+</xmi:XMI> \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a5/left2.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a5/left2.nodes
new file mode 100644
index 000000000..f8d367253
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a5/left2.nodes
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xmi:XMI
+ xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI"
+ xmlns:nodes="http://www.eclipse.org/emf/compare/tests/nodes">
+ <nodes:Node xmi:id="_c" name="c"/>
+ <nodes:Node xmi:id="_d" name="d"/>
+</xmi:XMI> \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a5/right.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a5/right.nodes
new file mode 100644
index 000000000..8311a1c33
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a5/right.nodes
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xmi:XMI
+ xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI"
+ xmlns:nodes="http://www.eclipse.org/emf/compare/tests/nodes">
+ <nodes:Node xmi:id="_a" name="a"/>
+ <nodes:Node xmi:id="_c" name="c"/>
+</xmi:XMI> \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a5/right2.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a5/right2.nodes
new file mode 100644
index 000000000..14a643212
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a5/right2.nodes
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xmi:XMI
+ xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI"
+ xmlns:nodes="http://www.eclipse.org/emf/compare/tests/nodes">
+ <nodes:Node xmi:id="_b" name="b"/>
+ <nodes:Node xmi:id="_h" name="h"/>
+</xmi:XMI> \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a6/left.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a6/left.nodes
new file mode 100644
index 000000000..35c9bc1f2
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a6/left.nodes
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xmi:XMI
+ xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI"
+ xmlns:nodes="http://www.eclipse.org/emf/compare/tests/nodes">
+ <nodes:Node xmi:id="_a" name="a"/>
+ <nodes:Node xmi:id="_b" name="b"/>
+</xmi:XMI> \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a6/left2.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a6/left2.nodes
new file mode 100644
index 000000000..f8d367253
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a6/left2.nodes
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xmi:XMI
+ xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI"
+ xmlns:nodes="http://www.eclipse.org/emf/compare/tests/nodes">
+ <nodes:Node xmi:id="_c" name="c"/>
+ <nodes:Node xmi:id="_d" name="d"/>
+</xmi:XMI> \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a6/right.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a6/right.nodes
new file mode 100644
index 000000000..f81585e7d
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a6/right.nodes
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xmi:XMI
+ xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI"
+ xmlns:nodes="http://www.eclipse.org/emf/compare/tests/nodes">
+ <nodes:Node xmi:id="_a" name="a"/>
+ <nodes:Node xmi:id="_d" name="d"/>
+</xmi:XMI> \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a6/right2.nodes b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a6/right2.nodes
new file mode 100644
index 000000000..14a643212
--- /dev/null
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/match/data/rootid/twoway/a6/right2.nodes
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xmi:XMI
+ xmi:version="2.0"
+ xmlns:xmi="http://www.omg.org/XMI"
+ xmlns:nodes="http://www.eclipse.org/emf/compare/tests/nodes">
+ <nodes:Node xmi:id="_b" name="b"/>
+ <nodes:Node xmi:id="_h" name="h"/>
+</xmi:XMI> \ No newline at end of file
diff --git a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllTests.java b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllTests.java
index ed7d9e2c5..98df55f9e 100644
--- a/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllTests.java
+++ b/plugins/org.eclipse.emf.compare.tests/src/org/eclipse/emf/compare/tests/suite/AllTests.java
@@ -39,6 +39,7 @@ import org.eclipse.emf.compare.tests.match.IdentifierEObjectMatcherTest;
import org.eclipse.emf.compare.tests.match.MatchEngineFactoryRegistryTest;
import org.eclipse.emf.compare.tests.match.ProximityIndexTest;
import org.eclipse.emf.compare.tests.match.ProxyMatchingTest;
+import org.eclipse.emf.compare.tests.match.RootIDMatchingTest;
import org.eclipse.emf.compare.tests.match.XMIMatchingTest;
import org.eclipse.emf.compare.tests.merge.ConflictMergeTest;
import org.eclipse.emf.compare.tests.merge.ExtensionMergeTest;
@@ -83,7 +84,7 @@ import org.junit.runners.Suite.SuiteClasses;
ExtensionMergeTest.class, IndividualMergeOutOfScopeValuesTest.class, ProximityComparisonTest.class,
DynamicInstanceComparisonTest.class, URIDistanceTest.class, FragmentationTest.class,
AllEditTests.class, CommandStackTestSuite.class, MatchEngineFactoryRegistryTest.class,
- XMIMatchingTest.class, ProxyMatchingTest.class, ConflictMergeTest.class,
+ RootIDMatchingTest.class, XMIMatchingTest.class, ProxyMatchingTest.class, ConflictMergeTest.class,
PseudoConflictMergeTest.class, ProximityIndexTest.class, AllRCPTests.class,
FeatureMaps2wayMergeTest.class, FeatureMaps3wayMergeTest.class, FeatureMapsConflictsMergeTest.class,
FeatureMapsPseudoConflictsMergeTest.class, TwoWayBatchMergingTest.class, EqualityHelperTest.class,
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/resource/RootIDMatchingStrategy.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/resource/RootIDMatchingStrategy.java
index c2fafe18a..827af4d5a 100644
--- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/resource/RootIDMatchingStrategy.java
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/resource/RootIDMatchingStrategy.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2015 Obeo.
+ * Copyright (c) 2012, 2015 Obeo and others.
* 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
@@ -7,14 +7,18 @@
*
* Contributors:
* Obeo - initial API and implementation
+ * Stefan Dirix - only return unique matches
*******************************************************************************/
package org.eclipse.emf.compare.match.resource;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
+import java.util.ArrayList;
import java.util.Iterator;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import org.eclipse.emf.compare.CompareFactory;
@@ -31,46 +35,180 @@ import org.eclipse.emf.ecore.xmi.XMIResource;
* @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
*/
public class RootIDMatchingStrategy implements IResourceMatchingStrategy {
+
/**
- * {@inheritDoc}
+ * Matches the given resources according to the IDs found in their roots.
+ * <p>
+ * When the root IDs of two resources intersect, they are considered as matching. This strategy will only
+ * return unique matches between all resources.
+ * </p>
*
- * @see org.eclipse.emf.compare.match.resource.IResourceMatchingStrategy#matchResources(java.lang.Iterable,
- * java.lang.Iterable, java.lang.Iterable)
+ * @param left
+ * Resources we are to match in the left.
+ * @param right
+ * Resources we are to match in the right.
+ * @param origin
+ * Resources we are to match in the origin.
+ * @return The list of unique mappings this strategy managed to determine.
*/
public List<MatchResource> matchResources(Iterable<? extends Resource> left,
Iterable<? extends Resource> right, Iterable<? extends Resource> origin) {
final List<MatchResource> mappings = Lists.newArrayList();
+ final List<Resource> leftCopy = Lists.newArrayList(left);
final List<Resource> rightCopy = Lists.newArrayList(right);
final List<Resource> originCopy = Lists.newArrayList(origin);
- // Can we find matches for the left resource in either left or origin?
- for (Resource leftResource : left) {
- final Resource matchingRight = findMatch(leftResource, rightCopy);
- final Resource matchingOrigin = findMatch(leftResource, originCopy);
+ final Map<Resource, List<Resource>> leftRightMap = new LinkedHashMap<Resource, List<Resource>>();
+ final Map<Resource, List<Resource>> leftOriginMap = new LinkedHashMap<Resource, List<Resource>>();
+ final Map<Resource, List<Resource>> rightOriginMap = new LinkedHashMap<Resource, List<Resource>>();
- if (matchingRight != null || matchingOrigin != null) {
- rightCopy.remove(matchingRight);
- originCopy.remove(matchingOrigin);
- mappings.add(createMatchResource(leftResource, matchingRight, matchingOrigin));
- }
- }
+ for (Resource leftResource : leftCopy) {
+ final List<Resource> matchingRights = findMatches(leftResource, rightCopy);
+ leftRightMap.put(leftResource, matchingRights);
- // We no longer have to check in the left, but we may have matches of the right resources in the
- // origin list
+ final List<Resource> matchingOrigins = findMatches(leftResource, originCopy);
+ leftOriginMap.put(leftResource, matchingOrigins);
+ }
for (Resource rightResource : rightCopy) {
- final Resource matchingOrigin = findMatch(rightResource, originCopy);
- originCopy.remove(matchingOrigin);
+ final List<Resource> matchingLefts = findMatches(rightResource, leftCopy);
+ leftRightMap.put(rightResource, matchingLefts);
+
+ final List<Resource> matchingOrigins = findMatches(rightResource, originCopy);
+ rightOriginMap.put(rightResource, matchingOrigins);
+ }
+ for (Resource originResource : originCopy) {
+ final List<Resource> matchingLefts = findMatches(originResource, leftCopy);
+ leftOriginMap.put(originResource, matchingLefts);
+
+ final List<Resource> matchingRights = findMatches(originResource, rightCopy);
+ rightOriginMap.put(originResource, matchingRights);
+ }
+
+ for (Resource leftResource : leftCopy) {
+ List<Resource> rightObjects = leftRightMap.get(leftResource);
+
+ Resource rightResource = null;
+ Resource originResource = null;
- if (matchingOrigin != null) {
- mappings.add(createMatchResource(null, rightResource, matchingOrigin));
+ if (rightObjects.size() > 1) {
+ rightCopy.removeAll(rightObjects);
+ continue;
+ }
+
+ if (rightObjects.size() == 1) {
+ final Resource rightCandidate = rightObjects.get(0);
+ // check left
+ if (leftRightMap.get(rightCandidate).size() == 1) {
+ rightResource = rightCandidate;
+ }
+ }
+
+ // check origins
+ if (!originCopy.isEmpty()) {
+ Set<Resource> originObjects = Sets.newHashSet();
+ originObjects.addAll(leftOriginMap.get(leftResource));
+ if (rightResource != null) {
+ originObjects.addAll(rightOriginMap.get(rightResource));
+ }
+ if (originObjects.size() > 1) {
+ rightCopy.remove(rightResource);
+ continue;
+ }
+ if (originObjects.size() == 1) {
+ final Resource originCandidate = originObjects.iterator().next();
+ // check origin does not map to more
+ Set<Resource> mappedResources = Sets.newHashSet();
+ mappedResources.addAll(leftOriginMap.get(originCandidate));
+ mappedResources.addAll(rightOriginMap.get(originCandidate));
+ mappedResources.add(leftResource);
+ mappedResources.add(rightResource);
+ if (mappedResources.size() > 2) {
+ rightCopy.remove(rightResource);
+ continue;
+ } else {
+ originResource = originCandidate;
+ }
+ }
+ }
+ if (rightResource != null || originResource != null) {
+ mappings.add(createMatchResource(leftResource, rightResource, originResource));
+ rightCopy.remove(rightResource);
}
}
+ if (!originCopy.isEmpty()) {
+ for (Resource rightResource : rightCopy) {
+
+ Resource leftResource = null;
+ Resource originResource = null;
+
+ List<Resource> originObjects = rightOriginMap.get(rightResource);
+ if (originObjects.size() == 1) {
+ originResource = originObjects.get(0);
+ // check right side
+ if (rightOriginMap.get(originResource).size() > 1) {
+ continue;
+ }
+ // check left side
+ List<Resource> leftCandidates = leftOriginMap.get(originResource);
+ if (leftCandidates.size() > 1) {
+ continue;
+ } else if (leftCandidates.size() == 1) {
+ Resource leftCandidate = leftCandidates.get(0);
+
+ // check right and origin
+ if (leftOriginMap.get(leftCandidate).size() > 1) {
+ continue;
+ }
+ if (!leftRightMap.get(leftCandidate).isEmpty()) {
+ continue;
+ }
+ leftResource = leftCandidate;
+ }
+ mappings.add(createMatchResource(leftResource, rightResource, originResource));
+ }
+ }
+ }
return mappings;
}
/**
+ * Returns the first two matches of <code>reference</code> in <code>candidates</code>. This implementation
+ * will consider two Resources to be "matches" if their roots have IDs, and these IDs intersect.
+ * <p>
+ * Subclasses may return more than two elements if considered useful.
+ * </p>
+ *
+ * @param reference
+ * The reference resource.
+ * @param candidates
+ * The list of potential candidates that may match <code>reference</code>.
+ * @return The first two matches of <code>reference</code> in <code>candidates</code>. Empty list if none.
+ * @since 3.3
+ */
+ protected List<Resource> findMatches(Resource reference, Iterable<Resource> candidates) {
+ final Set<String> referenceIDs = getResourceIdentifiers(reference);
+ if (referenceIDs.isEmpty()) {
+ return Lists.newArrayList();
+ }
+
+ final List<Resource> matches = new ArrayList<Resource>(2);
+ final Iterator<Resource> candidateIterator = candidates.iterator();
+
+ // optimize for size 2 since we do not need more at the moment
+ while (candidateIterator.hasNext() && matches.size() < 2) {
+ final Resource candidate = candidateIterator.next();
+ final Set<String> candidateIDs = getResourceIdentifiers(candidate);
+ if (!candidateIDs.isEmpty() && !Sets.intersection(candidateIDs, referenceIDs).isEmpty()) {
+ matches.add(candidate);
+ }
+ }
+
+ return matches;
+ }
+
+ /**
* Returns the first match of <code>reference</code> in <code>candidates</code>. This implementation will
* consider two Resources to be "matches" if their roots have IDs, and these IDs are the same.
*
@@ -80,7 +218,9 @@ public class RootIDMatchingStrategy implements IResourceMatchingStrategy {
* The list of potential candidates that may match <code>reference</code>.
* @return The first match of <code>reference</code> in <code>candidates</code>. <code>null</code> if
* none.
+ * @deprecated use {@link RootIDMatchingStrategy#findMatches(Resource, Iterable)} instead.
*/
+ @Deprecated
protected Resource findMatch(Resource reference, Iterable<Resource> candidates) {
final Set<String> referenceIDs = getResourceIdentifiers(reference);
if (referenceIDs.isEmpty()) {

Back to the top