blob: 304821d67666fd63f6c76305825c54a038fe3472 (
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
|
/*******************************************************************************
* Copyright (c) 2016, 2019 Chalmers | University of Gothenburg, rt-labs and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Chalmers | University of Gothenburg and rt-labs - initial API and implementation and/or initial documentation
* Chalmers | University of Gothenburg - additional features, updated API
*******************************************************************************/
package org.eclipse.capra.core.adapters;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import org.eclipse.capra.core.helpers.EMFHelper;
import org.eclipse.emf.ecore.EObject;
/**
* An minimal abstraction of a traceability link used in
* {@link TraceMetaModelAdapter}, to retain independence of a concrete trace
* metamodel.
*
* @author Anthony Anjorin, Salome Maro
*/
public class Connection {
private EObject origin;
private List<EObject> targets;
private EObject tlink;
public Connection(EObject origin, List<EObject> targets, EObject tlink) {
this.origin = origin;
this.targets = targets;
this.tlink = tlink;
}
public EObject getOrigin() {
return origin;
}
public List<EObject> getTargets() {
return targets;
}
public EObject getTlink() {
return tlink;
}
@Override
public boolean equals(Object object) {
if (object == null) {
return false;
}
if (!(object instanceof Connection)) {
return false;
}
if (object == this) {
return true;
}
Connection connection = (Connection) object;
List<EObject> allFirstElements = new ArrayList<>(this.getTargets());
allFirstElements.add(this.getOrigin());
List<EObject> allSecondElements = new ArrayList<>(connection.getTargets());
allSecondElements.add(connection.getOrigin());
String firstTraceType = EMFHelper.getIdentifier(this.getTlink().eClass());
String secondTracetype = EMFHelper.getIdentifier(connection.getTlink().eClass());
if (!(firstTraceType.equals(secondTracetype))) {
return false;
}
List<String> firstElementsIds = allFirstElements.stream().map(EMFHelper::getIdentifier)
.collect(Collectors.toList());
List<String> secondElementsIds = allSecondElements.stream().map(EMFHelper::getIdentifier)
.collect(Collectors.toList());
return (firstElementsIds.containsAll(secondElementsIds) && secondElementsIds.containsAll(firstElementsIds));
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((origin == null) ? 0 : EMFHelper.getIdentifier(origin).hashCode());
result = prime * result
+ ((targets == null) ? 0 : targets.stream().mapToInt(e -> EMFHelper.getIdentifier(e).hashCode()).sum());
result = prime * result + ((tlink == null) ? 0 : tlink.hashCode());
return result;
}
}
|