-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRelation.java
135 lines (106 loc) · 3.41 KB
/
Relation.java
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package fr.kriszt.theo.relations;
import fr.kriszt.theo.NodeEntities.TypeEntity;
import java.util.HashSet;
import java.util.Set;
public class Relation {
private String inputType;
private String outputType;
private Set<String> inMethodsNames = new HashSet<>();
private Set<String> outMethodsNames = new HashSet<>();
private int count;
private static Set<Relation> allRelations = new HashSet<>();
public Relation( String in, String out ){
if (in.compareTo(out) < 0){
inputType = in;
outputType = out;
} else {
inputType = out;
outputType = in;
}
count = 1;
}
public Relation(String a, String b, int i) {
this(a, b);
count = i;
}
public static void setAllRelations(Set<Relation> aGarder) {
allRelations = aGarder;
}
public void addMethod(String mn, String callingType){
if (callingType.equals(inputType)){
inMethodsNames.add(mn);
}else outMethodsNames.add(mn);
}
public static Relation addRelation(String type1, String type2 ){
Relation targetRelation = null;
for (Relation r : allRelations){
if (
(type1.equals(r.inputType) && type2.equals(r.outputType)) ||
(type1.equals(r.outputType) && type2.equals(r.inputType))
){
// Relation already exists
targetRelation = r;
break;
}
}
if (targetRelation != null){
targetRelation.count++;
return targetRelation;
}else {
targetRelation = new Relation(type1, type2);
allRelations.add(targetRelation);
return targetRelation;
}
}
public static Set<Relation> getAllRelations() {
return allRelations;
}
@Override
public String toString(){
return inputType + " ==> " + outputType + " [" + count + " time" + (count > 1 ? "s" : "") + "]";
}
public static void filterOutsideRelations() {
Set<TypeEntity> declaredTypes = TypeEntity.getDeclaredTypes();
Set<Relation> internalRelations = new HashSet<>();
for (Relation r : allRelations){
for (TypeEntity te : declaredTypes){
if (te.toString().equals(r.outputType)){
internalRelations.add(r);
}
}
}
allRelations = internalRelations;
}
public String getInputType() {
return inputType;
}
public String getOutputType() {
return outputType;
}
int getCount() {
return count;
}
public Set<String> getIncomingMethods() {
return inMethodsNames;
}
public Set<String> getOutcomingMethods() {
return outMethodsNames;
}
void setInType(String next) {
if (outputType.equals(next))
throw new IllegalArgumentException("Reference cyclique");
this.inputType = next;
}
void setOutType(String next) {
if (inputType.equals(next))
throw new IllegalArgumentException("Reference cyclique");
this.outputType = next;
}
@Override
public boolean equals(Object o) {
boolean res = o instanceof Relation &&
inputType.equals(((Relation) o).inputType) &&
outputType.equals(((Relation) o).outputType);
return res;
}
}