diff options
Diffstat (limited to 'subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/context/InputKeyImplication.java')
-rw-r--r-- | subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/context/InputKeyImplication.java | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/context/InputKeyImplication.java b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/context/InputKeyImplication.java new file mode 100644 index 00000000..2a403810 --- /dev/null +++ b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/matchers/context/InputKeyImplication.java | |||
@@ -0,0 +1,103 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2015, Bergmann Gabor, 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.matchers.context; | ||
10 | |||
11 | import java.util.ArrayList; | ||
12 | import java.util.Collections; | ||
13 | import java.util.List; | ||
14 | |||
15 | /** | ||
16 | * Data object representing the implication of an input key, in use cases including edge supertypes, edge opposites, node type constraints, etc. | ||
17 | * | ||
18 | * <p> Each instance tuple of the <i>implying input key</i> (if given) implies the presence of an instance tuple of the <i>implied input key</i> consisting of elements of the original tuple at given positions. | ||
19 | * When the input key is null, it is not an input constraint but some other source that implies input keys. | ||
20 | * | ||
21 | * <p> The implication is an immutable data object. | ||
22 | * | ||
23 | * @author Bergmann Gabor | ||
24 | * | ||
25 | */ | ||
26 | public final class InputKeyImplication { | ||
27 | private IInputKey implyingKey; | ||
28 | private IInputKey impliedKey; | ||
29 | private List<Integer> impliedIndices; | ||
30 | |||
31 | /** | ||
32 | * Optional. Instance tuples of this input key imply an instance tuple of another key. | ||
33 | * Sometimes it is not an input key that implies other input keys, so this attribute can be null. | ||
34 | */ | ||
35 | public IInputKey getImplyingKey() { | ||
36 | return implyingKey; | ||
37 | } | ||
38 | /** | ||
39 | * An instance tuple of this input key is implied by another key. | ||
40 | */ | ||
41 | public IInputKey getImpliedKey() { | ||
42 | return impliedKey; | ||
43 | } | ||
44 | /** | ||
45 | * The implied instance tuple consists of the values in the implying tuple at these indices. | ||
46 | */ | ||
47 | public List<Integer> getImpliedIndices() { | ||
48 | return impliedIndices; | ||
49 | } | ||
50 | /** | ||
51 | * @param implyingKey instance tuples of this input key imply an instance tuple of the other key. | ||
52 | * @param impliedKey instance tuple of this input key is implied by the other key. | ||
53 | * @param implyingIndices the implied instance tuple consists of the values in the implying tuple at these indices. | ||
54 | */ | ||
55 | public InputKeyImplication(IInputKey implyingKey, IInputKey impliedKey, | ||
56 | List<Integer> implyingIndices) { | ||
57 | super(); | ||
58 | this.implyingKey = implyingKey; | ||
59 | this.impliedKey = impliedKey; | ||
60 | this.impliedIndices = Collections.unmodifiableList(new ArrayList<>(implyingIndices)); | ||
61 | } | ||
62 | |||
63 | @Override | ||
64 | public int hashCode() { | ||
65 | final int prime = 31; | ||
66 | int result = 1; | ||
67 | result = prime * result | ||
68 | + ((impliedIndices == null) ? 0 : impliedIndices.hashCode()); | ||
69 | result = prime * result | ||
70 | + ((impliedKey == null) ? 0 : impliedKey.hashCode()); | ||
71 | result = prime * result | ||
72 | + ((implyingKey == null) ? 0 : implyingKey.hashCode()); | ||
73 | return result; | ||
74 | } | ||
75 | @Override | ||
76 | public boolean equals(Object obj) { | ||
77 | if (this == obj) | ||
78 | return true; | ||
79 | if (obj == null) | ||
80 | return false; | ||
81 | if (!(obj instanceof InputKeyImplication)) | ||
82 | return false; | ||
83 | InputKeyImplication other = (InputKeyImplication) obj; | ||
84 | if (impliedIndices == null) { | ||
85 | if (other.impliedIndices != null) | ||
86 | return false; | ||
87 | } else if (!impliedIndices.equals(other.impliedIndices)) | ||
88 | return false; | ||
89 | if (impliedKey == null) { | ||
90 | if (other.impliedKey != null) | ||
91 | return false; | ||
92 | } else if (!impliedKey.equals(other.impliedKey)) | ||
93 | return false; | ||
94 | if (implyingKey == null) { | ||
95 | if (other.implyingKey != null) | ||
96 | return false; | ||
97 | } else if (!implyingKey.equals(other.implyingKey)) | ||
98 | return false; | ||
99 | return true; | ||
100 | } | ||
101 | |||
102 | |||
103 | } | ||