diff options
Diffstat (limited to 'Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/GraphStatistic.java')
-rw-r--r-- | Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/GraphStatistic.java | 201 |
1 files changed, 201 insertions, 0 deletions
diff --git a/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/GraphStatistic.java b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/GraphStatistic.java new file mode 100644 index 00000000..7bd1d899 --- /dev/null +++ b/Metrics/Metrics-Calculation/ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator/xtend-gen/ca/mcgill/ecse/dslreasoner/realistic/metrics/calculator/graph/GraphStatistic.java | |||
@@ -0,0 +1,201 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.realistic.metrics.calculator.graph; | ||
2 | |||
3 | import com.google.common.collect.ArrayListMultimap; | ||
4 | import com.google.common.collect.Multimap; | ||
5 | import java.util.Collection; | ||
6 | import java.util.HashMap; | ||
7 | import java.util.HashSet; | ||
8 | import java.util.List; | ||
9 | import java.util.Map; | ||
10 | import java.util.Set; | ||
11 | import java.util.function.Consumer; | ||
12 | import org.eclipse.emf.ecore.EObject; | ||
13 | import org.eclipse.xtext.xbase.lib.IterableExtensions; | ||
14 | import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; | ||
15 | |||
16 | @SuppressWarnings("all") | ||
17 | public class GraphStatistic { | ||
18 | private final HashMap<String, Multimap<EObject, EObject>> incomingEdges = new HashMap<String, Multimap<EObject, EObject>>(); | ||
19 | |||
20 | private final HashMap<String, Multimap<EObject, EObject>> outgoingEdges = new HashMap<String, Multimap<EObject, EObject>>(); | ||
21 | |||
22 | private final HashSet<String> edgeTypes = new HashSet<String>(); | ||
23 | |||
24 | private final HashMap<EObject, Set<String>> nodeToType = new HashMap<EObject, Set<String>>(); | ||
25 | |||
26 | /** | ||
27 | * Add an edge type to to the graph | ||
28 | * @param type: type to add | ||
29 | */ | ||
30 | public void addEdgeType(final String type) { | ||
31 | boolean _contains = this.edgeTypes.contains(type); | ||
32 | if (_contains) { | ||
33 | return; | ||
34 | } | ||
35 | this.edgeTypes.add(type); | ||
36 | this.incomingEdges.put(type, ArrayListMultimap.<EObject, EObject>create()); | ||
37 | this.outgoingEdges.put(type, ArrayListMultimap.<EObject, EObject>create()); | ||
38 | } | ||
39 | |||
40 | /** | ||
41 | * Add a node to the graph with one type in its type hierarchy | ||
42 | * @param node: node to add | ||
43 | */ | ||
44 | public void addNodeWithType(final EObject n, final String Type) { | ||
45 | HashSet<String> _hashSet = new HashSet<String>(); | ||
46 | Set<String> types = this.nodeToType.getOrDefault(n, _hashSet); | ||
47 | types.add(Type); | ||
48 | this.nodeToType.put(n, types); | ||
49 | } | ||
50 | |||
51 | public boolean containsNode(final EObject o) { | ||
52 | return this.nodeToType.containsKey(o); | ||
53 | } | ||
54 | |||
55 | public Set<String> getTypesForNode(final EObject o) { | ||
56 | HashSet<String> _hashSet = new HashSet<String>(); | ||
57 | return this.nodeToType.getOrDefault(o, _hashSet); | ||
58 | } | ||
59 | |||
60 | public void overwriteCurrentType(final EObject o, final String type) { | ||
61 | HashSet<String> _hashSet = new HashSet<String>(); | ||
62 | Set<String> typeSet = this.nodeToType.getOrDefault(o, _hashSet); | ||
63 | typeSet.clear(); | ||
64 | typeSet.add(type); | ||
65 | this.nodeToType.put(o, typeSet); | ||
66 | } | ||
67 | |||
68 | /** | ||
69 | * Add a node to the graph with all types in its type hierarchy | ||
70 | */ | ||
71 | public void addNodeWithAllTypes(final EObject n, final Set<String> types) { | ||
72 | this.nodeToType.put(n, types); | ||
73 | } | ||
74 | |||
75 | /** | ||
76 | * Add an edge to the graph | ||
77 | * @param source: source node | ||
78 | * @param target: target node | ||
79 | * @param type: type of the reference | ||
80 | */ | ||
81 | public void addEdge(final EObject source, final EObject target, final String type) { | ||
82 | this.outgoingEdges.get(type).put(source, target); | ||
83 | this.incomingEdges.get(type).put(target, source); | ||
84 | } | ||
85 | |||
86 | /** | ||
87 | * check if this graph contains a specific edge type | ||
88 | */ | ||
89 | public boolean containsEdgeType(final String typeName) { | ||
90 | if ((this.outgoingEdges.containsKey(typeName) && this.incomingEdges.containsKey(typeName))) { | ||
91 | return true; | ||
92 | } | ||
93 | return false; | ||
94 | } | ||
95 | |||
96 | /** | ||
97 | * remove references from the statistics, potentially remove the nodes associated with it | ||
98 | * @Param name: name of the reference | ||
99 | * @Param isContainment: if true then the corresponding nodes on the incoming side will also be removed | ||
100 | */ | ||
101 | public void removeReference(final String name, final boolean isContainment) { | ||
102 | boolean _contains = this.edgeTypes.contains(name); | ||
103 | boolean _not = (!_contains); | ||
104 | if (_not) { | ||
105 | return; | ||
106 | } | ||
107 | this.edgeTypes.remove(name); | ||
108 | Multimap<EObject, EObject> incomingSet = this.incomingEdges.remove(name); | ||
109 | this.outgoingEdges.remove(name); | ||
110 | if ((!isContainment)) { | ||
111 | return; | ||
112 | } | ||
113 | final Set<EObject> nodesToRemove = incomingSet.keySet(); | ||
114 | final Consumer<EObject> _function = (EObject it) -> { | ||
115 | this.nodeToType.remove(it); | ||
116 | }; | ||
117 | nodesToRemove.forEach(_function); | ||
118 | final Procedure1<Multimap<EObject, EObject>> _function_1 = (Multimap<EObject, EObject> refMap) -> { | ||
119 | final Consumer<EObject> _function_2 = (EObject it) -> { | ||
120 | refMap.removeAll(it); | ||
121 | }; | ||
122 | nodesToRemove.forEach(_function_2); | ||
123 | Collection<EObject> values = refMap.values(); | ||
124 | values.removeAll(nodesToRemove); | ||
125 | return; | ||
126 | }; | ||
127 | final Procedure1<Multimap<EObject, EObject>> removeForMultimap = _function_1; | ||
128 | IterableExtensions.<Multimap<EObject, EObject>>forEach(this.incomingEdges.values(), removeForMultimap); | ||
129 | IterableExtensions.<Multimap<EObject, EObject>>forEach(this.outgoingEdges.values(), removeForMultimap); | ||
130 | } | ||
131 | |||
132 | /** | ||
133 | * calculate the out degree for an object | ||
134 | */ | ||
135 | public int outDegree(final EObject o) { | ||
136 | int count = 0; | ||
137 | for (final String type : this.edgeTypes) { | ||
138 | int _count = count; | ||
139 | int _size = this.outgoingEdges.get(type).get(o).size(); | ||
140 | count = (_count + _size); | ||
141 | } | ||
142 | return count; | ||
143 | } | ||
144 | |||
145 | /** | ||
146 | * calculate the in degree of an object | ||
147 | */ | ||
148 | public int inDegree(final EObject o) { | ||
149 | int count = 0; | ||
150 | for (final String type : this.edgeTypes) { | ||
151 | int _count = count; | ||
152 | int _size = this.incomingEdges.get(type).get(o).size(); | ||
153 | count = (_count + _size); | ||
154 | } | ||
155 | return count; | ||
156 | } | ||
157 | |||
158 | /** | ||
159 | * calculate the dimentional degree of a node | ||
160 | */ | ||
161 | public int dimentionalDegree(final EObject o, final String type) { | ||
162 | int _size = this.incomingEdges.get(type).get(o).size(); | ||
163 | int _size_1 = this.outgoingEdges.get(type).get(o).size(); | ||
164 | return (_size + _size_1); | ||
165 | } | ||
166 | |||
167 | /** | ||
168 | * calculate the number of edge types for a given node. | ||
169 | */ | ||
170 | public int numOfEdgeTypes(final EObject o) { | ||
171 | int count = 0; | ||
172 | for (final String type : this.edgeTypes) { | ||
173 | int _dimentionalDegree = this.dimentionalDegree(o, type); | ||
174 | boolean _greaterThan = (_dimentionalDegree > 0); | ||
175 | if (_greaterThan) { | ||
176 | count++; | ||
177 | } | ||
178 | } | ||
179 | return count; | ||
180 | } | ||
181 | |||
182 | public List<String> getAllTypes() { | ||
183 | return IterableExtensions.<String>toList(this.edgeTypes); | ||
184 | } | ||
185 | |||
186 | public Map<EObject, Set<String>> getNodeToTypesMap() { | ||
187 | return this.nodeToType; | ||
188 | } | ||
189 | |||
190 | public List<EObject> getAllNodes() { | ||
191 | return IterableExtensions.<EObject>toList(this.nodeToType.keySet()); | ||
192 | } | ||
193 | |||
194 | public HashMap<String, Multimap<EObject, EObject>> getOutgoingEdges() { | ||
195 | return this.outgoingEdges; | ||
196 | } | ||
197 | |||
198 | public HashMap<String, Multimap<EObject, EObject>> incomingEdges() { | ||
199 | return this.incomingEdges; | ||
200 | } | ||
201 | } | ||