diff options
Diffstat (limited to 'subprojects/viatra-runtime-matchers/src/main/java/tools/refinery/viatra/runtime/matchers/util/Signed.java')
-rw-r--r-- | subprojects/viatra-runtime-matchers/src/main/java/tools/refinery/viatra/runtime/matchers/util/Signed.java | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime-matchers/src/main/java/tools/refinery/viatra/runtime/matchers/util/Signed.java b/subprojects/viatra-runtime-matchers/src/main/java/tools/refinery/viatra/runtime/matchers/util/Signed.java new file mode 100644 index 00000000..8f8bc228 --- /dev/null +++ b/subprojects/viatra-runtime-matchers/src/main/java/tools/refinery/viatra/runtime/matchers/util/Signed.java | |||
@@ -0,0 +1,60 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2019, Tamas Szabo, itemis AG, Gabor Bergmann, IncQuery Labs 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.util; | ||
10 | |||
11 | import java.util.Objects; | ||
12 | |||
13 | /** | ||
14 | * A piece of data associated with a direction. | ||
15 | * | ||
16 | * @author Tamas Szabo | ||
17 | * @since 2.4 | ||
18 | */ | ||
19 | public class Signed<Payload extends Comparable<Payload>> { | ||
20 | |||
21 | private final Payload payload; | ||
22 | private final Direction direction; | ||
23 | |||
24 | public Signed(final Direction direction, final Payload payload) { | ||
25 | this.payload = payload; | ||
26 | this.direction = direction; | ||
27 | } | ||
28 | |||
29 | public Payload getPayload() { | ||
30 | return payload; | ||
31 | } | ||
32 | |||
33 | public Direction getDirection() { | ||
34 | return direction; | ||
35 | } | ||
36 | |||
37 | @Override | ||
38 | public int hashCode() { | ||
39 | return Objects.hash(direction, payload); | ||
40 | } | ||
41 | |||
42 | @Override | ||
43 | public boolean equals(final Object obj) { | ||
44 | if (this == obj) { | ||
45 | return true; | ||
46 | } else if (obj == null || this.getClass() != obj.getClass()) { | ||
47 | return false; | ||
48 | } else { | ||
49 | @SuppressWarnings("rawtypes") | ||
50 | final Signed other = (Signed) obj; | ||
51 | return direction == other.direction && Objects.equals(payload, other.payload); | ||
52 | } | ||
53 | } | ||
54 | |||
55 | @Override | ||
56 | public String toString() { | ||
57 | return this.direction.asSign() + this.payload.toString(); | ||
58 | } | ||
59 | |||
60 | } \ No newline at end of file | ||