diff options
Diffstat (limited to 'subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/tuple/LeftInheritanceTuple4.java')
-rw-r--r-- | subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/tuple/LeftInheritanceTuple4.java | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/tuple/LeftInheritanceTuple4.java b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/tuple/LeftInheritanceTuple4.java new file mode 100644 index 00000000..4e50f1e1 --- /dev/null +++ b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/tuple/LeftInheritanceTuple4.java | |||
@@ -0,0 +1,88 @@ | |||
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 | import java.util.Objects; | ||
12 | |||
13 | /** | ||
14 | * @author Gabor Bergmann | ||
15 | * @since 1.7 | ||
16 | */ | ||
17 | public final class LeftInheritanceTuple4 extends BaseLeftInheritanceTuple { | ||
18 | private final Object localElement0; | ||
19 | private final Object localElement1; | ||
20 | private final Object localElement2; | ||
21 | private final Object localElement3; | ||
22 | |||
23 | protected LeftInheritanceTuple4(Tuple ancestor, Object localElement0, Object localElement1, Object localElement2, | ||
24 | Object localElement3) { | ||
25 | super(ancestor); | ||
26 | this.localElement0 = localElement0; | ||
27 | this.localElement1 = localElement1; | ||
28 | this.localElement2 = localElement2; | ||
29 | this.localElement3 = localElement3; | ||
30 | calcHash(); | ||
31 | } | ||
32 | |||
33 | @Override | ||
34 | public int getLocalSize() { | ||
35 | return 4; | ||
36 | } | ||
37 | |||
38 | @Override | ||
39 | public int getSize() { | ||
40 | return inheritedIndex + 4; | ||
41 | } | ||
42 | |||
43 | @Override | ||
44 | public Object get(int index) { | ||
45 | int local = index - inheritedIndex; | ||
46 | if (local < 0) | ||
47 | return ancestor.get(index); | ||
48 | else if (local == 0) return localElement0; | ||
49 | else if (local == 1) return localElement1; | ||
50 | else if (local == 2) return localElement2; | ||
51 | else if (local == 3) return localElement3; | ||
52 | else throw raiseIndexingError(index); | ||
53 | } | ||
54 | |||
55 | /** | ||
56 | * Optimized hash calculation | ||
57 | */ | ||
58 | @Override | ||
59 | void calcHash() { | ||
60 | final int PRIME = 31; | ||
61 | cachedHash = ancestor.hashCode(); | ||
62 | cachedHash = PRIME * cachedHash; | ||
63 | if (localElement0 != null) cachedHash += localElement0.hashCode(); | ||
64 | cachedHash = PRIME * cachedHash; | ||
65 | if (localElement1 != null) cachedHash += localElement1.hashCode(); | ||
66 | cachedHash = PRIME * cachedHash; | ||
67 | if (localElement2 != null) cachedHash += localElement2.hashCode(); | ||
68 | cachedHash = PRIME * cachedHash; | ||
69 | if (localElement3 != null) cachedHash += localElement3.hashCode(); | ||
70 | } | ||
71 | |||
72 | @Override | ||
73 | protected boolean localEquals(BaseLeftInheritanceTuple other) { | ||
74 | if (other instanceof LeftInheritanceTuple4) { | ||
75 | LeftInheritanceTuple4 lit = (LeftInheritanceTuple4)other; | ||
76 | return Objects.equals(this.localElement0, lit.localElement0) && | ||
77 | Objects.equals(this.localElement1, lit.localElement1) && | ||
78 | Objects.equals(this.localElement2, lit.localElement2) && | ||
79 | Objects.equals(this.localElement3, lit.localElement3); | ||
80 | } else { | ||
81 | return (4 == other.getLocalSize()) && | ||
82 | Objects.equals(localElement0, other.get(inheritedIndex)) && | ||
83 | Objects.equals(localElement1, other.get(inheritedIndex + 1)) && | ||
84 | Objects.equals(localElement2, other.get(inheritedIndex + 2)) && | ||
85 | Objects.equals(localElement3, other.get(inheritedIndex + 3)); | ||
86 | } | ||
87 | } | ||
88 | } | ||