diff options
Diffstat (limited to 'subprojects/viatra-runtime-matchers/src/main/java/tools/refinery/viatra/runtime/matchers/util/Direction.java')
-rw-r--r-- | subprojects/viatra-runtime-matchers/src/main/java/tools/refinery/viatra/runtime/matchers/util/Direction.java | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime-matchers/src/main/java/tools/refinery/viatra/runtime/matchers/util/Direction.java b/subprojects/viatra-runtime-matchers/src/main/java/tools/refinery/viatra/runtime/matchers/util/Direction.java new file mode 100644 index 00000000..88f7ec00 --- /dev/null +++ b/subprojects/viatra-runtime-matchers/src/main/java/tools/refinery/viatra/runtime/matchers/util/Direction.java | |||
@@ -0,0 +1,61 @@ | |||
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 | /** | ||
12 | * Indicates whether a propagated update event signals the insertion or deletion of an element | ||
13 | * | ||
14 | * @author Gabor Bergmann | ||
15 | */ | ||
16 | public enum Direction { | ||
17 | INSERT, DELETE; | ||
18 | |||
19 | /** | ||
20 | * @since 2.4 | ||
21 | */ | ||
22 | public Direction opposite() { | ||
23 | switch (this) { | ||
24 | case INSERT: | ||
25 | return DELETE; | ||
26 | default: | ||
27 | return INSERT; | ||
28 | } | ||
29 | } | ||
30 | |||
31 | /** | ||
32 | * @since 2.4 | ||
33 | */ | ||
34 | public char asSign() { | ||
35 | switch (this) { | ||
36 | case INSERT: | ||
37 | return '+'; | ||
38 | default: | ||
39 | return '-'; | ||
40 | } | ||
41 | } | ||
42 | |||
43 | /** | ||
44 | * Returns the direction that is the product of this direction and the other direction. | ||
45 | * | ||
46 | * DELETE x DELETE = INSERT | ||
47 | * DELETE x INSERT = DELETE | ||
48 | * INSERT x DELETE = DELETE | ||
49 | * INSERT x INSERT = INSERT | ||
50 | * @since 2.4 | ||
51 | */ | ||
52 | public Direction multiply(final Direction other) { | ||
53 | switch (this) { | ||
54 | case DELETE: | ||
55 | return other.opposite(); | ||
56 | default: | ||
57 | return other; | ||
58 | } | ||
59 | } | ||
60 | |||
61 | } | ||