blob: b189c60e2909cdc16412c146da6e915fbe97052e (
plain) (
blame)
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
|
/*******************************************************************************
* Copyright (c) 2012 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.internal.spec;
import static com.google.common.collect.Iterables.concat;
import static com.google.common.collect.Iterables.transform;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
import java.util.List;
import org.eclipse.emf.compare.Comparison;
import org.eclipse.emf.compare.Diff;
import org.eclipse.emf.compare.Match;
import org.eclipse.emf.compare.impl.MatchImpl;
import org.eclipse.emf.compare.internal.SubMatchIterable;
import org.eclipse.emf.compare.utils.Objects;
import org.eclipse.emf.ecore.EObject;
/**
* This specialization of the {@link MatchImpl} class allows us to define the derived features and operations
* implementations.
*
* @author <a href="mailto:mikael.barbero@obeo.fr">Mikael Barbero</a>
*/
public class MatchSpec extends MatchImpl {
/**
* Function returning {@link #getDifferences() all DIFFERENCES} of the given match.
*/
private static final Function<Match, List<Diff>> DIFFERENCES = new Function<Match, List<Diff>>() {
public List<Diff> apply(Match match) {
if (match == null) {
return Lists.newArrayList();
}
return match.getDifferences();
}
};
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.compare.impl.MatchImpl#getComparison()
*/
@Override
public Comparison getComparison() {
Comparison ret = null;
EObject eContainer = eContainer();
while (!(eContainer instanceof Comparison) && eContainer != null) {
eContainer = eContainer.eContainer();
}
if (eContainer != null) {
ret = (Comparison)eContainer;
}
return ret;
}
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.compare.impl.MatchImpl#getAllSubmatches()
*/
@Override
public Iterable<Match> getAllSubmatches() {
return new SubMatchIterable(this);
}
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.compare.impl.MatchImpl#getAllDifferences()
*/
@Override
public Iterable<Diff> getAllDifferences() {
final Iterable<Diff> allSubDifferences = concat(transform(getAllSubmatches(), DIFFERENCES));
return concat(getDifferences(), allSubDifferences);
}
/**
* {@inheritDoc}
*
* @see org.eclipse.emf.ecore.impl.BasicEObjectImpl#toString()
*/
@SuppressWarnings("nls")
@Override
public String toString() {
// @formatter:off
return Objects.toStringHelper(this).add("left", EObjectUtil.getLabel(getLeft()))
.add("right", EObjectUtil.getLabel(getRight()))
.add("origin", EObjectUtil.getLabel(getOrigin()))
.add("#differences", Integer.valueOf(getDifferences().size()))
.add("#submatches", Integer.valueOf(getSubmatches().size())).toString();
// @formatter:on
}
}
|