diff options
Diffstat (limited to 'subprojects/viatra-runtime-base/src/main/java/tools/refinery/viatra/runtime/base/api/BaseIndexOptions.java')
-rw-r--r-- | subprojects/viatra-runtime-base/src/main/java/tools/refinery/viatra/runtime/base/api/BaseIndexOptions.java | 395 |
1 files changed, 0 insertions, 395 deletions
diff --git a/subprojects/viatra-runtime-base/src/main/java/tools/refinery/viatra/runtime/base/api/BaseIndexOptions.java b/subprojects/viatra-runtime-base/src/main/java/tools/refinery/viatra/runtime/base/api/BaseIndexOptions.java deleted file mode 100644 index 92663400..00000000 --- a/subprojects/viatra-runtime-base/src/main/java/tools/refinery/viatra/runtime/base/api/BaseIndexOptions.java +++ /dev/null | |||
@@ -1,395 +0,0 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2013, Abel Hegedus, Istvan Rath and Daniel Varro | ||
3 | * This program and the accompanying materials are made available under the | ||
4 | * terms of the Eclipse Public License v. 2.0 which is available at | ||
5 | * http://www.eclipse.org/legal/epl-v20.html. | ||
6 | * | ||
7 | * SPDX-License-Identifier: EPL-2.0 | ||
8 | *******************************************************************************/ | ||
9 | package tools.refinery.viatra.runtime.base.api; | ||
10 | |||
11 | import java.util.Objects; | ||
12 | |||
13 | import tools.refinery.viatra.runtime.base.api.filters.IBaseIndexFeatureFilter; | ||
14 | import tools.refinery.viatra.runtime.base.api.filters.IBaseIndexObjectFilter; | ||
15 | import tools.refinery.viatra.runtime.base.api.filters.IBaseIndexResourceFilter; | ||
16 | import tools.refinery.viatra.runtime.base.api.profiler.ProfilerMode; | ||
17 | |||
18 | /** | ||
19 | * The base index options indicate how the indices are built. | ||
20 | * | ||
21 | * <p> | ||
22 | * One of the options is to build indices in <em>wildcard mode</em>, meaning that all EClasses, EDataTypes, EReferences | ||
23 | * and EAttributes are indexed. This is convenient, but comes at a high memory cost. To save memory, one can disable | ||
24 | * <em>wildcard mode</em> and manually register those EClasses, EDataTypes, EReferences and EAttributes that should be | ||
25 | * indexed. | ||
26 | * </p> | ||
27 | * | ||
28 | * <p> | ||
29 | * Another choice is whether to build indices in <em>dynamic EMF mode</em>, meaning that types are identified by the | ||
30 | * String IDs that are ultimately derived from the nsURI of the EPackage. Multiple types with the same ID are treated as | ||
31 | * the same. This is useful if dynamic EMF is used, where there can be multiple copies (instantiations) of the same | ||
32 | * EPackage, representing essentially the same metamodel. If one disables <em>dynamic EMF mode</em>, an error is logged | ||
33 | * if duplicate EPackages with the same nsURI are encountered. | ||
34 | * </p> | ||
35 | * | ||
36 | * @author Abel Hegedus | ||
37 | * @noimplement This class is not intended to be subclasses outside of VIATRA runtime | ||
38 | * | ||
39 | */ | ||
40 | public class BaseIndexOptions { | ||
41 | |||
42 | /** | ||
43 | * | ||
44 | * By default, base indices will be constructed with wildcard mode set as false. | ||
45 | */ | ||
46 | protected static final IndexingLevel WILDCARD_MODE_DEFAULT = IndexingLevel.NONE; | ||
47 | /** | ||
48 | * | ||
49 | * By default, base indices will be constructed with only well-behaving features traversed. | ||
50 | */ | ||
51 | private static final boolean TRAVERSE_ONLY_WELLBEHAVING_DERIVED_FEATURES_DEFAULT = true; | ||
52 | /** | ||
53 | * | ||
54 | * By default, base indices will be constructed with dynamic EMF mode set as false. | ||
55 | */ | ||
56 | protected static final boolean DYNAMIC_EMF_MODE_DEFAULT = false; | ||
57 | |||
58 | /** | ||
59 | * | ||
60 | * By default, the scope will make the assumption that it is free from dangling edges. | ||
61 | * @since 1.6 | ||
62 | */ | ||
63 | protected static final boolean DANGLING_FREE_ASSUMPTION_DEFAULT = true; | ||
64 | |||
65 | /** | ||
66 | * By default, duplicate notifications are only logged. | ||
67 | * | ||
68 | * @since 1.6 | ||
69 | */ | ||
70 | protected static final boolean STRICT_NOTIFICATION_MODE_DEFAULT = true; | ||
71 | |||
72 | /** | ||
73 | * @since 2.3 | ||
74 | */ | ||
75 | protected static final ProfilerMode INDEX_PROFILER_MODE_DEFAULT = ProfilerMode.OFF; | ||
76 | |||
77 | /** | ||
78 | * @since 1.6 | ||
79 | */ | ||
80 | protected boolean danglingFreeAssumption = DANGLING_FREE_ASSUMPTION_DEFAULT; | ||
81 | protected boolean dynamicEMFMode = DYNAMIC_EMF_MODE_DEFAULT; | ||
82 | protected boolean traverseOnlyWellBehavingDerivedFeatures = TRAVERSE_ONLY_WELLBEHAVING_DERIVED_FEATURES_DEFAULT; | ||
83 | protected IndexingLevel wildcardMode = WILDCARD_MODE_DEFAULT; | ||
84 | protected IBaseIndexObjectFilter notifierFilterConfiguration; | ||
85 | protected IBaseIndexResourceFilter resourceFilterConfiguration; | ||
86 | /** | ||
87 | * @since 1.5 | ||
88 | */ | ||
89 | protected IBaseIndexFeatureFilter featureFilterConfiguration; | ||
90 | |||
91 | /** | ||
92 | * If strict notification mode is turned on, errors related to inconsistent notifications, e.g. duplicate deletions | ||
93 | * cause the entire Base index to be considered invalid, e.g. the query engine on top of the index should become | ||
94 | * tainted. | ||
95 | * | ||
96 | * @since 1.6 | ||
97 | */ | ||
98 | protected boolean strictNotificationMode = STRICT_NOTIFICATION_MODE_DEFAULT; | ||
99 | |||
100 | /** | ||
101 | * Returns whether base index profiling should be turned on. | ||
102 | * | ||
103 | * @since 2.3 | ||
104 | */ | ||
105 | protected ProfilerMode indexerProfilerMode = INDEX_PROFILER_MODE_DEFAULT; | ||
106 | |||
107 | /** | ||
108 | * Creates a base index options with the default values. | ||
109 | */ | ||
110 | public BaseIndexOptions() { | ||
111 | } | ||
112 | |||
113 | /** | ||
114 | * Creates a base index options using the provided values for dynamic EMF mode and wildcard mode. | ||
115 | * @since 1.4 | ||
116 | */ | ||
117 | public BaseIndexOptions(boolean dynamicEMFMode, IndexingLevel wildcardMode) { | ||
118 | this.dynamicEMFMode = dynamicEMFMode; | ||
119 | this.wildcardMode = wildcardMode; | ||
120 | } | ||
121 | |||
122 | /** | ||
123 | * | ||
124 | * @param dynamicEMFMode | ||
125 | * @since 0.9 | ||
126 | */ | ||
127 | public BaseIndexOptions withDynamicEMFMode(boolean dynamicEMFMode) { | ||
128 | BaseIndexOptions result = copy(); | ||
129 | result.dynamicEMFMode = dynamicEMFMode; | ||
130 | return result; | ||
131 | } | ||
132 | |||
133 | /** | ||
134 | * Sets the dangling edge handling property of the index option. If not set explicitly, it is considered as `true`. | ||
135 | * @param danglingFreeAssumption if true, | ||
136 | * the base index will assume that there are no dangling references | ||
137 | * (pointing out of scope or to proxies) | ||
138 | * @since 1.6 | ||
139 | */ | ||
140 | public BaseIndexOptions withDanglingFreeAssumption(boolean danglingFreeAssumption) { | ||
141 | BaseIndexOptions result = copy(); | ||
142 | result.danglingFreeAssumption = danglingFreeAssumption; | ||
143 | return result; | ||
144 | } | ||
145 | |||
146 | /** | ||
147 | * Adds an object-level filter to the indexer configuration. Warning - object-level indexing can increase indexing time | ||
148 | * noticeably. If possibly, use {@link #withResourceFilterConfiguration(IBaseIndexResourceFilter)} instead. | ||
149 | * | ||
150 | * @param filter | ||
151 | * @since 0.9 | ||
152 | */ | ||
153 | public BaseIndexOptions withObjectFilterConfiguration(IBaseIndexObjectFilter filter) { | ||
154 | BaseIndexOptions result = copy(); | ||
155 | result.notifierFilterConfiguration = filter; | ||
156 | return result; | ||
157 | } | ||
158 | |||
159 | /** | ||
160 | * @return the selected object filter configuration, or null if not set | ||
161 | */ | ||
162 | public IBaseIndexObjectFilter getObjectFilterConfiguration() { | ||
163 | return notifierFilterConfiguration; | ||
164 | } | ||
165 | |||
166 | /** | ||
167 | * Returns a copy of the configuration with a specified resource filter | ||
168 | * | ||
169 | * @param filter | ||
170 | * @since 0.9 | ||
171 | */ | ||
172 | public BaseIndexOptions withResourceFilterConfiguration(IBaseIndexResourceFilter filter) { | ||
173 | BaseIndexOptions result = copy(); | ||
174 | result.resourceFilterConfiguration = filter; | ||
175 | return result; | ||
176 | } | ||
177 | |||
178 | /** | ||
179 | * @return the selected resource filter, or null if not set | ||
180 | */ | ||
181 | public IBaseIndexResourceFilter getResourceFilterConfiguration() { | ||
182 | return resourceFilterConfiguration; | ||
183 | } | ||
184 | |||
185 | |||
186 | /** | ||
187 | * Returns a copy of the configuration with a specified feature filter | ||
188 | * | ||
189 | * @param filter | ||
190 | * @since 1.5 | ||
191 | */ | ||
192 | public BaseIndexOptions withFeatureFilterConfiguration(IBaseIndexFeatureFilter filter) { | ||
193 | BaseIndexOptions result = copy(); | ||
194 | result.featureFilterConfiguration = filter; | ||
195 | return result; | ||
196 | } | ||
197 | |||
198 | /** | ||
199 | * @return the selected feature filter, or null if not set | ||
200 | * @since 1.5 | ||
201 | */ | ||
202 | public IBaseIndexFeatureFilter getFeatureFilterConfiguration() { | ||
203 | return featureFilterConfiguration; | ||
204 | } | ||
205 | |||
206 | |||
207 | /** | ||
208 | * @return whether the base index option has dynamic EMF mode set | ||
209 | */ | ||
210 | public boolean isDynamicEMFMode() { | ||
211 | return dynamicEMFMode; | ||
212 | } | ||
213 | |||
214 | /** | ||
215 | * @return whether the base index makes the assumption that there can be no dangling edges | ||
216 | * @since 1.6 | ||
217 | */ | ||
218 | public boolean isDanglingFreeAssumption() { | ||
219 | return danglingFreeAssumption; | ||
220 | } | ||
221 | |||
222 | /** | ||
223 | * @return whether the base index option has traverse only well-behaving derived features set | ||
224 | */ | ||
225 | public boolean isTraverseOnlyWellBehavingDerivedFeatures() { | ||
226 | return traverseOnlyWellBehavingDerivedFeatures; | ||
227 | } | ||
228 | |||
229 | /** | ||
230 | * | ||
231 | * @param wildcardMode | ||
232 | * @since 1.4 | ||
233 | */ | ||
234 | public BaseIndexOptions withWildcardLevel(IndexingLevel wildcardLevel) { | ||
235 | BaseIndexOptions result = copy(); | ||
236 | result.wildcardMode = wildcardLevel; | ||
237 | return result; | ||
238 | } | ||
239 | |||
240 | /** | ||
241 | * @since 1.6 | ||
242 | */ | ||
243 | public BaseIndexOptions withStrictNotificationMode(boolean strictNotificationMode) { | ||
244 | BaseIndexOptions result = copy(); | ||
245 | result.strictNotificationMode = strictNotificationMode; | ||
246 | return result; | ||
247 | } | ||
248 | |||
249 | /** | ||
250 | * @since 2.3 | ||
251 | */ | ||
252 | public BaseIndexOptions withIndexProfilerMode(ProfilerMode indexerProfilerMode) { | ||
253 | BaseIndexOptions result = copy(); | ||
254 | result.indexerProfilerMode = indexerProfilerMode; | ||
255 | return result; | ||
256 | } | ||
257 | |||
258 | /** | ||
259 | * @return whether the base index option has wildcard mode set | ||
260 | */ | ||
261 | public boolean isWildcardMode() { | ||
262 | return wildcardMode == IndexingLevel.FULL; | ||
263 | } | ||
264 | |||
265 | /** | ||
266 | * @return the wildcardMode level | ||
267 | * @since 1.4 | ||
268 | */ | ||
269 | public IndexingLevel getWildcardLevel() { | ||
270 | return wildcardMode; | ||
271 | } | ||
272 | |||
273 | /** | ||
274 | * If strict notification mode is turned on, errors related to inconsistent notifications, e.g. duplicate deletions | ||
275 | * cause the entire Base index to be considered invalid, e.g. the query engine on top of the index should become | ||
276 | * tainted. | ||
277 | * | ||
278 | * @since 1.6 | ||
279 | */ | ||
280 | public boolean isStrictNotificationMode() { | ||
281 | return strictNotificationMode; | ||
282 | } | ||
283 | |||
284 | /** | ||
285 | * Returns whether base indexer profiling is enabled. The profiling causes some slowdown, but provides information | ||
286 | * about how much time the base indexer takes for initialization and updates. | ||
287 | * | ||
288 | * @since 2.3 | ||
289 | */ | ||
290 | public ProfilerMode getIndexerProfilerMode() { | ||
291 | return indexerProfilerMode; | ||
292 | } | ||
293 | |||
294 | /** | ||
295 | * Creates an independent copy of itself. The values of each option will be the same as this options. This method is | ||
296 | * used when a provided option must be copied to avoid external option changes afterward. | ||
297 | * | ||
298 | * @return the copy of this options | ||
299 | */ | ||
300 | public BaseIndexOptions copy() { | ||
301 | BaseIndexOptions baseIndexOptions = new BaseIndexOptions(this.dynamicEMFMode, this.wildcardMode); | ||
302 | baseIndexOptions.danglingFreeAssumption = this.danglingFreeAssumption; | ||
303 | baseIndexOptions.traverseOnlyWellBehavingDerivedFeatures = this.traverseOnlyWellBehavingDerivedFeatures; | ||
304 | baseIndexOptions.notifierFilterConfiguration = this.notifierFilterConfiguration; | ||
305 | baseIndexOptions.resourceFilterConfiguration = this.resourceFilterConfiguration; | ||
306 | baseIndexOptions.featureFilterConfiguration = this.featureFilterConfiguration; | ||
307 | baseIndexOptions.strictNotificationMode = this.strictNotificationMode; | ||
308 | baseIndexOptions.indexerProfilerMode = this.indexerProfilerMode; | ||
309 | return baseIndexOptions; | ||
310 | } | ||
311 | |||
312 | @Override | ||
313 | public int hashCode() { | ||
314 | return Objects.hash(dynamicEMFMode, notifierFilterConfiguration, resourceFilterConfiguration, | ||
315 | featureFilterConfiguration, traverseOnlyWellBehavingDerivedFeatures, wildcardMode, strictNotificationMode, | ||
316 | danglingFreeAssumption, indexerProfilerMode); | ||
317 | } | ||
318 | |||
319 | @Override | ||
320 | public boolean equals(Object obj) { | ||
321 | if (this == obj) | ||
322 | return true; | ||
323 | if (obj == null) | ||
324 | return false; | ||
325 | if (!(obj instanceof BaseIndexOptions)) | ||
326 | return false; | ||
327 | BaseIndexOptions other = (BaseIndexOptions) obj; | ||
328 | if (dynamicEMFMode != other.dynamicEMFMode) | ||
329 | return false; | ||
330 | if (danglingFreeAssumption != other.danglingFreeAssumption) | ||
331 | return false; | ||
332 | if (notifierFilterConfiguration == null) { | ||
333 | if (other.notifierFilterConfiguration != null) | ||
334 | return false; | ||
335 | } else if (!notifierFilterConfiguration | ||
336 | .equals(other.notifierFilterConfiguration)) | ||
337 | return false; | ||
338 | if (resourceFilterConfiguration == null) { | ||
339 | if (other.resourceFilterConfiguration != null) | ||
340 | return false; | ||
341 | } else if (!resourceFilterConfiguration | ||
342 | .equals(other.resourceFilterConfiguration)){ | ||
343 | return false; | ||
344 | } | ||
345 | |||
346 | if (featureFilterConfiguration == null) { | ||
347 | if (other.featureFilterConfiguration != null) | ||
348 | return false; | ||
349 | } else if (!featureFilterConfiguration | ||
350 | .equals(other.featureFilterConfiguration)){ | ||
351 | return false; | ||
352 | } | ||
353 | |||
354 | if (traverseOnlyWellBehavingDerivedFeatures != other.traverseOnlyWellBehavingDerivedFeatures) | ||
355 | return false; | ||
356 | if (wildcardMode != other.wildcardMode) | ||
357 | return false; | ||
358 | if (strictNotificationMode != other.strictNotificationMode) { | ||
359 | return false; | ||
360 | } | ||
361 | if (indexerProfilerMode != other.indexerProfilerMode) { | ||
362 | return false; | ||
363 | } | ||
364 | return true; | ||
365 | } | ||
366 | |||
367 | |||
368 | @Override | ||
369 | public String toString() { | ||
370 | StringBuilder sb = new StringBuilder(); | ||
371 | appendModifier(sb, dynamicEMFMode, DYNAMIC_EMF_MODE_DEFAULT, "dynamicEMF"); | ||
372 | appendModifier(sb, wildcardMode, WILDCARD_MODE_DEFAULT, "wildcard"); | ||
373 | appendModifier(sb, danglingFreeAssumption, DANGLING_FREE_ASSUMPTION_DEFAULT, "danglingFreeAssumption"); | ||
374 | appendModifier(sb, traverseOnlyWellBehavingDerivedFeatures, TRAVERSE_ONLY_WELLBEHAVING_DERIVED_FEATURES_DEFAULT, "wellBehavingOnly"); | ||
375 | appendModifier(sb, strictNotificationMode, STRICT_NOTIFICATION_MODE_DEFAULT, "strictNotificationMode"); | ||
376 | appendModifier(sb, indexerProfilerMode, INDEX_PROFILER_MODE_DEFAULT, "indexerProfilerMode"); | ||
377 | appendModifier(sb, notifierFilterConfiguration, null, "notifierFilter="); | ||
378 | appendModifier(sb, resourceFilterConfiguration, null, "resourceFilter="); | ||
379 | appendModifier(sb, featureFilterConfiguration, null, "featureFilterConfiguration="); | ||
380 | final String result = sb.toString(); | ||
381 | return result.isEmpty() ? "defaults" : result; | ||
382 | } | ||
383 | |||
384 | private static void appendModifier(StringBuilder sb, Object actualValue, Object expectedValue, String switchName) { | ||
385 | if (Objects.equals(expectedValue, actualValue)) { | ||
386 | // silent | ||
387 | } else { | ||
388 | sb.append(Boolean.FALSE.equals(actualValue) ? '-' : '+'); | ||
389 | sb.append(switchName); | ||
390 | if (! (actualValue instanceof Boolean)) | ||
391 | sb.append(actualValue); | ||
392 | } | ||
393 | } | ||
394 | |||
395 | } | ||