diff options
Diffstat (limited to 'Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/Output.java')
-rw-r--r-- | Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/Output.java | 724 |
1 files changed, 724 insertions, 0 deletions
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/Output.java b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/Output.java new file mode 100644 index 00000000..615b33af --- /dev/null +++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/Output.java | |||
@@ -0,0 +1,724 @@ | |||
1 | /** | ||
2 | * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql | ||
3 | */ | ||
4 | package modes3.queries; | ||
5 | |||
6 | import java.util.Arrays; | ||
7 | import java.util.Collection; | ||
8 | import java.util.LinkedHashSet; | ||
9 | import java.util.List; | ||
10 | import java.util.Objects; | ||
11 | import java.util.Optional; | ||
12 | import java.util.Set; | ||
13 | import java.util.function.Consumer; | ||
14 | import java.util.stream.Collectors; | ||
15 | import java.util.stream.Stream; | ||
16 | import modes3.Segment; | ||
17 | import modes3.queries.TurnoutOutput; | ||
18 | import org.apache.log4j.Logger; | ||
19 | import org.eclipse.emf.ecore.EClass; | ||
20 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
21 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
22 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
23 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
24 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; | ||
25 | import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; | ||
26 | import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; | ||
27 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
28 | import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
39 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
40 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
41 | import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil; | ||
42 | |||
43 | /** | ||
44 | * A pattern-specific query specification that can instantiate Matcher in a type-safe way. | ||
45 | * | ||
46 | * <p>Original source: | ||
47 | * <code><pre> | ||
48 | * pattern output(S1 : Segment, S2 : Segment) { | ||
49 | * Segment.connectedTo(S1, S2); | ||
50 | * } or { | ||
51 | * find turnoutOutput(S1, S2); | ||
52 | * } | ||
53 | * </pre></code> | ||
54 | * | ||
55 | * @see Matcher | ||
56 | * @see Match | ||
57 | * | ||
58 | */ | ||
59 | @SuppressWarnings("all") | ||
60 | public final class Output extends BaseGeneratedEMFQuerySpecification<Output.Matcher> { | ||
61 | /** | ||
62 | * Pattern-specific match representation of the modes3.queries.output pattern, | ||
63 | * to be used in conjunction with {@link Matcher}. | ||
64 | * | ||
65 | * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned. | ||
66 | * Each instance is a (possibly partial) substitution of pattern parameters, | ||
67 | * usable to represent a match of the pattern in the result of a query, | ||
68 | * or to specify the bound (fixed) input parameters when issuing a query. | ||
69 | * | ||
70 | * @see Matcher | ||
71 | * | ||
72 | */ | ||
73 | public static abstract class Match extends BasePatternMatch { | ||
74 | private Segment fS1; | ||
75 | |||
76 | private Segment fS2; | ||
77 | |||
78 | private static List<String> parameterNames = makeImmutableList("S1", "S2"); | ||
79 | |||
80 | private Match(final Segment pS1, final Segment pS2) { | ||
81 | this.fS1 = pS1; | ||
82 | this.fS2 = pS2; | ||
83 | } | ||
84 | |||
85 | @Override | ||
86 | public Object get(final String parameterName) { | ||
87 | switch(parameterName) { | ||
88 | case "S1": return this.fS1; | ||
89 | case "S2": return this.fS2; | ||
90 | default: return null; | ||
91 | } | ||
92 | } | ||
93 | |||
94 | @Override | ||
95 | public Object get(final int index) { | ||
96 | switch(index) { | ||
97 | case 0: return this.fS1; | ||
98 | case 1: return this.fS2; | ||
99 | default: return null; | ||
100 | } | ||
101 | } | ||
102 | |||
103 | public Segment getS1() { | ||
104 | return this.fS1; | ||
105 | } | ||
106 | |||
107 | public Segment getS2() { | ||
108 | return this.fS2; | ||
109 | } | ||
110 | |||
111 | @Override | ||
112 | public boolean set(final String parameterName, final Object newValue) { | ||
113 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
114 | if ("S1".equals(parameterName) ) { | ||
115 | this.fS1 = (Segment) newValue; | ||
116 | return true; | ||
117 | } | ||
118 | if ("S2".equals(parameterName) ) { | ||
119 | this.fS2 = (Segment) newValue; | ||
120 | return true; | ||
121 | } | ||
122 | return false; | ||
123 | } | ||
124 | |||
125 | public void setS1(final Segment pS1) { | ||
126 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
127 | this.fS1 = pS1; | ||
128 | } | ||
129 | |||
130 | public void setS2(final Segment pS2) { | ||
131 | if (!isMutable()) throw new java.lang.UnsupportedOperationException(); | ||
132 | this.fS2 = pS2; | ||
133 | } | ||
134 | |||
135 | @Override | ||
136 | public String patternName() { | ||
137 | return "modes3.queries.output"; | ||
138 | } | ||
139 | |||
140 | @Override | ||
141 | public List<String> parameterNames() { | ||
142 | return Output.Match.parameterNames; | ||
143 | } | ||
144 | |||
145 | @Override | ||
146 | public Object[] toArray() { | ||
147 | return new Object[]{fS1, fS2}; | ||
148 | } | ||
149 | |||
150 | @Override | ||
151 | public Output.Match toImmutable() { | ||
152 | return isMutable() ? newMatch(fS1, fS2) : this; | ||
153 | } | ||
154 | |||
155 | @Override | ||
156 | public String prettyPrint() { | ||
157 | StringBuilder result = new StringBuilder(); | ||
158 | result.append("\"S1\"=" + prettyPrintValue(fS1) + ", "); | ||
159 | result.append("\"S2\"=" + prettyPrintValue(fS2)); | ||
160 | return result.toString(); | ||
161 | } | ||
162 | |||
163 | @Override | ||
164 | public int hashCode() { | ||
165 | return Objects.hash(fS1, fS2); | ||
166 | } | ||
167 | |||
168 | @Override | ||
169 | public boolean equals(final Object obj) { | ||
170 | if (this == obj) | ||
171 | return true; | ||
172 | if (obj == null) { | ||
173 | return false; | ||
174 | } | ||
175 | if ((obj instanceof Output.Match)) { | ||
176 | Output.Match other = (Output.Match) obj; | ||
177 | return Objects.equals(fS1, other.fS1) && Objects.equals(fS2, other.fS2); | ||
178 | } else { | ||
179 | // this should be infrequent | ||
180 | if (!(obj instanceof IPatternMatch)) { | ||
181 | return false; | ||
182 | } | ||
183 | IPatternMatch otherSig = (IPatternMatch) obj; | ||
184 | return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray()); | ||
185 | } | ||
186 | } | ||
187 | |||
188 | @Override | ||
189 | public Output specification() { | ||
190 | return Output.instance(); | ||
191 | } | ||
192 | |||
193 | /** | ||
194 | * Returns an empty, mutable match. | ||
195 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
196 | * | ||
197 | * @return the empty match. | ||
198 | * | ||
199 | */ | ||
200 | public static Output.Match newEmptyMatch() { | ||
201 | return new Mutable(null, null); | ||
202 | } | ||
203 | |||
204 | /** | ||
205 | * Returns a mutable (partial) match. | ||
206 | * Fields of the mutable match can be filled to create a partial match, usable as matcher input. | ||
207 | * | ||
208 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
209 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
210 | * @return the new, mutable (partial) match object. | ||
211 | * | ||
212 | */ | ||
213 | public static Output.Match newMutableMatch(final Segment pS1, final Segment pS2) { | ||
214 | return new Mutable(pS1, pS2); | ||
215 | } | ||
216 | |||
217 | /** | ||
218 | * Returns a new (partial) match. | ||
219 | * This can be used e.g. to call the matcher with a partial match. | ||
220 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
221 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
222 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
223 | * @return the (partial) match object. | ||
224 | * | ||
225 | */ | ||
226 | public static Output.Match newMatch(final Segment pS1, final Segment pS2) { | ||
227 | return new Immutable(pS1, pS2); | ||
228 | } | ||
229 | |||
230 | private static final class Mutable extends Output.Match { | ||
231 | Mutable(final Segment pS1, final Segment pS2) { | ||
232 | super(pS1, pS2); | ||
233 | } | ||
234 | |||
235 | @Override | ||
236 | public boolean isMutable() { | ||
237 | return true; | ||
238 | } | ||
239 | } | ||
240 | |||
241 | private static final class Immutable extends Output.Match { | ||
242 | Immutable(final Segment pS1, final Segment pS2) { | ||
243 | super(pS1, pS2); | ||
244 | } | ||
245 | |||
246 | @Override | ||
247 | public boolean isMutable() { | ||
248 | return false; | ||
249 | } | ||
250 | } | ||
251 | } | ||
252 | |||
253 | /** | ||
254 | * Generated pattern matcher API of the modes3.queries.output pattern, | ||
255 | * providing pattern-specific query methods. | ||
256 | * | ||
257 | * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)}, | ||
258 | * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}. | ||
259 | * | ||
260 | * <p>Matches of the pattern will be represented as {@link Match}. | ||
261 | * | ||
262 | * <p>Original source: | ||
263 | * <code><pre> | ||
264 | * pattern output(S1 : Segment, S2 : Segment) { | ||
265 | * Segment.connectedTo(S1, S2); | ||
266 | * } or { | ||
267 | * find turnoutOutput(S1, S2); | ||
268 | * } | ||
269 | * </pre></code> | ||
270 | * | ||
271 | * @see Match | ||
272 | * @see Output | ||
273 | * | ||
274 | */ | ||
275 | public static class Matcher extends BaseMatcher<Output.Match> { | ||
276 | /** | ||
277 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
278 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
279 | * | ||
280 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
281 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
282 | * | ||
283 | */ | ||
284 | public static Output.Matcher on(final ViatraQueryEngine engine) { | ||
285 | // check if matcher already exists | ||
286 | Matcher matcher = engine.getExistingMatcher(querySpecification()); | ||
287 | if (matcher == null) { | ||
288 | matcher = (Matcher)engine.getMatcher(querySpecification()); | ||
289 | } | ||
290 | return matcher; | ||
291 | } | ||
292 | |||
293 | /** | ||
294 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
295 | * @return an initialized matcher | ||
296 | * @noreference This method is for internal matcher initialization by the framework, do not call it manually. | ||
297 | * | ||
298 | */ | ||
299 | public static Output.Matcher create() { | ||
300 | return new Matcher(); | ||
301 | } | ||
302 | |||
303 | private static final int POSITION_S1 = 0; | ||
304 | |||
305 | private static final int POSITION_S2 = 1; | ||
306 | |||
307 | private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(Output.Matcher.class); | ||
308 | |||
309 | /** | ||
310 | * Initializes the pattern matcher within an existing VIATRA Query engine. | ||
311 | * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned. | ||
312 | * | ||
313 | * @param engine the existing VIATRA Query engine in which this matcher will be created. | ||
314 | * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation | ||
315 | * | ||
316 | */ | ||
317 | private Matcher() { | ||
318 | super(querySpecification()); | ||
319 | } | ||
320 | |||
321 | /** | ||
322 | * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters. | ||
323 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
324 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
325 | * @return matches represented as a Match object. | ||
326 | * | ||
327 | */ | ||
328 | public Collection<Output.Match> getAllMatches(final Segment pS1, final Segment pS2) { | ||
329 | return rawStreamAllMatches(new Object[]{pS1, pS2}).collect(Collectors.toSet()); | ||
330 | } | ||
331 | |||
332 | /** | ||
333 | * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters. | ||
334 | * </p> | ||
335 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
336 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
337 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
338 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
339 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
340 | * @return a stream of matches represented as a Match object. | ||
341 | * | ||
342 | */ | ||
343 | public Stream<Output.Match> streamAllMatches(final Segment pS1, final Segment pS2) { | ||
344 | return rawStreamAllMatches(new Object[]{pS1, pS2}); | ||
345 | } | ||
346 | |||
347 | /** | ||
348 | * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
349 | * Neither determinism nor randomness of selection is guaranteed. | ||
350 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
351 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
352 | * @return a match represented as a Match object, or null if no match is found. | ||
353 | * | ||
354 | */ | ||
355 | public Optional<Output.Match> getOneArbitraryMatch(final Segment pS1, final Segment pS2) { | ||
356 | return rawGetOneArbitraryMatch(new Object[]{pS1, pS2}); | ||
357 | } | ||
358 | |||
359 | /** | ||
360 | * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match, | ||
361 | * under any possible substitution of the unspecified parameters (if any). | ||
362 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
363 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
364 | * @return true if the input is a valid (partial) match of the pattern. | ||
365 | * | ||
366 | */ | ||
367 | public boolean hasMatch(final Segment pS1, final Segment pS2) { | ||
368 | return rawHasMatch(new Object[]{pS1, pS2}); | ||
369 | } | ||
370 | |||
371 | /** | ||
372 | * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters. | ||
373 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
374 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
375 | * @return the number of pattern matches found. | ||
376 | * | ||
377 | */ | ||
378 | public int countMatches(final Segment pS1, final Segment pS2) { | ||
379 | return rawCountMatches(new Object[]{pS1, pS2}); | ||
380 | } | ||
381 | |||
382 | /** | ||
383 | * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters. | ||
384 | * Neither determinism nor randomness of selection is guaranteed. | ||
385 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
386 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
387 | * @param processor the action that will process the selected match. | ||
388 | * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked | ||
389 | * | ||
390 | */ | ||
391 | public boolean forOneArbitraryMatch(final Segment pS1, final Segment pS2, final Consumer<? super Output.Match> processor) { | ||
392 | return rawForOneArbitraryMatch(new Object[]{pS1, pS2}, processor); | ||
393 | } | ||
394 | |||
395 | /** | ||
396 | * Returns a new (partial) match. | ||
397 | * This can be used e.g. to call the matcher with a partial match. | ||
398 | * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object. | ||
399 | * @param pS1 the fixed value of pattern parameter S1, or null if not bound. | ||
400 | * @param pS2 the fixed value of pattern parameter S2, or null if not bound. | ||
401 | * @return the (partial) match object. | ||
402 | * | ||
403 | */ | ||
404 | public Output.Match newMatch(final Segment pS1, final Segment pS2) { | ||
405 | return Output.Match.newMatch(pS1, pS2); | ||
406 | } | ||
407 | |||
408 | /** | ||
409 | * Retrieve the set of values that occur in matches for S1. | ||
410 | * @return the Set of all values or empty set if there are no matches | ||
411 | * | ||
412 | */ | ||
413 | protected Stream<Segment> rawStreamAllValuesOfS1(final Object[] parameters) { | ||
414 | return rawStreamAllValues(POSITION_S1, parameters).map(Segment.class::cast); | ||
415 | } | ||
416 | |||
417 | /** | ||
418 | * Retrieve the set of values that occur in matches for S1. | ||
419 | * @return the Set of all values or empty set if there are no matches | ||
420 | * | ||
421 | */ | ||
422 | public Set<Segment> getAllValuesOfS1() { | ||
423 | return rawStreamAllValuesOfS1(emptyArray()).collect(Collectors.toSet()); | ||
424 | } | ||
425 | |||
426 | /** | ||
427 | * Retrieve the set of values that occur in matches for S1. | ||
428 | * @return the Set of all values or empty set if there are no matches | ||
429 | * | ||
430 | */ | ||
431 | public Stream<Segment> streamAllValuesOfS1() { | ||
432 | return rawStreamAllValuesOfS1(emptyArray()); | ||
433 | } | ||
434 | |||
435 | /** | ||
436 | * Retrieve the set of values that occur in matches for S1. | ||
437 | * </p> | ||
438 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
439 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
440 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
441 | * | ||
442 | * @return the Stream of all values or empty set if there are no matches | ||
443 | * | ||
444 | */ | ||
445 | public Stream<Segment> streamAllValuesOfS1(final Output.Match partialMatch) { | ||
446 | return rawStreamAllValuesOfS1(partialMatch.toArray()); | ||
447 | } | ||
448 | |||
449 | /** | ||
450 | * Retrieve the set of values that occur in matches for S1. | ||
451 | * </p> | ||
452 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
453 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
454 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
455 | * | ||
456 | * @return the Stream of all values or empty set if there are no matches | ||
457 | * | ||
458 | */ | ||
459 | public Stream<Segment> streamAllValuesOfS1(final Segment pS2) { | ||
460 | return rawStreamAllValuesOfS1(new Object[]{null, pS2}); | ||
461 | } | ||
462 | |||
463 | /** | ||
464 | * Retrieve the set of values that occur in matches for S1. | ||
465 | * @return the Set of all values or empty set if there are no matches | ||
466 | * | ||
467 | */ | ||
468 | public Set<Segment> getAllValuesOfS1(final Output.Match partialMatch) { | ||
469 | return rawStreamAllValuesOfS1(partialMatch.toArray()).collect(Collectors.toSet()); | ||
470 | } | ||
471 | |||
472 | /** | ||
473 | * Retrieve the set of values that occur in matches for S1. | ||
474 | * @return the Set of all values or empty set if there are no matches | ||
475 | * | ||
476 | */ | ||
477 | public Set<Segment> getAllValuesOfS1(final Segment pS2) { | ||
478 | return rawStreamAllValuesOfS1(new Object[]{null, pS2}).collect(Collectors.toSet()); | ||
479 | } | ||
480 | |||
481 | /** | ||
482 | * Retrieve the set of values that occur in matches for S2. | ||
483 | * @return the Set of all values or empty set if there are no matches | ||
484 | * | ||
485 | */ | ||
486 | protected Stream<Segment> rawStreamAllValuesOfS2(final Object[] parameters) { | ||
487 | return rawStreamAllValues(POSITION_S2, parameters).map(Segment.class::cast); | ||
488 | } | ||
489 | |||
490 | /** | ||
491 | * Retrieve the set of values that occur in matches for S2. | ||
492 | * @return the Set of all values or empty set if there are no matches | ||
493 | * | ||
494 | */ | ||
495 | public Set<Segment> getAllValuesOfS2() { | ||
496 | return rawStreamAllValuesOfS2(emptyArray()).collect(Collectors.toSet()); | ||
497 | } | ||
498 | |||
499 | /** | ||
500 | * Retrieve the set of values that occur in matches for S2. | ||
501 | * @return the Set of all values or empty set if there are no matches | ||
502 | * | ||
503 | */ | ||
504 | public Stream<Segment> streamAllValuesOfS2() { | ||
505 | return rawStreamAllValuesOfS2(emptyArray()); | ||
506 | } | ||
507 | |||
508 | /** | ||
509 | * Retrieve the set of values that occur in matches for S2. | ||
510 | * </p> | ||
511 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
512 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
513 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
514 | * | ||
515 | * @return the Stream of all values or empty set if there are no matches | ||
516 | * | ||
517 | */ | ||
518 | public Stream<Segment> streamAllValuesOfS2(final Output.Match partialMatch) { | ||
519 | return rawStreamAllValuesOfS2(partialMatch.toArray()); | ||
520 | } | ||
521 | |||
522 | /** | ||
523 | * Retrieve the set of values that occur in matches for S2. | ||
524 | * </p> | ||
525 | * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed. | ||
526 | * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>. | ||
527 | * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code. | ||
528 | * | ||
529 | * @return the Stream of all values or empty set if there are no matches | ||
530 | * | ||
531 | */ | ||
532 | public Stream<Segment> streamAllValuesOfS2(final Segment pS1) { | ||
533 | return rawStreamAllValuesOfS2(new Object[]{pS1, null}); | ||
534 | } | ||
535 | |||
536 | /** | ||
537 | * Retrieve the set of values that occur in matches for S2. | ||
538 | * @return the Set of all values or empty set if there are no matches | ||
539 | * | ||
540 | */ | ||
541 | public Set<Segment> getAllValuesOfS2(final Output.Match partialMatch) { | ||
542 | return rawStreamAllValuesOfS2(partialMatch.toArray()).collect(Collectors.toSet()); | ||
543 | } | ||
544 | |||
545 | /** | ||
546 | * Retrieve the set of values that occur in matches for S2. | ||
547 | * @return the Set of all values or empty set if there are no matches | ||
548 | * | ||
549 | */ | ||
550 | public Set<Segment> getAllValuesOfS2(final Segment pS1) { | ||
551 | return rawStreamAllValuesOfS2(new Object[]{pS1, null}).collect(Collectors.toSet()); | ||
552 | } | ||
553 | |||
554 | @Override | ||
555 | protected Output.Match tupleToMatch(final Tuple t) { | ||
556 | try { | ||
557 | return Output.Match.newMatch((Segment) t.get(POSITION_S1), (Segment) t.get(POSITION_S2)); | ||
558 | } catch(ClassCastException e) { | ||
559 | LOGGER.error("Element(s) in tuple not properly typed!",e); | ||
560 | return null; | ||
561 | } | ||
562 | } | ||
563 | |||
564 | @Override | ||
565 | protected Output.Match arrayToMatch(final Object[] match) { | ||
566 | try { | ||
567 | return Output.Match.newMatch((Segment) match[POSITION_S1], (Segment) match[POSITION_S2]); | ||
568 | } catch(ClassCastException e) { | ||
569 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
570 | return null; | ||
571 | } | ||
572 | } | ||
573 | |||
574 | @Override | ||
575 | protected Output.Match arrayToMatchMutable(final Object[] match) { | ||
576 | try { | ||
577 | return Output.Match.newMutableMatch((Segment) match[POSITION_S1], (Segment) match[POSITION_S2]); | ||
578 | } catch(ClassCastException e) { | ||
579 | LOGGER.error("Element(s) in array not properly typed!",e); | ||
580 | return null; | ||
581 | } | ||
582 | } | ||
583 | |||
584 | /** | ||
585 | * @return the singleton instance of the query specification of this pattern | ||
586 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
587 | * | ||
588 | */ | ||
589 | public static IQuerySpecification<Output.Matcher> querySpecification() { | ||
590 | return Output.instance(); | ||
591 | } | ||
592 | } | ||
593 | |||
594 | private Output() { | ||
595 | super(GeneratedPQuery.INSTANCE); | ||
596 | } | ||
597 | |||
598 | /** | ||
599 | * @return the singleton instance of the query specification | ||
600 | * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded | ||
601 | * | ||
602 | */ | ||
603 | public static Output instance() { | ||
604 | try{ | ||
605 | return LazyHolder.INSTANCE; | ||
606 | } catch (ExceptionInInitializerError err) { | ||
607 | throw processInitializerError(err); | ||
608 | } | ||
609 | } | ||
610 | |||
611 | @Override | ||
612 | protected Output.Matcher instantiate(final ViatraQueryEngine engine) { | ||
613 | return Output.Matcher.on(engine); | ||
614 | } | ||
615 | |||
616 | @Override | ||
617 | public Output.Matcher instantiate() { | ||
618 | return Output.Matcher.create(); | ||
619 | } | ||
620 | |||
621 | @Override | ||
622 | public Output.Match newEmptyMatch() { | ||
623 | return Output.Match.newEmptyMatch(); | ||
624 | } | ||
625 | |||
626 | @Override | ||
627 | public Output.Match newMatch(final Object... parameters) { | ||
628 | return Output.Match.newMatch((modes3.Segment) parameters[0], (modes3.Segment) parameters[1]); | ||
629 | } | ||
630 | |||
631 | /** | ||
632 | * Inner class allowing the singleton instance of {@link Output} to be created | ||
633 | * <b>not</b> at the class load time of the outer class, | ||
634 | * but rather at the first call to {@link Output#instance()}. | ||
635 | * | ||
636 | * <p> This workaround is required e.g. to support recursion. | ||
637 | * | ||
638 | */ | ||
639 | private static class LazyHolder { | ||
640 | private static final Output INSTANCE = new Output(); | ||
641 | |||
642 | /** | ||
643 | * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned. | ||
644 | * This initialization order is required to support indirect recursion. | ||
645 | * | ||
646 | * <p> The static initializer is defined using a helper field to work around limitations of the code generator. | ||
647 | * | ||
648 | */ | ||
649 | private static final Object STATIC_INITIALIZER = ensureInitialized(); | ||
650 | |||
651 | public static Object ensureInitialized() { | ||
652 | INSTANCE.ensureInitializedInternal(); | ||
653 | return null; | ||
654 | } | ||
655 | } | ||
656 | |||
657 | private static class GeneratedPQuery extends BaseGeneratedEMFPQuery { | ||
658 | private static final Output.GeneratedPQuery INSTANCE = new GeneratedPQuery(); | ||
659 | |||
660 | private final PParameter parameter_S1 = new PParameter("S1", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT); | ||
661 | |||
662 | private final PParameter parameter_S2 = new PParameter("S2", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT); | ||
663 | |||
664 | private final List<PParameter> parameters = Arrays.asList(parameter_S1, parameter_S2); | ||
665 | |||
666 | private GeneratedPQuery() { | ||
667 | super(PVisibility.PUBLIC); | ||
668 | } | ||
669 | |||
670 | @Override | ||
671 | public String getFullyQualifiedName() { | ||
672 | return "modes3.queries.output"; | ||
673 | } | ||
674 | |||
675 | @Override | ||
676 | public List<String> getParameterNames() { | ||
677 | return Arrays.asList("S1","S2"); | ||
678 | } | ||
679 | |||
680 | @Override | ||
681 | public List<PParameter> getParameters() { | ||
682 | return parameters; | ||
683 | } | ||
684 | |||
685 | @Override | ||
686 | public Set<PBody> doGetContainedBodies() { | ||
687 | setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED)); | ||
688 | Set<PBody> bodies = new LinkedHashSet<>(); | ||
689 | { | ||
690 | PBody body = new PBody(this); | ||
691 | PVariable var_S1 = body.getOrCreateVariableByName("S1"); | ||
692 | PVariable var_S2 = body.getOrCreateVariableByName("S2"); | ||
693 | new TypeConstraint(body, Tuples.flatTupleOf(var_S1), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
694 | new TypeConstraint(body, Tuples.flatTupleOf(var_S2), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
695 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
696 | new ExportedParameter(body, var_S1, parameter_S1), | ||
697 | new ExportedParameter(body, var_S2, parameter_S2) | ||
698 | )); | ||
699 | // Segment.connectedTo(S1, S2) | ||
700 | new TypeConstraint(body, Tuples.flatTupleOf(var_S1), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
701 | PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}"); | ||
702 | new TypeConstraint(body, Tuples.flatTupleOf(var_S1, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment", "connectedTo"))); | ||
703 | new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
704 | new Equality(body, var__virtual_0_, var_S2); | ||
705 | bodies.add(body); | ||
706 | } | ||
707 | { | ||
708 | PBody body = new PBody(this); | ||
709 | PVariable var_S1 = body.getOrCreateVariableByName("S1"); | ||
710 | PVariable var_S2 = body.getOrCreateVariableByName("S2"); | ||
711 | new TypeConstraint(body, Tuples.flatTupleOf(var_S1), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
712 | new TypeConstraint(body, Tuples.flatTupleOf(var_S2), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment"))); | ||
713 | body.setSymbolicParameters(Arrays.<ExportedParameter>asList( | ||
714 | new ExportedParameter(body, var_S1, parameter_S1), | ||
715 | new ExportedParameter(body, var_S2, parameter_S2) | ||
716 | )); | ||
717 | // find turnoutOutput(S1, S2) | ||
718 | new PositivePatternCall(body, Tuples.flatTupleOf(var_S1, var_S2), TurnoutOutput.instance().getInternalQueryRepresentation()); | ||
719 | bodies.add(body); | ||
720 | } | ||
721 | return bodies; | ||
722 | } | ||
723 | } | ||
724 | } | ||