diff options
Diffstat (limited to 'subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/tuple/BaseLeftInheritanceTuple.java')
-rw-r--r-- | subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/tuple/BaseLeftInheritanceTuple.java | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/tuple/BaseLeftInheritanceTuple.java b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/tuple/BaseLeftInheritanceTuple.java new file mode 100644 index 00000000..03f9ea89 --- /dev/null +++ b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/tuple/BaseLeftInheritanceTuple.java | |||
@@ -0,0 +1,65 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2017, Gabor Bergmann, IncQueryLabs Ltd. | ||
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.matchers.tuple; | ||
10 | |||
11 | /** | ||
12 | * Common functionality of left inheritance tuple implementations. | ||
13 | * | ||
14 | * <p>Left inheritance tuples inherit their first few elements from another tuple, | ||
15 | * and extend it with additional "local" elements. | ||
16 | * | ||
17 | * @author Gabor Bergmann | ||
18 | * @since 1.7 | ||
19 | */ | ||
20 | public abstract class BaseLeftInheritanceTuple extends Tuple { | ||
21 | |||
22 | /** | ||
23 | * The number of elements that aren't stored locally, but inherited from an ancestor Tuple instead. | ||
24 | */ | ||
25 | protected final int inheritedIndex; | ||
26 | /** | ||
27 | * This object contains the same elements as the ancestor on the first inheritedIndex positions | ||
28 | */ | ||
29 | protected final Tuple ancestor; | ||
30 | |||
31 | /** | ||
32 | * @param ancestor | ||
33 | */ | ||
34 | public BaseLeftInheritanceTuple(Tuple ancestor) { | ||
35 | super(); | ||
36 | this.ancestor = ancestor; | ||
37 | this.inheritedIndex = ancestor.getSize(); | ||
38 | } | ||
39 | |||
40 | /** | ||
41 | * @return the number of local (non-inherited) elements | ||
42 | */ | ||
43 | public abstract int getLocalSize(); | ||
44 | |||
45 | /** | ||
46 | * Optimized equals calculation (prediction: true, since hash values match) | ||
47 | */ | ||
48 | @Override | ||
49 | protected boolean internalEquals(ITuple other) { | ||
50 | if (other instanceof BaseLeftInheritanceTuple) { | ||
51 | BaseLeftInheritanceTuple blit = (BaseLeftInheritanceTuple) other; | ||
52 | if (blit.inheritedIndex == this.inheritedIndex) { | ||
53 | if (this.ancestor.equals(blit.ancestor)) { | ||
54 | return localEquals(blit); | ||
55 | } else return false; | ||
56 | } | ||
57 | } | ||
58 | return super.internalEquals(other); | ||
59 | } | ||
60 | |||
61 | /** | ||
62 | * Checks the equivalence of local elements only, after ancestor tuple has been determined to be equal. | ||
63 | */ | ||
64 | protected abstract boolean localEquals(BaseLeftInheritanceTuple other); | ||
65 | } | ||