diff options
Diffstat (limited to 'subprojects/viatra-runtime-base/src/main/java/tools/refinery/viatra/runtime/base/api/IndexingLevel.java')
-rw-r--r-- | subprojects/viatra-runtime-base/src/main/java/tools/refinery/viatra/runtime/base/api/IndexingLevel.java | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime-base/src/main/java/tools/refinery/viatra/runtime/base/api/IndexingLevel.java b/subprojects/viatra-runtime-base/src/main/java/tools/refinery/viatra/runtime/base/api/IndexingLevel.java new file mode 100644 index 00000000..df5c59f5 --- /dev/null +++ b/subprojects/viatra-runtime-base/src/main/java/tools/refinery/viatra/runtime/base/api/IndexingLevel.java | |||
@@ -0,0 +1,113 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2016, Grill Balázs, IncQueryLabs | ||
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 tools.refinery.viatra.runtime.matchers.context.IndexingService; | ||
12 | |||
13 | import java.util.Set; | ||
14 | |||
15 | /** | ||
16 | * The values of this enum denotes the level of indexing the base indexer is capable of. | ||
17 | * | ||
18 | * @author Grill Balázs | ||
19 | * @since 1.4 | ||
20 | * | ||
21 | */ | ||
22 | public enum IndexingLevel { | ||
23 | |||
24 | /** | ||
25 | * No indexing is performed | ||
26 | */ | ||
27 | NONE, | ||
28 | |||
29 | /** | ||
30 | * Only cardinality information is stored. This indexing level makes possible to calculate | ||
31 | * results of {@link NavigationHelper#countAllInstances(org.eclipse.emf.ecore.EClass)}, {@link NavigationHelper#countFeatures(org.eclipse.emf.ecore.EStructuralFeature)} | ||
32 | * and {@link NavigationHelper#countDataTypeInstances(org.eclipse.emf.ecore.EDataType)} with minimal memory footprint. | ||
33 | */ | ||
34 | STATISTICS, | ||
35 | |||
36 | /** | ||
37 | * Notifications are dispatched about the changes | ||
38 | */ | ||
39 | NOTIFICATIONS, | ||
40 | |||
41 | /** | ||
42 | * Cardinality information is stored and live notifications are dispatched | ||
43 | */ | ||
44 | BOTH, | ||
45 | |||
46 | /** | ||
47 | * Full indexing is performed, set of instances is available | ||
48 | */ | ||
49 | FULL | ||
50 | |||
51 | ; | ||
52 | |||
53 | private static final IndexingLevel[][] mergeTable = { | ||
54 | /* NONE STATISTICS NOTIFICATIONS BOTH FULL*/ | ||
55 | /* NONE */{ NONE, STATISTICS, NOTIFICATIONS, BOTH, FULL}, | ||
56 | /* STATISTICS */{ STATISTICS, STATISTICS, BOTH, BOTH, FULL}, | ||
57 | /* NOTIFICATIONS */{ NOTIFICATIONS, BOTH, NOTIFICATIONS, BOTH, FULL}, | ||
58 | /* BOTH */{ BOTH, BOTH, BOTH, BOTH, FULL}, | ||
59 | /* FULL */{ FULL, FULL, FULL, FULL, FULL} | ||
60 | }; | ||
61 | |||
62 | public static IndexingLevel toLevel(IndexingService service){ | ||
63 | switch(service){ | ||
64 | case INSTANCES: | ||
65 | return IndexingLevel.FULL; | ||
66 | case NOTIFICATIONS: | ||
67 | return IndexingLevel.NOTIFICATIONS; | ||
68 | case STATISTICS: | ||
69 | return IndexingLevel.STATISTICS; | ||
70 | default: | ||
71 | return IndexingLevel.NONE; | ||
72 | } | ||
73 | } | ||
74 | |||
75 | public static IndexingLevel toLevel(Set<IndexingService> services){ | ||
76 | IndexingLevel result = NONE; | ||
77 | for(IndexingService service : services){ | ||
78 | result = result.merge(toLevel(service)); | ||
79 | } | ||
80 | return result; | ||
81 | } | ||
82 | |||
83 | /** | ||
84 | * Merge this level with the given other level, The resulting indexing level will provide the | ||
85 | * functionality which conforms to both given levels. | ||
86 | */ | ||
87 | public IndexingLevel merge(IndexingLevel other){ | ||
88 | if (other == null) return this; | ||
89 | return mergeTable[this.ordinal()][other.ordinal()]; | ||
90 | } | ||
91 | |||
92 | /** | ||
93 | * Tells whether the indexer shall perform separate statistics calculation for this level | ||
94 | */ | ||
95 | public boolean hasStatistics() { | ||
96 | return this == IndexingLevel.BOTH || this == IndexingLevel.STATISTICS || this == IndexingLevel.FULL; | ||
97 | } | ||
98 | |||
99 | /** | ||
100 | * Tells whether the indexer shall perform instance indexing | ||
101 | */ | ||
102 | public boolean hasInstances(){ | ||
103 | return this == IndexingLevel.FULL; | ||
104 | } | ||
105 | |||
106 | /** | ||
107 | * Returns whether the current indexing level includes all features from the parameter level | ||
108 | * @since 1.5 | ||
109 | */ | ||
110 | public boolean providesLevel(IndexingLevel level) { | ||
111 | return this.merge(level) == this; | ||
112 | } | ||
113 | } | ||