1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
/*****************************************************************************
* Copyright (c) 2010 CEA LIST.
*
*
* 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:
* Tatiana Fesenko (CEA LIST) - Initial API and implementation
*
*****************************************************************************/
package org.eclipse.papyrus.uml.compare.element;
import org.eclipse.emf.compare.FactoryException;
import org.eclipse.emf.compare.match.engine.AbstractSimilarityChecker;
import org.eclipse.emf.compare.match.statistic.MetamodelFilter;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.papyrus.uml.compare.match.PapyrusMatchEngine;
/**
* The implementation of MatchEngine to compare two arbitrary elements, not nesseserily diagrams
*/
public class ElementContentMatchEngine extends PapyrusMatchEngine {
/** The my left. */
private final EObject myLeft;
/** The my right. */
private final EObject myRight;
/**
* Instantiates a new element content match engine.
*
* @param left the left
* @param right the right
*/
public ElementContentMatchEngine(EObject left, EObject right) {
this.myLeft = left;
this.myRight = right;
}
/* (non-Javadoc)
* @see org.eclipse.papyrus.uml.compare.match.PapyrusMatchEngine#prepareChecker()
*/
@Override
protected AbstractSimilarityChecker prepareChecker() {
return new AlwaysSimilarChecker(filter, super.prepareChecker());
}
/**
* The Class AlwaysSimilarChecker.
*/
private class AlwaysSimilarChecker extends AbstractSimilarityChecker {
/** The delegate. */
private AbstractSimilarityChecker delegate;
/**
* Instantiates a new always similar checker.
*
* @param filter the filter
* @param fallback the fallback
*/
public AlwaysSimilarChecker(MetamodelFilter filter, AbstractSimilarityChecker fallback) {
super(filter);
this.delegate = fallback;
}
/* (non-Javadoc)
* @see org.eclipse.emf.compare.match.engine.AbstractSimilarityChecker#isSimilar(org.eclipse.emf.ecore.EObject, org.eclipse.emf.ecore.EObject)
*/
/**
* The standard AbstractSimilarityChecker checks the parent of the elements,
* thus, compared elements won't be considered similar.
* To avoid this problem this method always returns true
**/
@Override
public boolean isSimilar(EObject obj1, EObject obj2) throws FactoryException {
return true;
}
/* (non-Javadoc)
* @see org.eclipse.emf.compare.match.engine.AbstractSimilarityChecker#init(org.eclipse.emf.ecore.EObject, org.eclipse.emf.ecore.EObject)
*/
@Override
public void init(EObject leftObject, EObject rightObject) throws FactoryException {
delegate.init(leftObject, rightObject);
}
/* (non-Javadoc)
* @see org.eclipse.emf.compare.match.engine.AbstractSimilarityChecker#init(org.eclipse.emf.ecore.resource.Resource, org.eclipse.emf.ecore.resource.Resource)
*/
@Override
public void init(Resource leftResource, Resource rightResource) throws FactoryException {
delegate.init(leftResource, rightResource);
}
/* (non-Javadoc)
* @see org.eclipse.emf.compare.match.engine.AbstractSimilarityChecker#absoluteMetric(org.eclipse.emf.ecore.EObject, org.eclipse.emf.ecore.EObject)
*/
@Override
public double absoluteMetric(EObject obj1, EObject obj2) throws FactoryException {
return delegate.absoluteMetric(obj1, obj2);
}
}
}
|