diff options
Diffstat (limited to 'subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/api/IPatternMatch.java')
-rw-r--r-- | subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/api/IPatternMatch.java | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/api/IPatternMatch.java b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/api/IPatternMatch.java new file mode 100644 index 00000000..be6467cc --- /dev/null +++ b/subprojects/viatra-runtime/src/main/java/tools/refinery/viatra/runtime/api/IPatternMatch.java | |||
@@ -0,0 +1,107 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2004-2010 Gabor Bergmann 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 | |||
10 | package tools.refinery.viatra.runtime.api; | ||
11 | |||
12 | import java.util.List; | ||
13 | |||
14 | /** | ||
15 | * Generic interface for a single match of a pattern. Each instance is a (partial) substitution of pattern parameters, | ||
16 | * essentially a parameter to value mapping. | ||
17 | * | ||
18 | * <p>Can also represent a partial match; unsubstituted parameters are assigned to null. Pattern matchers must never return | ||
19 | * a partial match, but they accept partial matches as method parameters. | ||
20 | * | ||
21 | * @author Bergmann Gábor | ||
22 | */ | ||
23 | public interface IPatternMatch extends Cloneable /* , Map<String, Object> */{ | ||
24 | /** @return the pattern for which this is a match. */ | ||
25 | public IQuerySpecification<? extends ViatraQueryMatcher<? extends IPatternMatch>> specification(); | ||
26 | |||
27 | /** Identifies the name of the pattern for which this is a match. */ | ||
28 | public String patternName(); | ||
29 | |||
30 | /** Returns the list of symbolic parameter names. */ | ||
31 | public List<String> parameterNames(); | ||
32 | |||
33 | /** Returns the value of the parameter with the given name, or null if name is invalid. */ | ||
34 | public Object get(String parameterName); | ||
35 | |||
36 | /** Returns the value of the parameter at the given position, or null if position is invalid. */ | ||
37 | public Object get(int position); | ||
38 | |||
39 | /** | ||
40 | * Sets the parameter with the given name to the given value. | ||
41 | * | ||
42 | * <p> Works only if match is mutable. See {@link #isMutable()}. | ||
43 | * | ||
44 | * @returns true if successful, false if parameter name is invalid. May also fail and return false if the value type | ||
45 | * is incompatible. | ||
46 | * @throws UnsupportedOperationException if match is not mutable. | ||
47 | */ | ||
48 | public boolean set(String parameterName, Object newValue); | ||
49 | |||
50 | /** | ||
51 | * Sets the parameter at the given position to the given value. | ||
52 | * | ||
53 | * <p> Works only if match is mutable. See {@link #isMutable()}. | ||
54 | * | ||
55 | * @returns true if successful, false if position is invalid. May also fail and return false if the value type is | ||
56 | * incompatible. | ||
57 | * @throws UnsupportedOperationException if match is not mutable. | ||
58 | */ | ||
59 | public boolean set(int position, Object newValue); | ||
60 | |||
61 | /** | ||
62 | * Returns whether the match object can be further modified after its creation. Setters work only if the match is mutable. | ||
63 | * | ||
64 | * <p>Matches computed by the pattern matchers are not mutable, so that the match set cannot be modified externally. | ||
65 | * Partial matches used as matcher input, however, can be mutable; such match objects can be created using {@link ViatraQueryMatcher#newEmptyMatch()}. | ||
66 | * | ||
67 | * @return whether the match can be modified | ||
68 | */ | ||
69 | public boolean isMutable(); | ||
70 | |||
71 | /** | ||
72 | * Converts the match to an array representation, with each pattern parameter at their respective position. | ||
73 | * In case of a partial match, unsubstituted parameters will be represented as null elements in the array. | ||
74 | * | ||
75 | * @return a newly constructed array containing each parameter substitution of the match in order. | ||
76 | */ | ||
77 | public Object[] toArray(); | ||
78 | |||
79 | /** | ||
80 | * Takes an immutable snapshot of this match. | ||
81 | * @return the match itself in case of immutable matches, an immutable copy in case of mutable ones. | ||
82 | */ | ||
83 | public IPatternMatch toImmutable(); | ||
84 | |||
85 | /** Prints the list of parameter-value pairs. */ | ||
86 | public String prettyPrint(); | ||
87 | |||
88 | /** | ||
89 | * Checks that this match is compatible with the given other match. | ||
90 | * This is used for filtering the match set of a matcher. | ||
91 | * | ||
92 | * <p/> Two non-null matches are compatible if and only if: | ||
93 | * <ul> | ||
94 | * <li>They share the same pattern.</li> | ||
95 | * <li>For each parameter, where they are set (non-null) in both matches, | ||
96 | * their values are equal.</li> | ||
97 | * </li> | ||
98 | * </ul> | ||
99 | * | ||
100 | * <p/> Furthermore, all matches are considered compatible with | ||
101 | * null matches (e.g. empty filter). | ||
102 | * | ||
103 | * @param other | ||
104 | * @return true, if this is compatible with other, or other is null | ||
105 | */ | ||
106 | public boolean isCompatibleWith(IPatternMatch other); | ||
107 | } | ||