aboutsummaryrefslogtreecommitdiffstats
path: root/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3
diff options
context:
space:
mode:
Diffstat (limited to 'Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3')
-rw-r--r--Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/.gitignore45
-rw-r--r--Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/EndOfSiding_step_2.java564
-rw-r--r--Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/EndOfSiding_step_3.java717
-rw-r--r--Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/EndOfSiding_step_4.java847
-rw-r--r--Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/EndOfSiding_step_5.java841
-rw-r--r--Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/Modes3Queries.java198
-rw-r--r--Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/MultipleConnectedTo.java565
-rw-r--r--Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TooManyInputsOfSegment.java12
-rw-r--r--Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TrainLocations_step_2.java564
-rw-r--r--Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TrainLocations_step_3.java713
10 files changed, 5054 insertions, 12 deletions
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/.gitignore b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/.gitignore
index b3e38571..a84c2906 100644
--- a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/.gitignore
+++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/.gitignore
@@ -31,3 +31,48 @@
31/.TooManyNonStraightInputsOfTurnout.java._trace 31/.TooManyNonStraightInputsOfTurnout.java._trace
32/.InputsOfTurnout.java._trace 32/.InputsOfTurnout.java._trace
33/.TooFewInputsOfTurnout.java._trace 33/.TooFewInputsOfTurnout.java._trace
34/.CloseTrains_step_2.java._trace
35/.CloseTrains_step_3.java._trace
36/.CloseTrains_step_4.java._trace
37/.CloseTrains_step_5.java._trace
38/.CloseTrains_step_6.java._trace
39/.CloseTrains_step_7.java._trace
40/.MisalignedTurnout_step_2.java._trace
41/.MisalignedTurnout_step_3.java._trace
42/.MisalignedTurnout_step_4.java._trace
43/.MisalignedTurnout_step_5.java._trace
44/.ConnectedSegmentsDirected.java._trace
45/Adjacent.java
46/CloseTrains_step_2.java
47/CloseTrains_step_3.java
48/CloseTrains_step_4.java
49/CloseTrains_step_5.java
50/CloseTrains_step_6.java
51/CloseTrains_step_7.java
52/ConnectedSegmentsDirected.java
53/ConnectedTo.java
54/ConnectedToNotSymmetric.java
55/ConnectedToReflexive.java
56/InputsOfTurnout.java
57/MisalignedTurnout_step_2.java
58/MisalignedTurnout_step_3.java
59/MisalignedTurnout_step_4.java
60/MisalignedTurnout_step_5.java
61/Modes3Queries.java
62/Output.java
63/OutputReflexive.java
64/Reachable.java
65/TooFewInputsOfTurnout.java
66/TooManyInputsOfSegment.java
67/TooManyInputsOfTurnout.java
68/TurnoutConnectedToBothOutputs.java
69/TurnoutOutput.java
70/TurnoutOutputsAreSame.java
71/Unreachable.java
72/.TrainLocations_step_2.java._trace
73/.TrainLocations_step_3.java._trace
74/.EndOfSiding_step_2.java._trace
75/.EndOfSiding_step_3.java._trace
76/.EndOfSiding_step_4.java._trace
77/.EndOfSiding_step_5.java._trace
78/.MultipleConnectedTo.java._trace
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/EndOfSiding_step_2.java b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/EndOfSiding_step_2.java
new file mode 100644
index 00000000..a8f68dca
--- /dev/null
+++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/EndOfSiding_step_2.java
@@ -0,0 +1,564 @@
1/**
2 * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql
3 */
4package modes3.queries;
5
6import java.util.Arrays;
7import java.util.Collection;
8import java.util.LinkedHashSet;
9import java.util.List;
10import java.util.Objects;
11import java.util.Optional;
12import java.util.Set;
13import java.util.function.Consumer;
14import java.util.stream.Collectors;
15import java.util.stream.Stream;
16import modes3.Train;
17import org.apache.log4j.Logger;
18import org.eclipse.emf.ecore.EClass;
19import org.eclipse.viatra.query.runtime.api.IPatternMatch;
20import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
21import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
22import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
23import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
24import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
25import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
26import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
27import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
28import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
29import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
30import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
31import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
32import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
33import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
34import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
35import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
36import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
37import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
38
39/**
40 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
41 *
42 * <p>Original source:
43 * <code><pre>
44 * //
45 * // endOfSiding
46 * //
47 *
48 * pattern endOfSiding_step_2(in train : Train) {
49 * // frame-{@literal >}train = model-{@literal >}trains[i0];
50 * // frame-{@literal >}location = frame-{@literal >}train-{@literal >}location;
51 * // if (frame-{@literal >}location != NULL) {
52 * // ...
53 * // }
54 *
55 * Train(train);
56 * }
57 * </pre></code>
58 *
59 * @see Matcher
60 * @see Match
61 *
62 */
63@SuppressWarnings("all")
64public final class EndOfSiding_step_2 extends BaseGeneratedEMFQuerySpecification<EndOfSiding_step_2.Matcher> {
65 /**
66 * Pattern-specific match representation of the modes3.queries.endOfSiding_step_2 pattern,
67 * to be used in conjunction with {@link Matcher}.
68 *
69 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
70 * Each instance is a (possibly partial) substitution of pattern parameters,
71 * usable to represent a match of the pattern in the result of a query,
72 * or to specify the bound (fixed) input parameters when issuing a query.
73 *
74 * @see Matcher
75 *
76 */
77 public static abstract class Match extends BasePatternMatch {
78 private Train fTrain;
79
80 private static List<String> parameterNames = makeImmutableList("train");
81
82 private Match(final Train pTrain) {
83 this.fTrain = pTrain;
84 }
85
86 @Override
87 public Object get(final String parameterName) {
88 switch(parameterName) {
89 case "train": return this.fTrain;
90 default: return null;
91 }
92 }
93
94 @Override
95 public Object get(final int index) {
96 switch(index) {
97 case 0: return this.fTrain;
98 default: return null;
99 }
100 }
101
102 public Train getTrain() {
103 return this.fTrain;
104 }
105
106 @Override
107 public boolean set(final String parameterName, final Object newValue) {
108 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
109 if ("train".equals(parameterName) ) {
110 this.fTrain = (Train) newValue;
111 return true;
112 }
113 return false;
114 }
115
116 public void setTrain(final Train pTrain) {
117 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
118 this.fTrain = pTrain;
119 }
120
121 @Override
122 public String patternName() {
123 return "modes3.queries.endOfSiding_step_2";
124 }
125
126 @Override
127 public List<String> parameterNames() {
128 return EndOfSiding_step_2.Match.parameterNames;
129 }
130
131 @Override
132 public Object[] toArray() {
133 return new Object[]{fTrain};
134 }
135
136 @Override
137 public EndOfSiding_step_2.Match toImmutable() {
138 return isMutable() ? newMatch(fTrain) : this;
139 }
140
141 @Override
142 public String prettyPrint() {
143 StringBuilder result = new StringBuilder();
144 result.append("\"train\"=" + prettyPrintValue(fTrain));
145 return result.toString();
146 }
147
148 @Override
149 public int hashCode() {
150 return Objects.hash(fTrain);
151 }
152
153 @Override
154 public boolean equals(final Object obj) {
155 if (this == obj)
156 return true;
157 if (obj == null) {
158 return false;
159 }
160 if ((obj instanceof EndOfSiding_step_2.Match)) {
161 EndOfSiding_step_2.Match other = (EndOfSiding_step_2.Match) obj;
162 return Objects.equals(fTrain, other.fTrain);
163 } else {
164 // this should be infrequent
165 if (!(obj instanceof IPatternMatch)) {
166 return false;
167 }
168 IPatternMatch otherSig = (IPatternMatch) obj;
169 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
170 }
171 }
172
173 @Override
174 public EndOfSiding_step_2 specification() {
175 return EndOfSiding_step_2.instance();
176 }
177
178 /**
179 * Returns an empty, mutable match.
180 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
181 *
182 * @return the empty match.
183 *
184 */
185 public static EndOfSiding_step_2.Match newEmptyMatch() {
186 return new Mutable(null);
187 }
188
189 /**
190 * Returns a mutable (partial) match.
191 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
192 *
193 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
194 * @return the new, mutable (partial) match object.
195 *
196 */
197 public static EndOfSiding_step_2.Match newMutableMatch(final Train pTrain) {
198 return new Mutable(pTrain);
199 }
200
201 /**
202 * Returns a new (partial) match.
203 * This can be used e.g. to call the matcher with a partial match.
204 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
205 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
206 * @return the (partial) match object.
207 *
208 */
209 public static EndOfSiding_step_2.Match newMatch(final Train pTrain) {
210 return new Immutable(pTrain);
211 }
212
213 private static final class Mutable extends EndOfSiding_step_2.Match {
214 Mutable(final Train pTrain) {
215 super(pTrain);
216 }
217
218 @Override
219 public boolean isMutable() {
220 return true;
221 }
222 }
223
224 private static final class Immutable extends EndOfSiding_step_2.Match {
225 Immutable(final Train pTrain) {
226 super(pTrain);
227 }
228
229 @Override
230 public boolean isMutable() {
231 return false;
232 }
233 }
234 }
235
236 /**
237 * Generated pattern matcher API of the modes3.queries.endOfSiding_step_2 pattern,
238 * providing pattern-specific query methods.
239 *
240 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
241 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
242 *
243 * <p>Matches of the pattern will be represented as {@link Match}.
244 *
245 * <p>Original source:
246 * <code><pre>
247 * //
248 * // endOfSiding
249 * //
250 *
251 * pattern endOfSiding_step_2(in train : Train) {
252 * // frame-{@literal >}train = model-{@literal >}trains[i0];
253 * // frame-{@literal >}location = frame-{@literal >}train-{@literal >}location;
254 * // if (frame-{@literal >}location != NULL) {
255 * // ...
256 * // }
257 *
258 * Train(train);
259 * }
260 * </pre></code>
261 *
262 * @see Match
263 * @see EndOfSiding_step_2
264 *
265 */
266 public static class Matcher extends BaseMatcher<EndOfSiding_step_2.Match> {
267 /**
268 * Initializes the pattern matcher within an existing VIATRA Query engine.
269 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
270 *
271 * @param engine the existing VIATRA Query engine in which this matcher will be created.
272 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
273 *
274 */
275 public static EndOfSiding_step_2.Matcher on(final ViatraQueryEngine engine) {
276 // check if matcher already exists
277 Matcher matcher = engine.getExistingMatcher(querySpecification());
278 if (matcher == null) {
279 matcher = (Matcher)engine.getMatcher(querySpecification());
280 }
281 return matcher;
282 }
283
284 /**
285 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
286 * @return an initialized matcher
287 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
288 *
289 */
290 public static EndOfSiding_step_2.Matcher create() {
291 return new Matcher();
292 }
293
294 private static final int POSITION_TRAIN = 0;
295
296 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(EndOfSiding_step_2.Matcher.class);
297
298 /**
299 * Initializes the pattern matcher within an existing VIATRA Query engine.
300 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
301 *
302 * @param engine the existing VIATRA Query engine in which this matcher will be created.
303 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
304 *
305 */
306 private Matcher() {
307 super(querySpecification());
308 }
309
310 /**
311 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
312 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
313 * @return matches represented as a Match object.
314 *
315 */
316 public Collection<EndOfSiding_step_2.Match> getAllMatches(final Train pTrain) {
317 return rawStreamAllMatches(new Object[]{pTrain}).collect(Collectors.toSet());
318 }
319
320 /**
321 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
322 * </p>
323 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
324 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
325 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
326 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
327 * @return a stream of matches represented as a Match object.
328 *
329 */
330 public Stream<EndOfSiding_step_2.Match> streamAllMatches(final Train pTrain) {
331 return rawStreamAllMatches(new Object[]{pTrain});
332 }
333
334 /**
335 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
336 * Neither determinism nor randomness of selection is guaranteed.
337 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
338 * @return a match represented as a Match object, or null if no match is found.
339 *
340 */
341 public Optional<EndOfSiding_step_2.Match> getOneArbitraryMatch(final Train pTrain) {
342 return rawGetOneArbitraryMatch(new Object[]{pTrain});
343 }
344
345 /**
346 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
347 * under any possible substitution of the unspecified parameters (if any).
348 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
349 * @return true if the input is a valid (partial) match of the pattern.
350 *
351 */
352 public boolean hasMatch(final Train pTrain) {
353 return rawHasMatch(new Object[]{pTrain});
354 }
355
356 /**
357 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
358 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
359 * @return the number of pattern matches found.
360 *
361 */
362 public int countMatches(final Train pTrain) {
363 return rawCountMatches(new Object[]{pTrain});
364 }
365
366 /**
367 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
368 * Neither determinism nor randomness of selection is guaranteed.
369 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
370 * @param processor the action that will process the selected match.
371 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
372 *
373 */
374 public boolean forOneArbitraryMatch(final Train pTrain, final Consumer<? super EndOfSiding_step_2.Match> processor) {
375 return rawForOneArbitraryMatch(new Object[]{pTrain}, processor);
376 }
377
378 /**
379 * Returns a new (partial) match.
380 * This can be used e.g. to call the matcher with a partial match.
381 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
382 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
383 * @return the (partial) match object.
384 *
385 */
386 public EndOfSiding_step_2.Match newMatch(final Train pTrain) {
387 return EndOfSiding_step_2.Match.newMatch(pTrain);
388 }
389
390 /**
391 * Retrieve the set of values that occur in matches for train.
392 * @return the Set of all values or empty set if there are no matches
393 *
394 */
395 protected Stream<Train> rawStreamAllValuesOftrain(final Object[] parameters) {
396 return rawStreamAllValues(POSITION_TRAIN, parameters).map(Train.class::cast);
397 }
398
399 /**
400 * Retrieve the set of values that occur in matches for train.
401 * @return the Set of all values or empty set if there are no matches
402 *
403 */
404 public Set<Train> getAllValuesOftrain() {
405 return rawStreamAllValuesOftrain(emptyArray()).collect(Collectors.toSet());
406 }
407
408 /**
409 * Retrieve the set of values that occur in matches for train.
410 * @return the Set of all values or empty set if there are no matches
411 *
412 */
413 public Stream<Train> streamAllValuesOftrain() {
414 return rawStreamAllValuesOftrain(emptyArray());
415 }
416
417 @Override
418 protected EndOfSiding_step_2.Match tupleToMatch(final Tuple t) {
419 try {
420 return EndOfSiding_step_2.Match.newMatch((Train) t.get(POSITION_TRAIN));
421 } catch(ClassCastException e) {
422 LOGGER.error("Element(s) in tuple not properly typed!",e);
423 return null;
424 }
425 }
426
427 @Override
428 protected EndOfSiding_step_2.Match arrayToMatch(final Object[] match) {
429 try {
430 return EndOfSiding_step_2.Match.newMatch((Train) match[POSITION_TRAIN]);
431 } catch(ClassCastException e) {
432 LOGGER.error("Element(s) in array not properly typed!",e);
433 return null;
434 }
435 }
436
437 @Override
438 protected EndOfSiding_step_2.Match arrayToMatchMutable(final Object[] match) {
439 try {
440 return EndOfSiding_step_2.Match.newMutableMatch((Train) match[POSITION_TRAIN]);
441 } catch(ClassCastException e) {
442 LOGGER.error("Element(s) in array not properly typed!",e);
443 return null;
444 }
445 }
446
447 /**
448 * @return the singleton instance of the query specification of this pattern
449 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
450 *
451 */
452 public static IQuerySpecification<EndOfSiding_step_2.Matcher> querySpecification() {
453 return EndOfSiding_step_2.instance();
454 }
455 }
456
457 private EndOfSiding_step_2() {
458 super(GeneratedPQuery.INSTANCE);
459 }
460
461 /**
462 * @return the singleton instance of the query specification
463 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
464 *
465 */
466 public static EndOfSiding_step_2 instance() {
467 try{
468 return LazyHolder.INSTANCE;
469 } catch (ExceptionInInitializerError err) {
470 throw processInitializerError(err);
471 }
472 }
473
474 @Override
475 protected EndOfSiding_step_2.Matcher instantiate(final ViatraQueryEngine engine) {
476 return EndOfSiding_step_2.Matcher.on(engine);
477 }
478
479 @Override
480 public EndOfSiding_step_2.Matcher instantiate() {
481 return EndOfSiding_step_2.Matcher.create();
482 }
483
484 @Override
485 public EndOfSiding_step_2.Match newEmptyMatch() {
486 return EndOfSiding_step_2.Match.newEmptyMatch();
487 }
488
489 @Override
490 public EndOfSiding_step_2.Match newMatch(final Object... parameters) {
491 return EndOfSiding_step_2.Match.newMatch((modes3.Train) parameters[0]);
492 }
493
494 /**
495 * Inner class allowing the singleton instance of {@link EndOfSiding_step_2} to be created
496 * <b>not</b> at the class load time of the outer class,
497 * but rather at the first call to {@link EndOfSiding_step_2#instance()}.
498 *
499 * <p> This workaround is required e.g. to support recursion.
500 *
501 */
502 private static class LazyHolder {
503 private static final EndOfSiding_step_2 INSTANCE = new EndOfSiding_step_2();
504
505 /**
506 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
507 * This initialization order is required to support indirect recursion.
508 *
509 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
510 *
511 */
512 private static final Object STATIC_INITIALIZER = ensureInitialized();
513
514 public static Object ensureInitialized() {
515 INSTANCE.ensureInitializedInternal();
516 return null;
517 }
518 }
519
520 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
521 private static final EndOfSiding_step_2.GeneratedPQuery INSTANCE = new GeneratedPQuery();
522
523 private final PParameter parameter_train = new PParameter("train", "modes3.Train", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Train")), PParameterDirection.INOUT);
524
525 private final List<PParameter> parameters = Arrays.asList(parameter_train);
526
527 private GeneratedPQuery() {
528 super(PVisibility.PUBLIC);
529 }
530
531 @Override
532 public String getFullyQualifiedName() {
533 return "modes3.queries.endOfSiding_step_2";
534 }
535
536 @Override
537 public List<String> getParameterNames() {
538 return Arrays.asList("train");
539 }
540
541 @Override
542 public List<PParameter> getParameters() {
543 return parameters;
544 }
545
546 @Override
547 public Set<PBody> doGetContainedBodies() {
548 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
549 Set<PBody> bodies = new LinkedHashSet<>();
550 {
551 PBody body = new PBody(this);
552 PVariable var_train = body.getOrCreateVariableByName("train");
553 new TypeConstraint(body, Tuples.flatTupleOf(var_train), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Train")));
554 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
555 new ExportedParameter(body, var_train, parameter_train)
556 ));
557 // // frame->train = model->trains[i0];// frame->location = frame->train->location;// if (frame->location != NULL) {// ...// } Train(train)
558 new TypeConstraint(body, Tuples.flatTupleOf(var_train), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Train")));
559 bodies.add(body);
560 }
561 return bodies;
562 }
563 }
564}
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/EndOfSiding_step_3.java b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/EndOfSiding_step_3.java
new file mode 100644
index 00000000..16b28a9f
--- /dev/null
+++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/EndOfSiding_step_3.java
@@ -0,0 +1,717 @@
1/**
2 * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql
3 */
4package modes3.queries;
5
6import java.util.Arrays;
7import java.util.Collection;
8import java.util.LinkedHashSet;
9import java.util.List;
10import java.util.Objects;
11import java.util.Optional;
12import java.util.Set;
13import java.util.function.Consumer;
14import java.util.stream.Collectors;
15import java.util.stream.Stream;
16import modes3.Segment;
17import modes3.Train;
18import org.apache.log4j.Logger;
19import org.eclipse.emf.ecore.EClass;
20import org.eclipse.viatra.query.runtime.api.IPatternMatch;
21import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
22import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
23import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
24import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
25import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
26import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
27import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
28import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
29import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
30import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
31import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
32import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
33import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
34import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
35import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
36import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
37import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
38import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
39import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
40import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
41
42/**
43 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
44 *
45 * <p>Original source:
46 * <code><pre>
47 * pattern endOfSiding_step_3(in train : Train, in location : Segment) {
48 * // int loop_bound1 = frame-{@literal >}location-{@literal >}connected_to_count;
49 * // for (int i1 = 0; i1 {@literal <} loop_bound1; i1++) {
50 * // ...
51 * // }
52 * Train(train);
53 * Train.location(train, location);
54 * }
55 * </pre></code>
56 *
57 * @see Matcher
58 * @see Match
59 *
60 */
61@SuppressWarnings("all")
62public final class EndOfSiding_step_3 extends BaseGeneratedEMFQuerySpecification<EndOfSiding_step_3.Matcher> {
63 /**
64 * Pattern-specific match representation of the modes3.queries.endOfSiding_step_3 pattern,
65 * to be used in conjunction with {@link Matcher}.
66 *
67 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
68 * Each instance is a (possibly partial) substitution of pattern parameters,
69 * usable to represent a match of the pattern in the result of a query,
70 * or to specify the bound (fixed) input parameters when issuing a query.
71 *
72 * @see Matcher
73 *
74 */
75 public static abstract class Match extends BasePatternMatch {
76 private Train fTrain;
77
78 private Segment fLocation;
79
80 private static List<String> parameterNames = makeImmutableList("train", "location");
81
82 private Match(final Train pTrain, final Segment pLocation) {
83 this.fTrain = pTrain;
84 this.fLocation = pLocation;
85 }
86
87 @Override
88 public Object get(final String parameterName) {
89 switch(parameterName) {
90 case "train": return this.fTrain;
91 case "location": return this.fLocation;
92 default: return null;
93 }
94 }
95
96 @Override
97 public Object get(final int index) {
98 switch(index) {
99 case 0: return this.fTrain;
100 case 1: return this.fLocation;
101 default: return null;
102 }
103 }
104
105 public Train getTrain() {
106 return this.fTrain;
107 }
108
109 public Segment getLocation() {
110 return this.fLocation;
111 }
112
113 @Override
114 public boolean set(final String parameterName, final Object newValue) {
115 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
116 if ("train".equals(parameterName) ) {
117 this.fTrain = (Train) newValue;
118 return true;
119 }
120 if ("location".equals(parameterName) ) {
121 this.fLocation = (Segment) newValue;
122 return true;
123 }
124 return false;
125 }
126
127 public void setTrain(final Train pTrain) {
128 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
129 this.fTrain = pTrain;
130 }
131
132 public void setLocation(final Segment pLocation) {
133 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
134 this.fLocation = pLocation;
135 }
136
137 @Override
138 public String patternName() {
139 return "modes3.queries.endOfSiding_step_3";
140 }
141
142 @Override
143 public List<String> parameterNames() {
144 return EndOfSiding_step_3.Match.parameterNames;
145 }
146
147 @Override
148 public Object[] toArray() {
149 return new Object[]{fTrain, fLocation};
150 }
151
152 @Override
153 public EndOfSiding_step_3.Match toImmutable() {
154 return isMutable() ? newMatch(fTrain, fLocation) : this;
155 }
156
157 @Override
158 public String prettyPrint() {
159 StringBuilder result = new StringBuilder();
160 result.append("\"train\"=" + prettyPrintValue(fTrain) + ", ");
161 result.append("\"location\"=" + prettyPrintValue(fLocation));
162 return result.toString();
163 }
164
165 @Override
166 public int hashCode() {
167 return Objects.hash(fTrain, fLocation);
168 }
169
170 @Override
171 public boolean equals(final Object obj) {
172 if (this == obj)
173 return true;
174 if (obj == null) {
175 return false;
176 }
177 if ((obj instanceof EndOfSiding_step_3.Match)) {
178 EndOfSiding_step_3.Match other = (EndOfSiding_step_3.Match) obj;
179 return Objects.equals(fTrain, other.fTrain) && Objects.equals(fLocation, other.fLocation);
180 } else {
181 // this should be infrequent
182 if (!(obj instanceof IPatternMatch)) {
183 return false;
184 }
185 IPatternMatch otherSig = (IPatternMatch) obj;
186 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
187 }
188 }
189
190 @Override
191 public EndOfSiding_step_3 specification() {
192 return EndOfSiding_step_3.instance();
193 }
194
195 /**
196 * Returns an empty, mutable match.
197 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
198 *
199 * @return the empty match.
200 *
201 */
202 public static EndOfSiding_step_3.Match newEmptyMatch() {
203 return new Mutable(null, null);
204 }
205
206 /**
207 * Returns a mutable (partial) match.
208 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
209 *
210 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
211 * @param pLocation the fixed value of pattern parameter location, or null if not bound.
212 * @return the new, mutable (partial) match object.
213 *
214 */
215 public static EndOfSiding_step_3.Match newMutableMatch(final Train pTrain, final Segment pLocation) {
216 return new Mutable(pTrain, pLocation);
217 }
218
219 /**
220 * Returns a new (partial) match.
221 * This can be used e.g. to call the matcher with a partial match.
222 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
223 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
224 * @param pLocation the fixed value of pattern parameter location, or null if not bound.
225 * @return the (partial) match object.
226 *
227 */
228 public static EndOfSiding_step_3.Match newMatch(final Train pTrain, final Segment pLocation) {
229 return new Immutable(pTrain, pLocation);
230 }
231
232 private static final class Mutable extends EndOfSiding_step_3.Match {
233 Mutable(final Train pTrain, final Segment pLocation) {
234 super(pTrain, pLocation);
235 }
236
237 @Override
238 public boolean isMutable() {
239 return true;
240 }
241 }
242
243 private static final class Immutable extends EndOfSiding_step_3.Match {
244 Immutable(final Train pTrain, final Segment pLocation) {
245 super(pTrain, pLocation);
246 }
247
248 @Override
249 public boolean isMutable() {
250 return false;
251 }
252 }
253 }
254
255 /**
256 * Generated pattern matcher API of the modes3.queries.endOfSiding_step_3 pattern,
257 * providing pattern-specific query methods.
258 *
259 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
260 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
261 *
262 * <p>Matches of the pattern will be represented as {@link Match}.
263 *
264 * <p>Original source:
265 * <code><pre>
266 * pattern endOfSiding_step_3(in train : Train, in location : Segment) {
267 * // int loop_bound1 = frame-{@literal >}location-{@literal >}connected_to_count;
268 * // for (int i1 = 0; i1 {@literal <} loop_bound1; i1++) {
269 * // ...
270 * // }
271 * Train(train);
272 * Train.location(train, location);
273 * }
274 * </pre></code>
275 *
276 * @see Match
277 * @see EndOfSiding_step_3
278 *
279 */
280 public static class Matcher extends BaseMatcher<EndOfSiding_step_3.Match> {
281 /**
282 * Initializes the pattern matcher within an existing VIATRA Query engine.
283 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
284 *
285 * @param engine the existing VIATRA Query engine in which this matcher will be created.
286 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
287 *
288 */
289 public static EndOfSiding_step_3.Matcher on(final ViatraQueryEngine engine) {
290 // check if matcher already exists
291 Matcher matcher = engine.getExistingMatcher(querySpecification());
292 if (matcher == null) {
293 matcher = (Matcher)engine.getMatcher(querySpecification());
294 }
295 return matcher;
296 }
297
298 /**
299 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
300 * @return an initialized matcher
301 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
302 *
303 */
304 public static EndOfSiding_step_3.Matcher create() {
305 return new Matcher();
306 }
307
308 private static final int POSITION_TRAIN = 0;
309
310 private static final int POSITION_LOCATION = 1;
311
312 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(EndOfSiding_step_3.Matcher.class);
313
314 /**
315 * Initializes the pattern matcher within an existing VIATRA Query engine.
316 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
317 *
318 * @param engine the existing VIATRA Query engine in which this matcher will be created.
319 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
320 *
321 */
322 private Matcher() {
323 super(querySpecification());
324 }
325
326 /**
327 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
328 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
329 * @param pLocation the fixed value of pattern parameter location, or null if not bound.
330 * @return matches represented as a Match object.
331 *
332 */
333 public Collection<EndOfSiding_step_3.Match> getAllMatches(final Train pTrain, final Segment pLocation) {
334 return rawStreamAllMatches(new Object[]{pTrain, pLocation}).collect(Collectors.toSet());
335 }
336
337 /**
338 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
339 * </p>
340 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
341 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
342 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
343 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
344 * @param pLocation the fixed value of pattern parameter location, or null if not bound.
345 * @return a stream of matches represented as a Match object.
346 *
347 */
348 public Stream<EndOfSiding_step_3.Match> streamAllMatches(final Train pTrain, final Segment pLocation) {
349 return rawStreamAllMatches(new Object[]{pTrain, pLocation});
350 }
351
352 /**
353 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
354 * Neither determinism nor randomness of selection is guaranteed.
355 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
356 * @param pLocation the fixed value of pattern parameter location, or null if not bound.
357 * @return a match represented as a Match object, or null if no match is found.
358 *
359 */
360 public Optional<EndOfSiding_step_3.Match> getOneArbitraryMatch(final Train pTrain, final Segment pLocation) {
361 return rawGetOneArbitraryMatch(new Object[]{pTrain, pLocation});
362 }
363
364 /**
365 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
366 * under any possible substitution of the unspecified parameters (if any).
367 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
368 * @param pLocation the fixed value of pattern parameter location, or null if not bound.
369 * @return true if the input is a valid (partial) match of the pattern.
370 *
371 */
372 public boolean hasMatch(final Train pTrain, final Segment pLocation) {
373 return rawHasMatch(new Object[]{pTrain, pLocation});
374 }
375
376 /**
377 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
378 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
379 * @param pLocation the fixed value of pattern parameter location, or null if not bound.
380 * @return the number of pattern matches found.
381 *
382 */
383 public int countMatches(final Train pTrain, final Segment pLocation) {
384 return rawCountMatches(new Object[]{pTrain, pLocation});
385 }
386
387 /**
388 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
389 * Neither determinism nor randomness of selection is guaranteed.
390 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
391 * @param pLocation the fixed value of pattern parameter location, or null if not bound.
392 * @param processor the action that will process the selected match.
393 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
394 *
395 */
396 public boolean forOneArbitraryMatch(final Train pTrain, final Segment pLocation, final Consumer<? super EndOfSiding_step_3.Match> processor) {
397 return rawForOneArbitraryMatch(new Object[]{pTrain, pLocation}, processor);
398 }
399
400 /**
401 * Returns a new (partial) match.
402 * This can be used e.g. to call the matcher with a partial match.
403 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
404 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
405 * @param pLocation the fixed value of pattern parameter location, or null if not bound.
406 * @return the (partial) match object.
407 *
408 */
409 public EndOfSiding_step_3.Match newMatch(final Train pTrain, final Segment pLocation) {
410 return EndOfSiding_step_3.Match.newMatch(pTrain, pLocation);
411 }
412
413 /**
414 * Retrieve the set of values that occur in matches for train.
415 * @return the Set of all values or empty set if there are no matches
416 *
417 */
418 protected Stream<Train> rawStreamAllValuesOftrain(final Object[] parameters) {
419 return rawStreamAllValues(POSITION_TRAIN, parameters).map(Train.class::cast);
420 }
421
422 /**
423 * Retrieve the set of values that occur in matches for train.
424 * @return the Set of all values or empty set if there are no matches
425 *
426 */
427 public Set<Train> getAllValuesOftrain() {
428 return rawStreamAllValuesOftrain(emptyArray()).collect(Collectors.toSet());
429 }
430
431 /**
432 * Retrieve the set of values that occur in matches for train.
433 * @return the Set of all values or empty set if there are no matches
434 *
435 */
436 public Stream<Train> streamAllValuesOftrain() {
437 return rawStreamAllValuesOftrain(emptyArray());
438 }
439
440 /**
441 * Retrieve the set of values that occur in matches for train.
442 * </p>
443 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
444 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
445 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
446 *
447 * @return the Stream of all values or empty set if there are no matches
448 *
449 */
450 public Stream<Train> streamAllValuesOftrain(final EndOfSiding_step_3.Match partialMatch) {
451 return rawStreamAllValuesOftrain(partialMatch.toArray());
452 }
453
454 /**
455 * Retrieve the set of values that occur in matches for train.
456 * </p>
457 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
458 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
459 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
460 *
461 * @return the Stream of all values or empty set if there are no matches
462 *
463 */
464 public Stream<Train> streamAllValuesOftrain(final Segment pLocation) {
465 return rawStreamAllValuesOftrain(new Object[]{null, pLocation});
466 }
467
468 /**
469 * Retrieve the set of values that occur in matches for train.
470 * @return the Set of all values or empty set if there are no matches
471 *
472 */
473 public Set<Train> getAllValuesOftrain(final EndOfSiding_step_3.Match partialMatch) {
474 return rawStreamAllValuesOftrain(partialMatch.toArray()).collect(Collectors.toSet());
475 }
476
477 /**
478 * Retrieve the set of values that occur in matches for train.
479 * @return the Set of all values or empty set if there are no matches
480 *
481 */
482 public Set<Train> getAllValuesOftrain(final Segment pLocation) {
483 return rawStreamAllValuesOftrain(new Object[]{null, pLocation}).collect(Collectors.toSet());
484 }
485
486 /**
487 * Retrieve the set of values that occur in matches for location.
488 * @return the Set of all values or empty set if there are no matches
489 *
490 */
491 protected Stream<Segment> rawStreamAllValuesOflocation(final Object[] parameters) {
492 return rawStreamAllValues(POSITION_LOCATION, parameters).map(Segment.class::cast);
493 }
494
495 /**
496 * Retrieve the set of values that occur in matches for location.
497 * @return the Set of all values or empty set if there are no matches
498 *
499 */
500 public Set<Segment> getAllValuesOflocation() {
501 return rawStreamAllValuesOflocation(emptyArray()).collect(Collectors.toSet());
502 }
503
504 /**
505 * Retrieve the set of values that occur in matches for location.
506 * @return the Set of all values or empty set if there are no matches
507 *
508 */
509 public Stream<Segment> streamAllValuesOflocation() {
510 return rawStreamAllValuesOflocation(emptyArray());
511 }
512
513 /**
514 * Retrieve the set of values that occur in matches for location.
515 * </p>
516 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
517 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
518 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
519 *
520 * @return the Stream of all values or empty set if there are no matches
521 *
522 */
523 public Stream<Segment> streamAllValuesOflocation(final EndOfSiding_step_3.Match partialMatch) {
524 return rawStreamAllValuesOflocation(partialMatch.toArray());
525 }
526
527 /**
528 * Retrieve the set of values that occur in matches for location.
529 * </p>
530 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
531 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
532 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
533 *
534 * @return the Stream of all values or empty set if there are no matches
535 *
536 */
537 public Stream<Segment> streamAllValuesOflocation(final Train pTrain) {
538 return rawStreamAllValuesOflocation(new Object[]{pTrain, null});
539 }
540
541 /**
542 * Retrieve the set of values that occur in matches for location.
543 * @return the Set of all values or empty set if there are no matches
544 *
545 */
546 public Set<Segment> getAllValuesOflocation(final EndOfSiding_step_3.Match partialMatch) {
547 return rawStreamAllValuesOflocation(partialMatch.toArray()).collect(Collectors.toSet());
548 }
549
550 /**
551 * Retrieve the set of values that occur in matches for location.
552 * @return the Set of all values or empty set if there are no matches
553 *
554 */
555 public Set<Segment> getAllValuesOflocation(final Train pTrain) {
556 return rawStreamAllValuesOflocation(new Object[]{pTrain, null}).collect(Collectors.toSet());
557 }
558
559 @Override
560 protected EndOfSiding_step_3.Match tupleToMatch(final Tuple t) {
561 try {
562 return EndOfSiding_step_3.Match.newMatch((Train) t.get(POSITION_TRAIN), (Segment) t.get(POSITION_LOCATION));
563 } catch(ClassCastException e) {
564 LOGGER.error("Element(s) in tuple not properly typed!",e);
565 return null;
566 }
567 }
568
569 @Override
570 protected EndOfSiding_step_3.Match arrayToMatch(final Object[] match) {
571 try {
572 return EndOfSiding_step_3.Match.newMatch((Train) match[POSITION_TRAIN], (Segment) match[POSITION_LOCATION]);
573 } catch(ClassCastException e) {
574 LOGGER.error("Element(s) in array not properly typed!",e);
575 return null;
576 }
577 }
578
579 @Override
580 protected EndOfSiding_step_3.Match arrayToMatchMutable(final Object[] match) {
581 try {
582 return EndOfSiding_step_3.Match.newMutableMatch((Train) match[POSITION_TRAIN], (Segment) match[POSITION_LOCATION]);
583 } catch(ClassCastException e) {
584 LOGGER.error("Element(s) in array not properly typed!",e);
585 return null;
586 }
587 }
588
589 /**
590 * @return the singleton instance of the query specification of this pattern
591 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
592 *
593 */
594 public static IQuerySpecification<EndOfSiding_step_3.Matcher> querySpecification() {
595 return EndOfSiding_step_3.instance();
596 }
597 }
598
599 private EndOfSiding_step_3() {
600 super(GeneratedPQuery.INSTANCE);
601 }
602
603 /**
604 * @return the singleton instance of the query specification
605 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
606 *
607 */
608 public static EndOfSiding_step_3 instance() {
609 try{
610 return LazyHolder.INSTANCE;
611 } catch (ExceptionInInitializerError err) {
612 throw processInitializerError(err);
613 }
614 }
615
616 @Override
617 protected EndOfSiding_step_3.Matcher instantiate(final ViatraQueryEngine engine) {
618 return EndOfSiding_step_3.Matcher.on(engine);
619 }
620
621 @Override
622 public EndOfSiding_step_3.Matcher instantiate() {
623 return EndOfSiding_step_3.Matcher.create();
624 }
625
626 @Override
627 public EndOfSiding_step_3.Match newEmptyMatch() {
628 return EndOfSiding_step_3.Match.newEmptyMatch();
629 }
630
631 @Override
632 public EndOfSiding_step_3.Match newMatch(final Object... parameters) {
633 return EndOfSiding_step_3.Match.newMatch((modes3.Train) parameters[0], (modes3.Segment) parameters[1]);
634 }
635
636 /**
637 * Inner class allowing the singleton instance of {@link EndOfSiding_step_3} to be created
638 * <b>not</b> at the class load time of the outer class,
639 * but rather at the first call to {@link EndOfSiding_step_3#instance()}.
640 *
641 * <p> This workaround is required e.g. to support recursion.
642 *
643 */
644 private static class LazyHolder {
645 private static final EndOfSiding_step_3 INSTANCE = new EndOfSiding_step_3();
646
647 /**
648 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
649 * This initialization order is required to support indirect recursion.
650 *
651 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
652 *
653 */
654 private static final Object STATIC_INITIALIZER = ensureInitialized();
655
656 public static Object ensureInitialized() {
657 INSTANCE.ensureInitializedInternal();
658 return null;
659 }
660 }
661
662 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
663 private static final EndOfSiding_step_3.GeneratedPQuery INSTANCE = new GeneratedPQuery();
664
665 private final PParameter parameter_train = new PParameter("train", "modes3.Train", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Train")), PParameterDirection.INOUT);
666
667 private final PParameter parameter_location = new PParameter("location", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT);
668
669 private final List<PParameter> parameters = Arrays.asList(parameter_train, parameter_location);
670
671 private GeneratedPQuery() {
672 super(PVisibility.PUBLIC);
673 }
674
675 @Override
676 public String getFullyQualifiedName() {
677 return "modes3.queries.endOfSiding_step_3";
678 }
679
680 @Override
681 public List<String> getParameterNames() {
682 return Arrays.asList("train","location");
683 }
684
685 @Override
686 public List<PParameter> getParameters() {
687 return parameters;
688 }
689
690 @Override
691 public Set<PBody> doGetContainedBodies() {
692 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
693 Set<PBody> bodies = new LinkedHashSet<>();
694 {
695 PBody body = new PBody(this);
696 PVariable var_train = body.getOrCreateVariableByName("train");
697 PVariable var_location = body.getOrCreateVariableByName("location");
698 new TypeConstraint(body, Tuples.flatTupleOf(var_train), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Train")));
699 new TypeConstraint(body, Tuples.flatTupleOf(var_location), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
700 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
701 new ExportedParameter(body, var_train, parameter_train),
702 new ExportedParameter(body, var_location, parameter_location)
703 ));
704 // // int loop_bound1 = frame->location->connected_to_count;// for (int i1 = 0; i1 < loop_bound1; i1++) {// ...// } Train(train)
705 new TypeConstraint(body, Tuples.flatTupleOf(var_train), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Train")));
706 // Train.location(train, location)
707 new TypeConstraint(body, Tuples.flatTupleOf(var_train), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Train")));
708 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
709 new TypeConstraint(body, Tuples.flatTupleOf(var_train, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Train", "location")));
710 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
711 new Equality(body, var__virtual_0_, var_location);
712 bodies.add(body);
713 }
714 return bodies;
715 }
716 }
717}
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/EndOfSiding_step_4.java b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/EndOfSiding_step_4.java
new file mode 100644
index 00000000..73df8514
--- /dev/null
+++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/EndOfSiding_step_4.java
@@ -0,0 +1,847 @@
1/**
2 * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql
3 */
4package modes3.queries;
5
6import java.util.Arrays;
7import java.util.Collection;
8import java.util.LinkedHashSet;
9import java.util.List;
10import java.util.Objects;
11import java.util.Optional;
12import java.util.Set;
13import java.util.function.Consumer;
14import java.util.stream.Collectors;
15import java.util.stream.Stream;
16import modes3.Segment;
17import modes3.Train;
18import org.apache.log4j.Logger;
19import org.eclipse.emf.ecore.EClass;
20import org.eclipse.viatra.query.runtime.api.IPatternMatch;
21import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
22import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
23import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
24import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
25import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
26import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
27import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
28import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
29import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
30import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
31import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
32import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
33import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
34import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
35import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
36import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
37import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
38import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
39import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
40import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
41
42/**
43 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
44 *
45 * <p>Original source:
46 * <code><pre>
47 * pattern endOfSiding_step_4(in train : Train, in location : Segment, in end : Segment) {
48 * // frame-{@literal >}end = frame-{@literal >}location-{@literal >}connected_to[i1];
49 * // if (frame-{@literal >}end != NULL &&
50 * // frame-{@literal >}end-{@literal >}connected_to[1] == frame-{@literal >}location &&
51 * // frame-{@literal >}end-{@literal >}connected_to[0] == NULL) {
52 * // ...
53 * // }
54 * // if (frame-{@literal >}end != NULL &&
55 * // frame-{@literal >}end-{@literal >}connected_to[0] == frame-{@literal >}location &&
56 * // frame-{@literal >}end-{@literal >}connected_to[1] == NULL) {
57 * // ...
58 * // }
59 * Train(train);
60 * Train.location(train, location);
61 * Segment.connectedTo(location, end);
62 * }
63 * </pre></code>
64 *
65 * @see Matcher
66 * @see Match
67 *
68 */
69@SuppressWarnings("all")
70public final class EndOfSiding_step_4 extends BaseGeneratedEMFQuerySpecification<EndOfSiding_step_4.Matcher> {
71 /**
72 * Pattern-specific match representation of the modes3.queries.endOfSiding_step_4 pattern,
73 * to be used in conjunction with {@link Matcher}.
74 *
75 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
76 * Each instance is a (possibly partial) substitution of pattern parameters,
77 * usable to represent a match of the pattern in the result of a query,
78 * or to specify the bound (fixed) input parameters when issuing a query.
79 *
80 * @see Matcher
81 *
82 */
83 public static abstract class Match extends BasePatternMatch {
84 private Train fTrain;
85
86 private Segment fLocation;
87
88 private Segment fEnd;
89
90 private static List<String> parameterNames = makeImmutableList("train", "location", "end");
91
92 private Match(final Train pTrain, final Segment pLocation, final Segment pEnd) {
93 this.fTrain = pTrain;
94 this.fLocation = pLocation;
95 this.fEnd = pEnd;
96 }
97
98 @Override
99 public Object get(final String parameterName) {
100 switch(parameterName) {
101 case "train": return this.fTrain;
102 case "location": return this.fLocation;
103 case "end": return this.fEnd;
104 default: return null;
105 }
106 }
107
108 @Override
109 public Object get(final int index) {
110 switch(index) {
111 case 0: return this.fTrain;
112 case 1: return this.fLocation;
113 case 2: return this.fEnd;
114 default: return null;
115 }
116 }
117
118 public Train getTrain() {
119 return this.fTrain;
120 }
121
122 public Segment getLocation() {
123 return this.fLocation;
124 }
125
126 public Segment getEnd() {
127 return this.fEnd;
128 }
129
130 @Override
131 public boolean set(final String parameterName, final Object newValue) {
132 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
133 if ("train".equals(parameterName) ) {
134 this.fTrain = (Train) newValue;
135 return true;
136 }
137 if ("location".equals(parameterName) ) {
138 this.fLocation = (Segment) newValue;
139 return true;
140 }
141 if ("end".equals(parameterName) ) {
142 this.fEnd = (Segment) newValue;
143 return true;
144 }
145 return false;
146 }
147
148 public void setTrain(final Train pTrain) {
149 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
150 this.fTrain = pTrain;
151 }
152
153 public void setLocation(final Segment pLocation) {
154 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
155 this.fLocation = pLocation;
156 }
157
158 public void setEnd(final Segment pEnd) {
159 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
160 this.fEnd = pEnd;
161 }
162
163 @Override
164 public String patternName() {
165 return "modes3.queries.endOfSiding_step_4";
166 }
167
168 @Override
169 public List<String> parameterNames() {
170 return EndOfSiding_step_4.Match.parameterNames;
171 }
172
173 @Override
174 public Object[] toArray() {
175 return new Object[]{fTrain, fLocation, fEnd};
176 }
177
178 @Override
179 public EndOfSiding_step_4.Match toImmutable() {
180 return isMutable() ? newMatch(fTrain, fLocation, fEnd) : this;
181 }
182
183 @Override
184 public String prettyPrint() {
185 StringBuilder result = new StringBuilder();
186 result.append("\"train\"=" + prettyPrintValue(fTrain) + ", ");
187 result.append("\"location\"=" + prettyPrintValue(fLocation) + ", ");
188 result.append("\"end\"=" + prettyPrintValue(fEnd));
189 return result.toString();
190 }
191
192 @Override
193 public int hashCode() {
194 return Objects.hash(fTrain, fLocation, fEnd);
195 }
196
197 @Override
198 public boolean equals(final Object obj) {
199 if (this == obj)
200 return true;
201 if (obj == null) {
202 return false;
203 }
204 if ((obj instanceof EndOfSiding_step_4.Match)) {
205 EndOfSiding_step_4.Match other = (EndOfSiding_step_4.Match) obj;
206 return Objects.equals(fTrain, other.fTrain) && Objects.equals(fLocation, other.fLocation) && Objects.equals(fEnd, other.fEnd);
207 } else {
208 // this should be infrequent
209 if (!(obj instanceof IPatternMatch)) {
210 return false;
211 }
212 IPatternMatch otherSig = (IPatternMatch) obj;
213 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
214 }
215 }
216
217 @Override
218 public EndOfSiding_step_4 specification() {
219 return EndOfSiding_step_4.instance();
220 }
221
222 /**
223 * Returns an empty, mutable match.
224 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
225 *
226 * @return the empty match.
227 *
228 */
229 public static EndOfSiding_step_4.Match newEmptyMatch() {
230 return new Mutable(null, null, null);
231 }
232
233 /**
234 * Returns a mutable (partial) match.
235 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
236 *
237 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
238 * @param pLocation the fixed value of pattern parameter location, or null if not bound.
239 * @param pEnd the fixed value of pattern parameter end, or null if not bound.
240 * @return the new, mutable (partial) match object.
241 *
242 */
243 public static EndOfSiding_step_4.Match newMutableMatch(final Train pTrain, final Segment pLocation, final Segment pEnd) {
244 return new Mutable(pTrain, pLocation, pEnd);
245 }
246
247 /**
248 * Returns a new (partial) match.
249 * This can be used e.g. to call the matcher with a partial match.
250 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
251 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
252 * @param pLocation the fixed value of pattern parameter location, or null if not bound.
253 * @param pEnd the fixed value of pattern parameter end, or null if not bound.
254 * @return the (partial) match object.
255 *
256 */
257 public static EndOfSiding_step_4.Match newMatch(final Train pTrain, final Segment pLocation, final Segment pEnd) {
258 return new Immutable(pTrain, pLocation, pEnd);
259 }
260
261 private static final class Mutable extends EndOfSiding_step_4.Match {
262 Mutable(final Train pTrain, final Segment pLocation, final Segment pEnd) {
263 super(pTrain, pLocation, pEnd);
264 }
265
266 @Override
267 public boolean isMutable() {
268 return true;
269 }
270 }
271
272 private static final class Immutable extends EndOfSiding_step_4.Match {
273 Immutable(final Train pTrain, final Segment pLocation, final Segment pEnd) {
274 super(pTrain, pLocation, pEnd);
275 }
276
277 @Override
278 public boolean isMutable() {
279 return false;
280 }
281 }
282 }
283
284 /**
285 * Generated pattern matcher API of the modes3.queries.endOfSiding_step_4 pattern,
286 * providing pattern-specific query methods.
287 *
288 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
289 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
290 *
291 * <p>Matches of the pattern will be represented as {@link Match}.
292 *
293 * <p>Original source:
294 * <code><pre>
295 * pattern endOfSiding_step_4(in train : Train, in location : Segment, in end : Segment) {
296 * // frame-{@literal >}end = frame-{@literal >}location-{@literal >}connected_to[i1];
297 * // if (frame-{@literal >}end != NULL &&
298 * // frame-{@literal >}end-{@literal >}connected_to[1] == frame-{@literal >}location &&
299 * // frame-{@literal >}end-{@literal >}connected_to[0] == NULL) {
300 * // ...
301 * // }
302 * // if (frame-{@literal >}end != NULL &&
303 * // frame-{@literal >}end-{@literal >}connected_to[0] == frame-{@literal >}location &&
304 * // frame-{@literal >}end-{@literal >}connected_to[1] == NULL) {
305 * // ...
306 * // }
307 * Train(train);
308 * Train.location(train, location);
309 * Segment.connectedTo(location, end);
310 * }
311 * </pre></code>
312 *
313 * @see Match
314 * @see EndOfSiding_step_4
315 *
316 */
317 public static class Matcher extends BaseMatcher<EndOfSiding_step_4.Match> {
318 /**
319 * Initializes the pattern matcher within an existing VIATRA Query engine.
320 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
321 *
322 * @param engine the existing VIATRA Query engine in which this matcher will be created.
323 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
324 *
325 */
326 public static EndOfSiding_step_4.Matcher on(final ViatraQueryEngine engine) {
327 // check if matcher already exists
328 Matcher matcher = engine.getExistingMatcher(querySpecification());
329 if (matcher == null) {
330 matcher = (Matcher)engine.getMatcher(querySpecification());
331 }
332 return matcher;
333 }
334
335 /**
336 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
337 * @return an initialized matcher
338 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
339 *
340 */
341 public static EndOfSiding_step_4.Matcher create() {
342 return new Matcher();
343 }
344
345 private static final int POSITION_TRAIN = 0;
346
347 private static final int POSITION_LOCATION = 1;
348
349 private static final int POSITION_END = 2;
350
351 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(EndOfSiding_step_4.Matcher.class);
352
353 /**
354 * Initializes the pattern matcher within an existing VIATRA Query engine.
355 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
356 *
357 * @param engine the existing VIATRA Query engine in which this matcher will be created.
358 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
359 *
360 */
361 private Matcher() {
362 super(querySpecification());
363 }
364
365 /**
366 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
367 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
368 * @param pLocation the fixed value of pattern parameter location, or null if not bound.
369 * @param pEnd the fixed value of pattern parameter end, or null if not bound.
370 * @return matches represented as a Match object.
371 *
372 */
373 public Collection<EndOfSiding_step_4.Match> getAllMatches(final Train pTrain, final Segment pLocation, final Segment pEnd) {
374 return rawStreamAllMatches(new Object[]{pTrain, pLocation, pEnd}).collect(Collectors.toSet());
375 }
376
377 /**
378 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
379 * </p>
380 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
381 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
382 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
383 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
384 * @param pLocation the fixed value of pattern parameter location, or null if not bound.
385 * @param pEnd the fixed value of pattern parameter end, or null if not bound.
386 * @return a stream of matches represented as a Match object.
387 *
388 */
389 public Stream<EndOfSiding_step_4.Match> streamAllMatches(final Train pTrain, final Segment pLocation, final Segment pEnd) {
390 return rawStreamAllMatches(new Object[]{pTrain, pLocation, pEnd});
391 }
392
393 /**
394 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
395 * Neither determinism nor randomness of selection is guaranteed.
396 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
397 * @param pLocation the fixed value of pattern parameter location, or null if not bound.
398 * @param pEnd the fixed value of pattern parameter end, or null if not bound.
399 * @return a match represented as a Match object, or null if no match is found.
400 *
401 */
402 public Optional<EndOfSiding_step_4.Match> getOneArbitraryMatch(final Train pTrain, final Segment pLocation, final Segment pEnd) {
403 return rawGetOneArbitraryMatch(new Object[]{pTrain, pLocation, pEnd});
404 }
405
406 /**
407 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
408 * under any possible substitution of the unspecified parameters (if any).
409 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
410 * @param pLocation the fixed value of pattern parameter location, or null if not bound.
411 * @param pEnd the fixed value of pattern parameter end, or null if not bound.
412 * @return true if the input is a valid (partial) match of the pattern.
413 *
414 */
415 public boolean hasMatch(final Train pTrain, final Segment pLocation, final Segment pEnd) {
416 return rawHasMatch(new Object[]{pTrain, pLocation, pEnd});
417 }
418
419 /**
420 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
421 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
422 * @param pLocation the fixed value of pattern parameter location, or null if not bound.
423 * @param pEnd the fixed value of pattern parameter end, or null if not bound.
424 * @return the number of pattern matches found.
425 *
426 */
427 public int countMatches(final Train pTrain, final Segment pLocation, final Segment pEnd) {
428 return rawCountMatches(new Object[]{pTrain, pLocation, pEnd});
429 }
430
431 /**
432 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
433 * Neither determinism nor randomness of selection is guaranteed.
434 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
435 * @param pLocation the fixed value of pattern parameter location, or null if not bound.
436 * @param pEnd the fixed value of pattern parameter end, or null if not bound.
437 * @param processor the action that will process the selected match.
438 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
439 *
440 */
441 public boolean forOneArbitraryMatch(final Train pTrain, final Segment pLocation, final Segment pEnd, final Consumer<? super EndOfSiding_step_4.Match> processor) {
442 return rawForOneArbitraryMatch(new Object[]{pTrain, pLocation, pEnd}, processor);
443 }
444
445 /**
446 * Returns a new (partial) match.
447 * This can be used e.g. to call the matcher with a partial match.
448 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
449 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
450 * @param pLocation the fixed value of pattern parameter location, or null if not bound.
451 * @param pEnd the fixed value of pattern parameter end, or null if not bound.
452 * @return the (partial) match object.
453 *
454 */
455 public EndOfSiding_step_4.Match newMatch(final Train pTrain, final Segment pLocation, final Segment pEnd) {
456 return EndOfSiding_step_4.Match.newMatch(pTrain, pLocation, pEnd);
457 }
458
459 /**
460 * Retrieve the set of values that occur in matches for train.
461 * @return the Set of all values or empty set if there are no matches
462 *
463 */
464 protected Stream<Train> rawStreamAllValuesOftrain(final Object[] parameters) {
465 return rawStreamAllValues(POSITION_TRAIN, parameters).map(Train.class::cast);
466 }
467
468 /**
469 * Retrieve the set of values that occur in matches for train.
470 * @return the Set of all values or empty set if there are no matches
471 *
472 */
473 public Set<Train> getAllValuesOftrain() {
474 return rawStreamAllValuesOftrain(emptyArray()).collect(Collectors.toSet());
475 }
476
477 /**
478 * Retrieve the set of values that occur in matches for train.
479 * @return the Set of all values or empty set if there are no matches
480 *
481 */
482 public Stream<Train> streamAllValuesOftrain() {
483 return rawStreamAllValuesOftrain(emptyArray());
484 }
485
486 /**
487 * Retrieve the set of values that occur in matches for train.
488 * </p>
489 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
490 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
491 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
492 *
493 * @return the Stream of all values or empty set if there are no matches
494 *
495 */
496 public Stream<Train> streamAllValuesOftrain(final EndOfSiding_step_4.Match partialMatch) {
497 return rawStreamAllValuesOftrain(partialMatch.toArray());
498 }
499
500 /**
501 * Retrieve the set of values that occur in matches for train.
502 * </p>
503 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
504 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
505 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
506 *
507 * @return the Stream of all values or empty set if there are no matches
508 *
509 */
510 public Stream<Train> streamAllValuesOftrain(final Segment pLocation, final Segment pEnd) {
511 return rawStreamAllValuesOftrain(new Object[]{null, pLocation, pEnd});
512 }
513
514 /**
515 * Retrieve the set of values that occur in matches for train.
516 * @return the Set of all values or empty set if there are no matches
517 *
518 */
519 public Set<Train> getAllValuesOftrain(final EndOfSiding_step_4.Match partialMatch) {
520 return rawStreamAllValuesOftrain(partialMatch.toArray()).collect(Collectors.toSet());
521 }
522
523 /**
524 * Retrieve the set of values that occur in matches for train.
525 * @return the Set of all values or empty set if there are no matches
526 *
527 */
528 public Set<Train> getAllValuesOftrain(final Segment pLocation, final Segment pEnd) {
529 return rawStreamAllValuesOftrain(new Object[]{null, pLocation, pEnd}).collect(Collectors.toSet());
530 }
531
532 /**
533 * Retrieve the set of values that occur in matches for location.
534 * @return the Set of all values or empty set if there are no matches
535 *
536 */
537 protected Stream<Segment> rawStreamAllValuesOflocation(final Object[] parameters) {
538 return rawStreamAllValues(POSITION_LOCATION, parameters).map(Segment.class::cast);
539 }
540
541 /**
542 * Retrieve the set of values that occur in matches for location.
543 * @return the Set of all values or empty set if there are no matches
544 *
545 */
546 public Set<Segment> getAllValuesOflocation() {
547 return rawStreamAllValuesOflocation(emptyArray()).collect(Collectors.toSet());
548 }
549
550 /**
551 * Retrieve the set of values that occur in matches for location.
552 * @return the Set of all values or empty set if there are no matches
553 *
554 */
555 public Stream<Segment> streamAllValuesOflocation() {
556 return rawStreamAllValuesOflocation(emptyArray());
557 }
558
559 /**
560 * Retrieve the set of values that occur in matches for location.
561 * </p>
562 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
563 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
564 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
565 *
566 * @return the Stream of all values or empty set if there are no matches
567 *
568 */
569 public Stream<Segment> streamAllValuesOflocation(final EndOfSiding_step_4.Match partialMatch) {
570 return rawStreamAllValuesOflocation(partialMatch.toArray());
571 }
572
573 /**
574 * Retrieve the set of values that occur in matches for location.
575 * </p>
576 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
577 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
578 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
579 *
580 * @return the Stream of all values or empty set if there are no matches
581 *
582 */
583 public Stream<Segment> streamAllValuesOflocation(final Train pTrain, final Segment pEnd) {
584 return rawStreamAllValuesOflocation(new Object[]{pTrain, null, pEnd});
585 }
586
587 /**
588 * Retrieve the set of values that occur in matches for location.
589 * @return the Set of all values or empty set if there are no matches
590 *
591 */
592 public Set<Segment> getAllValuesOflocation(final EndOfSiding_step_4.Match partialMatch) {
593 return rawStreamAllValuesOflocation(partialMatch.toArray()).collect(Collectors.toSet());
594 }
595
596 /**
597 * Retrieve the set of values that occur in matches for location.
598 * @return the Set of all values or empty set if there are no matches
599 *
600 */
601 public Set<Segment> getAllValuesOflocation(final Train pTrain, final Segment pEnd) {
602 return rawStreamAllValuesOflocation(new Object[]{pTrain, null, pEnd}).collect(Collectors.toSet());
603 }
604
605 /**
606 * Retrieve the set of values that occur in matches for end.
607 * @return the Set of all values or empty set if there are no matches
608 *
609 */
610 protected Stream<Segment> rawStreamAllValuesOfend(final Object[] parameters) {
611 return rawStreamAllValues(POSITION_END, parameters).map(Segment.class::cast);
612 }
613
614 /**
615 * Retrieve the set of values that occur in matches for end.
616 * @return the Set of all values or empty set if there are no matches
617 *
618 */
619 public Set<Segment> getAllValuesOfend() {
620 return rawStreamAllValuesOfend(emptyArray()).collect(Collectors.toSet());
621 }
622
623 /**
624 * Retrieve the set of values that occur in matches for end.
625 * @return the Set of all values or empty set if there are no matches
626 *
627 */
628 public Stream<Segment> streamAllValuesOfend() {
629 return rawStreamAllValuesOfend(emptyArray());
630 }
631
632 /**
633 * Retrieve the set of values that occur in matches for end.
634 * </p>
635 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
636 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
637 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
638 *
639 * @return the Stream of all values or empty set if there are no matches
640 *
641 */
642 public Stream<Segment> streamAllValuesOfend(final EndOfSiding_step_4.Match partialMatch) {
643 return rawStreamAllValuesOfend(partialMatch.toArray());
644 }
645
646 /**
647 * Retrieve the set of values that occur in matches for end.
648 * </p>
649 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
650 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
651 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
652 *
653 * @return the Stream of all values or empty set if there are no matches
654 *
655 */
656 public Stream<Segment> streamAllValuesOfend(final Train pTrain, final Segment pLocation) {
657 return rawStreamAllValuesOfend(new Object[]{pTrain, pLocation, null});
658 }
659
660 /**
661 * Retrieve the set of values that occur in matches for end.
662 * @return the Set of all values or empty set if there are no matches
663 *
664 */
665 public Set<Segment> getAllValuesOfend(final EndOfSiding_step_4.Match partialMatch) {
666 return rawStreamAllValuesOfend(partialMatch.toArray()).collect(Collectors.toSet());
667 }
668
669 /**
670 * Retrieve the set of values that occur in matches for end.
671 * @return the Set of all values or empty set if there are no matches
672 *
673 */
674 public Set<Segment> getAllValuesOfend(final Train pTrain, final Segment pLocation) {
675 return rawStreamAllValuesOfend(new Object[]{pTrain, pLocation, null}).collect(Collectors.toSet());
676 }
677
678 @Override
679 protected EndOfSiding_step_4.Match tupleToMatch(final Tuple t) {
680 try {
681 return EndOfSiding_step_4.Match.newMatch((Train) t.get(POSITION_TRAIN), (Segment) t.get(POSITION_LOCATION), (Segment) t.get(POSITION_END));
682 } catch(ClassCastException e) {
683 LOGGER.error("Element(s) in tuple not properly typed!",e);
684 return null;
685 }
686 }
687
688 @Override
689 protected EndOfSiding_step_4.Match arrayToMatch(final Object[] match) {
690 try {
691 return EndOfSiding_step_4.Match.newMatch((Train) match[POSITION_TRAIN], (Segment) match[POSITION_LOCATION], (Segment) match[POSITION_END]);
692 } catch(ClassCastException e) {
693 LOGGER.error("Element(s) in array not properly typed!",e);
694 return null;
695 }
696 }
697
698 @Override
699 protected EndOfSiding_step_4.Match arrayToMatchMutable(final Object[] match) {
700 try {
701 return EndOfSiding_step_4.Match.newMutableMatch((Train) match[POSITION_TRAIN], (Segment) match[POSITION_LOCATION], (Segment) match[POSITION_END]);
702 } catch(ClassCastException e) {
703 LOGGER.error("Element(s) in array not properly typed!",e);
704 return null;
705 }
706 }
707
708 /**
709 * @return the singleton instance of the query specification of this pattern
710 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
711 *
712 */
713 public static IQuerySpecification<EndOfSiding_step_4.Matcher> querySpecification() {
714 return EndOfSiding_step_4.instance();
715 }
716 }
717
718 private EndOfSiding_step_4() {
719 super(GeneratedPQuery.INSTANCE);
720 }
721
722 /**
723 * @return the singleton instance of the query specification
724 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
725 *
726 */
727 public static EndOfSiding_step_4 instance() {
728 try{
729 return LazyHolder.INSTANCE;
730 } catch (ExceptionInInitializerError err) {
731 throw processInitializerError(err);
732 }
733 }
734
735 @Override
736 protected EndOfSiding_step_4.Matcher instantiate(final ViatraQueryEngine engine) {
737 return EndOfSiding_step_4.Matcher.on(engine);
738 }
739
740 @Override
741 public EndOfSiding_step_4.Matcher instantiate() {
742 return EndOfSiding_step_4.Matcher.create();
743 }
744
745 @Override
746 public EndOfSiding_step_4.Match newEmptyMatch() {
747 return EndOfSiding_step_4.Match.newEmptyMatch();
748 }
749
750 @Override
751 public EndOfSiding_step_4.Match newMatch(final Object... parameters) {
752 return EndOfSiding_step_4.Match.newMatch((modes3.Train) parameters[0], (modes3.Segment) parameters[1], (modes3.Segment) parameters[2]);
753 }
754
755 /**
756 * Inner class allowing the singleton instance of {@link EndOfSiding_step_4} to be created
757 * <b>not</b> at the class load time of the outer class,
758 * but rather at the first call to {@link EndOfSiding_step_4#instance()}.
759 *
760 * <p> This workaround is required e.g. to support recursion.
761 *
762 */
763 private static class LazyHolder {
764 private static final EndOfSiding_step_4 INSTANCE = new EndOfSiding_step_4();
765
766 /**
767 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
768 * This initialization order is required to support indirect recursion.
769 *
770 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
771 *
772 */
773 private static final Object STATIC_INITIALIZER = ensureInitialized();
774
775 public static Object ensureInitialized() {
776 INSTANCE.ensureInitializedInternal();
777 return null;
778 }
779 }
780
781 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
782 private static final EndOfSiding_step_4.GeneratedPQuery INSTANCE = new GeneratedPQuery();
783
784 private final PParameter parameter_train = new PParameter("train", "modes3.Train", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Train")), PParameterDirection.INOUT);
785
786 private final PParameter parameter_location = new PParameter("location", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT);
787
788 private final PParameter parameter_end = new PParameter("end", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT);
789
790 private final List<PParameter> parameters = Arrays.asList(parameter_train, parameter_location, parameter_end);
791
792 private GeneratedPQuery() {
793 super(PVisibility.PUBLIC);
794 }
795
796 @Override
797 public String getFullyQualifiedName() {
798 return "modes3.queries.endOfSiding_step_4";
799 }
800
801 @Override
802 public List<String> getParameterNames() {
803 return Arrays.asList("train","location","end");
804 }
805
806 @Override
807 public List<PParameter> getParameters() {
808 return parameters;
809 }
810
811 @Override
812 public Set<PBody> doGetContainedBodies() {
813 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
814 Set<PBody> bodies = new LinkedHashSet<>();
815 {
816 PBody body = new PBody(this);
817 PVariable var_train = body.getOrCreateVariableByName("train");
818 PVariable var_location = body.getOrCreateVariableByName("location");
819 PVariable var_end = body.getOrCreateVariableByName("end");
820 new TypeConstraint(body, Tuples.flatTupleOf(var_train), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Train")));
821 new TypeConstraint(body, Tuples.flatTupleOf(var_location), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
822 new TypeConstraint(body, Tuples.flatTupleOf(var_end), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
823 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
824 new ExportedParameter(body, var_train, parameter_train),
825 new ExportedParameter(body, var_location, parameter_location),
826 new ExportedParameter(body, var_end, parameter_end)
827 ));
828 // // frame->end = frame->location->connected_to[i1];// if (frame->end != NULL &&// frame->end->connected_to[1] == frame->location &&// frame->end->connected_to[0] == NULL) {// ...// } // if (frame->end != NULL &&// frame->end->connected_to[0] == frame->location &&// frame->end->connected_to[1] == NULL) {// ...// } Train(train)
829 new TypeConstraint(body, Tuples.flatTupleOf(var_train), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Train")));
830 // Train.location(train, location)
831 new TypeConstraint(body, Tuples.flatTupleOf(var_train), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Train")));
832 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
833 new TypeConstraint(body, Tuples.flatTupleOf(var_train, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Train", "location")));
834 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
835 new Equality(body, var__virtual_0_, var_location);
836 // Segment.connectedTo(location, end)
837 new TypeConstraint(body, Tuples.flatTupleOf(var_location), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
838 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
839 new TypeConstraint(body, Tuples.flatTupleOf(var_location, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment", "connectedTo")));
840 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
841 new Equality(body, var__virtual_1_, var_end);
842 bodies.add(body);
843 }
844 return bodies;
845 }
846 }
847}
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/EndOfSiding_step_5.java b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/EndOfSiding_step_5.java
new file mode 100644
index 00000000..48a2697d
--- /dev/null
+++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/EndOfSiding_step_5.java
@@ -0,0 +1,841 @@
1/**
2 * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql
3 */
4package modes3.queries;
5
6import java.util.Arrays;
7import java.util.Collection;
8import java.util.LinkedHashSet;
9import java.util.List;
10import java.util.Objects;
11import java.util.Optional;
12import java.util.Set;
13import java.util.function.Consumer;
14import java.util.stream.Collectors;
15import java.util.stream.Stream;
16import modes3.Segment;
17import modes3.Train;
18import modes3.queries.MultipleConnectedTo;
19import org.apache.log4j.Logger;
20import org.eclipse.emf.ecore.EClass;
21import org.eclipse.viatra.query.runtime.api.IPatternMatch;
22import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
23import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
24import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
25import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
26import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
27import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
28import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
29import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
30import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
31import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
32import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
33import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
34import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
35import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.NegativePatternCall;
36import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
37import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
38import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
39import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
40import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
41import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
42import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
43
44/**
45 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
46 *
47 * <p>Original source:
48 * <code><pre>
49 * pattern endOfSiding_step_5(in train : Train, in location : Segment, in end : Segment) {
50 * // results-{@literal >}matches[match_cntr].location = frame-{@literal >}location;
51 * // results-{@literal >}matches[match_cntr++].train = frame-{@literal >}train;
52 * // ...OR...
53 * // results-{@literal >}matches[match_cntr].location = frame-{@literal >}location;
54 * // results-{@literal >}matches[match_cntr++].train = frame-{@literal >}train;
55 * Train(train);
56 * Train.location(train, location);
57 * Segment.connectedTo(location, end);
58 * neg find multipleConnectedTo(end);
59 * }
60 * </pre></code>
61 *
62 * @see Matcher
63 * @see Match
64 *
65 */
66@SuppressWarnings("all")
67public final class EndOfSiding_step_5 extends BaseGeneratedEMFQuerySpecification<EndOfSiding_step_5.Matcher> {
68 /**
69 * Pattern-specific match representation of the modes3.queries.endOfSiding_step_5 pattern,
70 * to be used in conjunction with {@link Matcher}.
71 *
72 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
73 * Each instance is a (possibly partial) substitution of pattern parameters,
74 * usable to represent a match of the pattern in the result of a query,
75 * or to specify the bound (fixed) input parameters when issuing a query.
76 *
77 * @see Matcher
78 *
79 */
80 public static abstract class Match extends BasePatternMatch {
81 private Train fTrain;
82
83 private Segment fLocation;
84
85 private Segment fEnd;
86
87 private static List<String> parameterNames = makeImmutableList("train", "location", "end");
88
89 private Match(final Train pTrain, final Segment pLocation, final Segment pEnd) {
90 this.fTrain = pTrain;
91 this.fLocation = pLocation;
92 this.fEnd = pEnd;
93 }
94
95 @Override
96 public Object get(final String parameterName) {
97 switch(parameterName) {
98 case "train": return this.fTrain;
99 case "location": return this.fLocation;
100 case "end": return this.fEnd;
101 default: return null;
102 }
103 }
104
105 @Override
106 public Object get(final int index) {
107 switch(index) {
108 case 0: return this.fTrain;
109 case 1: return this.fLocation;
110 case 2: return this.fEnd;
111 default: return null;
112 }
113 }
114
115 public Train getTrain() {
116 return this.fTrain;
117 }
118
119 public Segment getLocation() {
120 return this.fLocation;
121 }
122
123 public Segment getEnd() {
124 return this.fEnd;
125 }
126
127 @Override
128 public boolean set(final String parameterName, final Object newValue) {
129 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
130 if ("train".equals(parameterName) ) {
131 this.fTrain = (Train) newValue;
132 return true;
133 }
134 if ("location".equals(parameterName) ) {
135 this.fLocation = (Segment) newValue;
136 return true;
137 }
138 if ("end".equals(parameterName) ) {
139 this.fEnd = (Segment) newValue;
140 return true;
141 }
142 return false;
143 }
144
145 public void setTrain(final Train pTrain) {
146 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
147 this.fTrain = pTrain;
148 }
149
150 public void setLocation(final Segment pLocation) {
151 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
152 this.fLocation = pLocation;
153 }
154
155 public void setEnd(final Segment pEnd) {
156 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
157 this.fEnd = pEnd;
158 }
159
160 @Override
161 public String patternName() {
162 return "modes3.queries.endOfSiding_step_5";
163 }
164
165 @Override
166 public List<String> parameterNames() {
167 return EndOfSiding_step_5.Match.parameterNames;
168 }
169
170 @Override
171 public Object[] toArray() {
172 return new Object[]{fTrain, fLocation, fEnd};
173 }
174
175 @Override
176 public EndOfSiding_step_5.Match toImmutable() {
177 return isMutable() ? newMatch(fTrain, fLocation, fEnd) : this;
178 }
179
180 @Override
181 public String prettyPrint() {
182 StringBuilder result = new StringBuilder();
183 result.append("\"train\"=" + prettyPrintValue(fTrain) + ", ");
184 result.append("\"location\"=" + prettyPrintValue(fLocation) + ", ");
185 result.append("\"end\"=" + prettyPrintValue(fEnd));
186 return result.toString();
187 }
188
189 @Override
190 public int hashCode() {
191 return Objects.hash(fTrain, fLocation, fEnd);
192 }
193
194 @Override
195 public boolean equals(final Object obj) {
196 if (this == obj)
197 return true;
198 if (obj == null) {
199 return false;
200 }
201 if ((obj instanceof EndOfSiding_step_5.Match)) {
202 EndOfSiding_step_5.Match other = (EndOfSiding_step_5.Match) obj;
203 return Objects.equals(fTrain, other.fTrain) && Objects.equals(fLocation, other.fLocation) && Objects.equals(fEnd, other.fEnd);
204 } else {
205 // this should be infrequent
206 if (!(obj instanceof IPatternMatch)) {
207 return false;
208 }
209 IPatternMatch otherSig = (IPatternMatch) obj;
210 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
211 }
212 }
213
214 @Override
215 public EndOfSiding_step_5 specification() {
216 return EndOfSiding_step_5.instance();
217 }
218
219 /**
220 * Returns an empty, mutable match.
221 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
222 *
223 * @return the empty match.
224 *
225 */
226 public static EndOfSiding_step_5.Match newEmptyMatch() {
227 return new Mutable(null, null, null);
228 }
229
230 /**
231 * Returns a mutable (partial) match.
232 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
233 *
234 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
235 * @param pLocation the fixed value of pattern parameter location, or null if not bound.
236 * @param pEnd the fixed value of pattern parameter end, or null if not bound.
237 * @return the new, mutable (partial) match object.
238 *
239 */
240 public static EndOfSiding_step_5.Match newMutableMatch(final Train pTrain, final Segment pLocation, final Segment pEnd) {
241 return new Mutable(pTrain, pLocation, pEnd);
242 }
243
244 /**
245 * Returns a new (partial) match.
246 * This can be used e.g. to call the matcher with a partial match.
247 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
248 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
249 * @param pLocation the fixed value of pattern parameter location, or null if not bound.
250 * @param pEnd the fixed value of pattern parameter end, or null if not bound.
251 * @return the (partial) match object.
252 *
253 */
254 public static EndOfSiding_step_5.Match newMatch(final Train pTrain, final Segment pLocation, final Segment pEnd) {
255 return new Immutable(pTrain, pLocation, pEnd);
256 }
257
258 private static final class Mutable extends EndOfSiding_step_5.Match {
259 Mutable(final Train pTrain, final Segment pLocation, final Segment pEnd) {
260 super(pTrain, pLocation, pEnd);
261 }
262
263 @Override
264 public boolean isMutable() {
265 return true;
266 }
267 }
268
269 private static final class Immutable extends EndOfSiding_step_5.Match {
270 Immutable(final Train pTrain, final Segment pLocation, final Segment pEnd) {
271 super(pTrain, pLocation, pEnd);
272 }
273
274 @Override
275 public boolean isMutable() {
276 return false;
277 }
278 }
279 }
280
281 /**
282 * Generated pattern matcher API of the modes3.queries.endOfSiding_step_5 pattern,
283 * providing pattern-specific query methods.
284 *
285 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
286 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
287 *
288 * <p>Matches of the pattern will be represented as {@link Match}.
289 *
290 * <p>Original source:
291 * <code><pre>
292 * pattern endOfSiding_step_5(in train : Train, in location : Segment, in end : Segment) {
293 * // results-{@literal >}matches[match_cntr].location = frame-{@literal >}location;
294 * // results-{@literal >}matches[match_cntr++].train = frame-{@literal >}train;
295 * // ...OR...
296 * // results-{@literal >}matches[match_cntr].location = frame-{@literal >}location;
297 * // results-{@literal >}matches[match_cntr++].train = frame-{@literal >}train;
298 * Train(train);
299 * Train.location(train, location);
300 * Segment.connectedTo(location, end);
301 * neg find multipleConnectedTo(end);
302 * }
303 * </pre></code>
304 *
305 * @see Match
306 * @see EndOfSiding_step_5
307 *
308 */
309 public static class Matcher extends BaseMatcher<EndOfSiding_step_5.Match> {
310 /**
311 * Initializes the pattern matcher within an existing VIATRA Query engine.
312 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
313 *
314 * @param engine the existing VIATRA Query engine in which this matcher will be created.
315 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
316 *
317 */
318 public static EndOfSiding_step_5.Matcher on(final ViatraQueryEngine engine) {
319 // check if matcher already exists
320 Matcher matcher = engine.getExistingMatcher(querySpecification());
321 if (matcher == null) {
322 matcher = (Matcher)engine.getMatcher(querySpecification());
323 }
324 return matcher;
325 }
326
327 /**
328 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
329 * @return an initialized matcher
330 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
331 *
332 */
333 public static EndOfSiding_step_5.Matcher create() {
334 return new Matcher();
335 }
336
337 private static final int POSITION_TRAIN = 0;
338
339 private static final int POSITION_LOCATION = 1;
340
341 private static final int POSITION_END = 2;
342
343 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(EndOfSiding_step_5.Matcher.class);
344
345 /**
346 * Initializes the pattern matcher within an existing VIATRA Query engine.
347 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
348 *
349 * @param engine the existing VIATRA Query engine in which this matcher will be created.
350 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
351 *
352 */
353 private Matcher() {
354 super(querySpecification());
355 }
356
357 /**
358 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
359 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
360 * @param pLocation the fixed value of pattern parameter location, or null if not bound.
361 * @param pEnd the fixed value of pattern parameter end, or null if not bound.
362 * @return matches represented as a Match object.
363 *
364 */
365 public Collection<EndOfSiding_step_5.Match> getAllMatches(final Train pTrain, final Segment pLocation, final Segment pEnd) {
366 return rawStreamAllMatches(new Object[]{pTrain, pLocation, pEnd}).collect(Collectors.toSet());
367 }
368
369 /**
370 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
371 * </p>
372 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
373 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
374 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
375 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
376 * @param pLocation the fixed value of pattern parameter location, or null if not bound.
377 * @param pEnd the fixed value of pattern parameter end, or null if not bound.
378 * @return a stream of matches represented as a Match object.
379 *
380 */
381 public Stream<EndOfSiding_step_5.Match> streamAllMatches(final Train pTrain, final Segment pLocation, final Segment pEnd) {
382 return rawStreamAllMatches(new Object[]{pTrain, pLocation, pEnd});
383 }
384
385 /**
386 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
387 * Neither determinism nor randomness of selection is guaranteed.
388 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
389 * @param pLocation the fixed value of pattern parameter location, or null if not bound.
390 * @param pEnd the fixed value of pattern parameter end, or null if not bound.
391 * @return a match represented as a Match object, or null if no match is found.
392 *
393 */
394 public Optional<EndOfSiding_step_5.Match> getOneArbitraryMatch(final Train pTrain, final Segment pLocation, final Segment pEnd) {
395 return rawGetOneArbitraryMatch(new Object[]{pTrain, pLocation, pEnd});
396 }
397
398 /**
399 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
400 * under any possible substitution of the unspecified parameters (if any).
401 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
402 * @param pLocation the fixed value of pattern parameter location, or null if not bound.
403 * @param pEnd the fixed value of pattern parameter end, or null if not bound.
404 * @return true if the input is a valid (partial) match of the pattern.
405 *
406 */
407 public boolean hasMatch(final Train pTrain, final Segment pLocation, final Segment pEnd) {
408 return rawHasMatch(new Object[]{pTrain, pLocation, pEnd});
409 }
410
411 /**
412 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
413 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
414 * @param pLocation the fixed value of pattern parameter location, or null if not bound.
415 * @param pEnd the fixed value of pattern parameter end, or null if not bound.
416 * @return the number of pattern matches found.
417 *
418 */
419 public int countMatches(final Train pTrain, final Segment pLocation, final Segment pEnd) {
420 return rawCountMatches(new Object[]{pTrain, pLocation, pEnd});
421 }
422
423 /**
424 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
425 * Neither determinism nor randomness of selection is guaranteed.
426 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
427 * @param pLocation the fixed value of pattern parameter location, or null if not bound.
428 * @param pEnd the fixed value of pattern parameter end, or null if not bound.
429 * @param processor the action that will process the selected match.
430 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
431 *
432 */
433 public boolean forOneArbitraryMatch(final Train pTrain, final Segment pLocation, final Segment pEnd, final Consumer<? super EndOfSiding_step_5.Match> processor) {
434 return rawForOneArbitraryMatch(new Object[]{pTrain, pLocation, pEnd}, processor);
435 }
436
437 /**
438 * Returns a new (partial) match.
439 * This can be used e.g. to call the matcher with a partial match.
440 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
441 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
442 * @param pLocation the fixed value of pattern parameter location, or null if not bound.
443 * @param pEnd the fixed value of pattern parameter end, or null if not bound.
444 * @return the (partial) match object.
445 *
446 */
447 public EndOfSiding_step_5.Match newMatch(final Train pTrain, final Segment pLocation, final Segment pEnd) {
448 return EndOfSiding_step_5.Match.newMatch(pTrain, pLocation, pEnd);
449 }
450
451 /**
452 * Retrieve the set of values that occur in matches for train.
453 * @return the Set of all values or empty set if there are no matches
454 *
455 */
456 protected Stream<Train> rawStreamAllValuesOftrain(final Object[] parameters) {
457 return rawStreamAllValues(POSITION_TRAIN, parameters).map(Train.class::cast);
458 }
459
460 /**
461 * Retrieve the set of values that occur in matches for train.
462 * @return the Set of all values or empty set if there are no matches
463 *
464 */
465 public Set<Train> getAllValuesOftrain() {
466 return rawStreamAllValuesOftrain(emptyArray()).collect(Collectors.toSet());
467 }
468
469 /**
470 * Retrieve the set of values that occur in matches for train.
471 * @return the Set of all values or empty set if there are no matches
472 *
473 */
474 public Stream<Train> streamAllValuesOftrain() {
475 return rawStreamAllValuesOftrain(emptyArray());
476 }
477
478 /**
479 * Retrieve the set of values that occur in matches for train.
480 * </p>
481 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
482 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
483 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
484 *
485 * @return the Stream of all values or empty set if there are no matches
486 *
487 */
488 public Stream<Train> streamAllValuesOftrain(final EndOfSiding_step_5.Match partialMatch) {
489 return rawStreamAllValuesOftrain(partialMatch.toArray());
490 }
491
492 /**
493 * Retrieve the set of values that occur in matches for train.
494 * </p>
495 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
496 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
497 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
498 *
499 * @return the Stream of all values or empty set if there are no matches
500 *
501 */
502 public Stream<Train> streamAllValuesOftrain(final Segment pLocation, final Segment pEnd) {
503 return rawStreamAllValuesOftrain(new Object[]{null, pLocation, pEnd});
504 }
505
506 /**
507 * Retrieve the set of values that occur in matches for train.
508 * @return the Set of all values or empty set if there are no matches
509 *
510 */
511 public Set<Train> getAllValuesOftrain(final EndOfSiding_step_5.Match partialMatch) {
512 return rawStreamAllValuesOftrain(partialMatch.toArray()).collect(Collectors.toSet());
513 }
514
515 /**
516 * Retrieve the set of values that occur in matches for train.
517 * @return the Set of all values or empty set if there are no matches
518 *
519 */
520 public Set<Train> getAllValuesOftrain(final Segment pLocation, final Segment pEnd) {
521 return rawStreamAllValuesOftrain(new Object[]{null, pLocation, pEnd}).collect(Collectors.toSet());
522 }
523
524 /**
525 * Retrieve the set of values that occur in matches for location.
526 * @return the Set of all values or empty set if there are no matches
527 *
528 */
529 protected Stream<Segment> rawStreamAllValuesOflocation(final Object[] parameters) {
530 return rawStreamAllValues(POSITION_LOCATION, parameters).map(Segment.class::cast);
531 }
532
533 /**
534 * Retrieve the set of values that occur in matches for location.
535 * @return the Set of all values or empty set if there are no matches
536 *
537 */
538 public Set<Segment> getAllValuesOflocation() {
539 return rawStreamAllValuesOflocation(emptyArray()).collect(Collectors.toSet());
540 }
541
542 /**
543 * Retrieve the set of values that occur in matches for location.
544 * @return the Set of all values or empty set if there are no matches
545 *
546 */
547 public Stream<Segment> streamAllValuesOflocation() {
548 return rawStreamAllValuesOflocation(emptyArray());
549 }
550
551 /**
552 * Retrieve the set of values that occur in matches for location.
553 * </p>
554 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
555 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
556 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
557 *
558 * @return the Stream of all values or empty set if there are no matches
559 *
560 */
561 public Stream<Segment> streamAllValuesOflocation(final EndOfSiding_step_5.Match partialMatch) {
562 return rawStreamAllValuesOflocation(partialMatch.toArray());
563 }
564
565 /**
566 * Retrieve the set of values that occur in matches for location.
567 * </p>
568 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
569 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
570 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
571 *
572 * @return the Stream of all values or empty set if there are no matches
573 *
574 */
575 public Stream<Segment> streamAllValuesOflocation(final Train pTrain, final Segment pEnd) {
576 return rawStreamAllValuesOflocation(new Object[]{pTrain, null, pEnd});
577 }
578
579 /**
580 * Retrieve the set of values that occur in matches for location.
581 * @return the Set of all values or empty set if there are no matches
582 *
583 */
584 public Set<Segment> getAllValuesOflocation(final EndOfSiding_step_5.Match partialMatch) {
585 return rawStreamAllValuesOflocation(partialMatch.toArray()).collect(Collectors.toSet());
586 }
587
588 /**
589 * Retrieve the set of values that occur in matches for location.
590 * @return the Set of all values or empty set if there are no matches
591 *
592 */
593 public Set<Segment> getAllValuesOflocation(final Train pTrain, final Segment pEnd) {
594 return rawStreamAllValuesOflocation(new Object[]{pTrain, null, pEnd}).collect(Collectors.toSet());
595 }
596
597 /**
598 * Retrieve the set of values that occur in matches for end.
599 * @return the Set of all values or empty set if there are no matches
600 *
601 */
602 protected Stream<Segment> rawStreamAllValuesOfend(final Object[] parameters) {
603 return rawStreamAllValues(POSITION_END, parameters).map(Segment.class::cast);
604 }
605
606 /**
607 * Retrieve the set of values that occur in matches for end.
608 * @return the Set of all values or empty set if there are no matches
609 *
610 */
611 public Set<Segment> getAllValuesOfend() {
612 return rawStreamAllValuesOfend(emptyArray()).collect(Collectors.toSet());
613 }
614
615 /**
616 * Retrieve the set of values that occur in matches for end.
617 * @return the Set of all values or empty set if there are no matches
618 *
619 */
620 public Stream<Segment> streamAllValuesOfend() {
621 return rawStreamAllValuesOfend(emptyArray());
622 }
623
624 /**
625 * Retrieve the set of values that occur in matches for end.
626 * </p>
627 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
628 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
629 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
630 *
631 * @return the Stream of all values or empty set if there are no matches
632 *
633 */
634 public Stream<Segment> streamAllValuesOfend(final EndOfSiding_step_5.Match partialMatch) {
635 return rawStreamAllValuesOfend(partialMatch.toArray());
636 }
637
638 /**
639 * Retrieve the set of values that occur in matches for end.
640 * </p>
641 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
642 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
643 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
644 *
645 * @return the Stream of all values or empty set if there are no matches
646 *
647 */
648 public Stream<Segment> streamAllValuesOfend(final Train pTrain, final Segment pLocation) {
649 return rawStreamAllValuesOfend(new Object[]{pTrain, pLocation, null});
650 }
651
652 /**
653 * Retrieve the set of values that occur in matches for end.
654 * @return the Set of all values or empty set if there are no matches
655 *
656 */
657 public Set<Segment> getAllValuesOfend(final EndOfSiding_step_5.Match partialMatch) {
658 return rawStreamAllValuesOfend(partialMatch.toArray()).collect(Collectors.toSet());
659 }
660
661 /**
662 * Retrieve the set of values that occur in matches for end.
663 * @return the Set of all values or empty set if there are no matches
664 *
665 */
666 public Set<Segment> getAllValuesOfend(final Train pTrain, final Segment pLocation) {
667 return rawStreamAllValuesOfend(new Object[]{pTrain, pLocation, null}).collect(Collectors.toSet());
668 }
669
670 @Override
671 protected EndOfSiding_step_5.Match tupleToMatch(final Tuple t) {
672 try {
673 return EndOfSiding_step_5.Match.newMatch((Train) t.get(POSITION_TRAIN), (Segment) t.get(POSITION_LOCATION), (Segment) t.get(POSITION_END));
674 } catch(ClassCastException e) {
675 LOGGER.error("Element(s) in tuple not properly typed!",e);
676 return null;
677 }
678 }
679
680 @Override
681 protected EndOfSiding_step_5.Match arrayToMatch(final Object[] match) {
682 try {
683 return EndOfSiding_step_5.Match.newMatch((Train) match[POSITION_TRAIN], (Segment) match[POSITION_LOCATION], (Segment) match[POSITION_END]);
684 } catch(ClassCastException e) {
685 LOGGER.error("Element(s) in array not properly typed!",e);
686 return null;
687 }
688 }
689
690 @Override
691 protected EndOfSiding_step_5.Match arrayToMatchMutable(final Object[] match) {
692 try {
693 return EndOfSiding_step_5.Match.newMutableMatch((Train) match[POSITION_TRAIN], (Segment) match[POSITION_LOCATION], (Segment) match[POSITION_END]);
694 } catch(ClassCastException e) {
695 LOGGER.error("Element(s) in array not properly typed!",e);
696 return null;
697 }
698 }
699
700 /**
701 * @return the singleton instance of the query specification of this pattern
702 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
703 *
704 */
705 public static IQuerySpecification<EndOfSiding_step_5.Matcher> querySpecification() {
706 return EndOfSiding_step_5.instance();
707 }
708 }
709
710 private EndOfSiding_step_5() {
711 super(GeneratedPQuery.INSTANCE);
712 }
713
714 /**
715 * @return the singleton instance of the query specification
716 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
717 *
718 */
719 public static EndOfSiding_step_5 instance() {
720 try{
721 return LazyHolder.INSTANCE;
722 } catch (ExceptionInInitializerError err) {
723 throw processInitializerError(err);
724 }
725 }
726
727 @Override
728 protected EndOfSiding_step_5.Matcher instantiate(final ViatraQueryEngine engine) {
729 return EndOfSiding_step_5.Matcher.on(engine);
730 }
731
732 @Override
733 public EndOfSiding_step_5.Matcher instantiate() {
734 return EndOfSiding_step_5.Matcher.create();
735 }
736
737 @Override
738 public EndOfSiding_step_5.Match newEmptyMatch() {
739 return EndOfSiding_step_5.Match.newEmptyMatch();
740 }
741
742 @Override
743 public EndOfSiding_step_5.Match newMatch(final Object... parameters) {
744 return EndOfSiding_step_5.Match.newMatch((modes3.Train) parameters[0], (modes3.Segment) parameters[1], (modes3.Segment) parameters[2]);
745 }
746
747 /**
748 * Inner class allowing the singleton instance of {@link EndOfSiding_step_5} to be created
749 * <b>not</b> at the class load time of the outer class,
750 * but rather at the first call to {@link EndOfSiding_step_5#instance()}.
751 *
752 * <p> This workaround is required e.g. to support recursion.
753 *
754 */
755 private static class LazyHolder {
756 private static final EndOfSiding_step_5 INSTANCE = new EndOfSiding_step_5();
757
758 /**
759 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
760 * This initialization order is required to support indirect recursion.
761 *
762 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
763 *
764 */
765 private static final Object STATIC_INITIALIZER = ensureInitialized();
766
767 public static Object ensureInitialized() {
768 INSTANCE.ensureInitializedInternal();
769 return null;
770 }
771 }
772
773 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
774 private static final EndOfSiding_step_5.GeneratedPQuery INSTANCE = new GeneratedPQuery();
775
776 private final PParameter parameter_train = new PParameter("train", "modes3.Train", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Train")), PParameterDirection.INOUT);
777
778 private final PParameter parameter_location = new PParameter("location", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT);
779
780 private final PParameter parameter_end = new PParameter("end", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT);
781
782 private final List<PParameter> parameters = Arrays.asList(parameter_train, parameter_location, parameter_end);
783
784 private GeneratedPQuery() {
785 super(PVisibility.PUBLIC);
786 }
787
788 @Override
789 public String getFullyQualifiedName() {
790 return "modes3.queries.endOfSiding_step_5";
791 }
792
793 @Override
794 public List<String> getParameterNames() {
795 return Arrays.asList("train","location","end");
796 }
797
798 @Override
799 public List<PParameter> getParameters() {
800 return parameters;
801 }
802
803 @Override
804 public Set<PBody> doGetContainedBodies() {
805 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
806 Set<PBody> bodies = new LinkedHashSet<>();
807 {
808 PBody body = new PBody(this);
809 PVariable var_train = body.getOrCreateVariableByName("train");
810 PVariable var_location = body.getOrCreateVariableByName("location");
811 PVariable var_end = body.getOrCreateVariableByName("end");
812 new TypeConstraint(body, Tuples.flatTupleOf(var_train), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Train")));
813 new TypeConstraint(body, Tuples.flatTupleOf(var_location), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
814 new TypeConstraint(body, Tuples.flatTupleOf(var_end), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
815 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
816 new ExportedParameter(body, var_train, parameter_train),
817 new ExportedParameter(body, var_location, parameter_location),
818 new ExportedParameter(body, var_end, parameter_end)
819 ));
820 // // results->matches[match_cntr].location = frame->location;// results->matches[match_cntr++].train = frame->train;// ...OR...// results->matches[match_cntr].location = frame->location;// results->matches[match_cntr++].train = frame->train; Train(train)
821 new TypeConstraint(body, Tuples.flatTupleOf(var_train), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Train")));
822 // Train.location(train, location)
823 new TypeConstraint(body, Tuples.flatTupleOf(var_train), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Train")));
824 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
825 new TypeConstraint(body, Tuples.flatTupleOf(var_train, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Train", "location")));
826 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
827 new Equality(body, var__virtual_0_, var_location);
828 // Segment.connectedTo(location, end)
829 new TypeConstraint(body, Tuples.flatTupleOf(var_location), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
830 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
831 new TypeConstraint(body, Tuples.flatTupleOf(var_location, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment", "connectedTo")));
832 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
833 new Equality(body, var__virtual_1_, var_end);
834 // neg find multipleConnectedTo(end)
835 new NegativePatternCall(body, Tuples.flatTupleOf(var_end), MultipleConnectedTo.instance().getInternalQueryRepresentation());
836 bodies.add(body);
837 }
838 return bodies;
839 }
840 }
841}
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/Modes3Queries.java b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/Modes3Queries.java
index 6e244430..d1238d61 100644
--- a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/Modes3Queries.java
+++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/Modes3Queries.java
@@ -4,16 +4,34 @@
4package modes3.queries; 4package modes3.queries;
5 5
6import modes3.queries.Adjacent; 6import modes3.queries.Adjacent;
7import modes3.queries.CloseTrains_step_2;
8import modes3.queries.CloseTrains_step_3;
9import modes3.queries.CloseTrains_step_4;
10import modes3.queries.CloseTrains_step_5;
11import modes3.queries.CloseTrains_step_6;
12import modes3.queries.CloseTrains_step_7;
13import modes3.queries.ConnectedSegmentsDirected;
7import modes3.queries.ConnectedTo; 14import modes3.queries.ConnectedTo;
8import modes3.queries.ConnectedToNotSymmetric; 15import modes3.queries.ConnectedToNotSymmetric;
9import modes3.queries.ConnectedToReflexive; 16import modes3.queries.ConnectedToReflexive;
17import modes3.queries.EndOfSiding_step_2;
18import modes3.queries.EndOfSiding_step_3;
19import modes3.queries.EndOfSiding_step_4;
20import modes3.queries.EndOfSiding_step_5;
10import modes3.queries.InputsOfTurnout; 21import modes3.queries.InputsOfTurnout;
22import modes3.queries.MisalignedTurnout_step_2;
23import modes3.queries.MisalignedTurnout_step_3;
24import modes3.queries.MisalignedTurnout_step_4;
25import modes3.queries.MisalignedTurnout_step_5;
26import modes3.queries.MultipleConnectedTo;
11import modes3.queries.Output; 27import modes3.queries.Output;
12import modes3.queries.OutputReflexive; 28import modes3.queries.OutputReflexive;
13import modes3.queries.Reachable; 29import modes3.queries.Reachable;
14import modes3.queries.TooFewInputsOfTurnout; 30import modes3.queries.TooFewInputsOfTurnout;
15import modes3.queries.TooManyInputsOfSegment; 31import modes3.queries.TooManyInputsOfSegment;
16import modes3.queries.TooManyInputsOfTurnout; 32import modes3.queries.TooManyInputsOfTurnout;
33import modes3.queries.TrainLocations_step_2;
34import modes3.queries.TrainLocations_step_3;
17import modes3.queries.TurnoutConnectedToBothOutputs; 35import modes3.queries.TurnoutConnectedToBothOutputs;
18import modes3.queries.TurnoutOutput; 36import modes3.queries.TurnoutOutput;
19import modes3.queries.TurnoutOutputsAreSame; 37import modes3.queries.TurnoutOutputsAreSame;
@@ -44,6 +62,24 @@ import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedPatternGroup;
44 * <li>tooFewInputsOfTurnout</li> 62 * <li>tooFewInputsOfTurnout</li>
45 * <li>reachable</li> 63 * <li>reachable</li>
46 * <li>unreachable</li> 64 * <li>unreachable</li>
65 * <li>closeTrains_step_2</li>
66 * <li>closeTrains_step_3</li>
67 * <li>closeTrains_step_4</li>
68 * <li>closeTrains_step_5</li>
69 * <li>closeTrains_step_6</li>
70 * <li>closeTrains_step_7</li>
71 * <li>trainLocations_step_2</li>
72 * <li>trainLocations_step_3</li>
73 * <li>misalignedTurnout_step_2</li>
74 * <li>misalignedTurnout_step_3</li>
75 * <li>misalignedTurnout_step_4</li>
76 * <li>misalignedTurnout_step_5</li>
77 * <li>connectedSegmentsDirected</li>
78 * <li>endOfSiding_step_2</li>
79 * <li>endOfSiding_step_3</li>
80 * <li>endOfSiding_step_4</li>
81 * <li>endOfSiding_step_5</li>
82 * <li>multipleConnectedTo</li>
47 * </ul> 83 * </ul>
48 * 84 *
49 * @see IQueryGroup 85 * @see IQueryGroup
@@ -83,6 +119,24 @@ public final class Modes3Queries extends BaseGeneratedPatternGroup {
83 querySpecifications.add(TooFewInputsOfTurnout.instance()); 119 querySpecifications.add(TooFewInputsOfTurnout.instance());
84 querySpecifications.add(Reachable.instance()); 120 querySpecifications.add(Reachable.instance());
85 querySpecifications.add(Unreachable.instance()); 121 querySpecifications.add(Unreachable.instance());
122 querySpecifications.add(CloseTrains_step_2.instance());
123 querySpecifications.add(CloseTrains_step_3.instance());
124 querySpecifications.add(CloseTrains_step_4.instance());
125 querySpecifications.add(CloseTrains_step_5.instance());
126 querySpecifications.add(CloseTrains_step_6.instance());
127 querySpecifications.add(CloseTrains_step_7.instance());
128 querySpecifications.add(TrainLocations_step_2.instance());
129 querySpecifications.add(TrainLocations_step_3.instance());
130 querySpecifications.add(MisalignedTurnout_step_2.instance());
131 querySpecifications.add(MisalignedTurnout_step_3.instance());
132 querySpecifications.add(MisalignedTurnout_step_4.instance());
133 querySpecifications.add(MisalignedTurnout_step_5.instance());
134 querySpecifications.add(ConnectedSegmentsDirected.instance());
135 querySpecifications.add(EndOfSiding_step_2.instance());
136 querySpecifications.add(EndOfSiding_step_3.instance());
137 querySpecifications.add(EndOfSiding_step_4.instance());
138 querySpecifications.add(EndOfSiding_step_5.instance());
139 querySpecifications.add(MultipleConnectedTo.instance());
86 } 140 }
87 141
88 public ConnectedTo getConnectedTo() { 142 public ConnectedTo getConnectedTo() {
@@ -204,4 +258,148 @@ public final class Modes3Queries extends BaseGeneratedPatternGroup {
204 public Unreachable.Matcher getUnreachable(final ViatraQueryEngine engine) { 258 public Unreachable.Matcher getUnreachable(final ViatraQueryEngine engine) {
205 return Unreachable.Matcher.on(engine); 259 return Unreachable.Matcher.on(engine);
206 } 260 }
261
262 public CloseTrains_step_2 getCloseTrains_step_2() {
263 return CloseTrains_step_2.instance();
264 }
265
266 public CloseTrains_step_2.Matcher getCloseTrains_step_2(final ViatraQueryEngine engine) {
267 return CloseTrains_step_2.Matcher.on(engine);
268 }
269
270 public CloseTrains_step_3 getCloseTrains_step_3() {
271 return CloseTrains_step_3.instance();
272 }
273
274 public CloseTrains_step_3.Matcher getCloseTrains_step_3(final ViatraQueryEngine engine) {
275 return CloseTrains_step_3.Matcher.on(engine);
276 }
277
278 public CloseTrains_step_4 getCloseTrains_step_4() {
279 return CloseTrains_step_4.instance();
280 }
281
282 public CloseTrains_step_4.Matcher getCloseTrains_step_4(final ViatraQueryEngine engine) {
283 return CloseTrains_step_4.Matcher.on(engine);
284 }
285
286 public CloseTrains_step_5 getCloseTrains_step_5() {
287 return CloseTrains_step_5.instance();
288 }
289
290 public CloseTrains_step_5.Matcher getCloseTrains_step_5(final ViatraQueryEngine engine) {
291 return CloseTrains_step_5.Matcher.on(engine);
292 }
293
294 public CloseTrains_step_6 getCloseTrains_step_6() {
295 return CloseTrains_step_6.instance();
296 }
297
298 public CloseTrains_step_6.Matcher getCloseTrains_step_6(final ViatraQueryEngine engine) {
299 return CloseTrains_step_6.Matcher.on(engine);
300 }
301
302 public CloseTrains_step_7 getCloseTrains_step_7() {
303 return CloseTrains_step_7.instance();
304 }
305
306 public CloseTrains_step_7.Matcher getCloseTrains_step_7(final ViatraQueryEngine engine) {
307 return CloseTrains_step_7.Matcher.on(engine);
308 }
309
310 public TrainLocations_step_2 getTrainLocations_step_2() {
311 return TrainLocations_step_2.instance();
312 }
313
314 public TrainLocations_step_2.Matcher getTrainLocations_step_2(final ViatraQueryEngine engine) {
315 return TrainLocations_step_2.Matcher.on(engine);
316 }
317
318 public TrainLocations_step_3 getTrainLocations_step_3() {
319 return TrainLocations_step_3.instance();
320 }
321
322 public TrainLocations_step_3.Matcher getTrainLocations_step_3(final ViatraQueryEngine engine) {
323 return TrainLocations_step_3.Matcher.on(engine);
324 }
325
326 public MisalignedTurnout_step_2 getMisalignedTurnout_step_2() {
327 return MisalignedTurnout_step_2.instance();
328 }
329
330 public MisalignedTurnout_step_2.Matcher getMisalignedTurnout_step_2(final ViatraQueryEngine engine) {
331 return MisalignedTurnout_step_2.Matcher.on(engine);
332 }
333
334 public MisalignedTurnout_step_3 getMisalignedTurnout_step_3() {
335 return MisalignedTurnout_step_3.instance();
336 }
337
338 public MisalignedTurnout_step_3.Matcher getMisalignedTurnout_step_3(final ViatraQueryEngine engine) {
339 return MisalignedTurnout_step_3.Matcher.on(engine);
340 }
341
342 public MisalignedTurnout_step_4 getMisalignedTurnout_step_4() {
343 return MisalignedTurnout_step_4.instance();
344 }
345
346 public MisalignedTurnout_step_4.Matcher getMisalignedTurnout_step_4(final ViatraQueryEngine engine) {
347 return MisalignedTurnout_step_4.Matcher.on(engine);
348 }
349
350 public MisalignedTurnout_step_5 getMisalignedTurnout_step_5() {
351 return MisalignedTurnout_step_5.instance();
352 }
353
354 public MisalignedTurnout_step_5.Matcher getMisalignedTurnout_step_5(final ViatraQueryEngine engine) {
355 return MisalignedTurnout_step_5.Matcher.on(engine);
356 }
357
358 public ConnectedSegmentsDirected getConnectedSegmentsDirected() {
359 return ConnectedSegmentsDirected.instance();
360 }
361
362 public ConnectedSegmentsDirected.Matcher getConnectedSegmentsDirected(final ViatraQueryEngine engine) {
363 return ConnectedSegmentsDirected.Matcher.on(engine);
364 }
365
366 public EndOfSiding_step_2 getEndOfSiding_step_2() {
367 return EndOfSiding_step_2.instance();
368 }
369
370 public EndOfSiding_step_2.Matcher getEndOfSiding_step_2(final ViatraQueryEngine engine) {
371 return EndOfSiding_step_2.Matcher.on(engine);
372 }
373
374 public EndOfSiding_step_3 getEndOfSiding_step_3() {
375 return EndOfSiding_step_3.instance();
376 }
377
378 public EndOfSiding_step_3.Matcher getEndOfSiding_step_3(final ViatraQueryEngine engine) {
379 return EndOfSiding_step_3.Matcher.on(engine);
380 }
381
382 public EndOfSiding_step_4 getEndOfSiding_step_4() {
383 return EndOfSiding_step_4.instance();
384 }
385
386 public EndOfSiding_step_4.Matcher getEndOfSiding_step_4(final ViatraQueryEngine engine) {
387 return EndOfSiding_step_4.Matcher.on(engine);
388 }
389
390 public EndOfSiding_step_5 getEndOfSiding_step_5() {
391 return EndOfSiding_step_5.instance();
392 }
393
394 public EndOfSiding_step_5.Matcher getEndOfSiding_step_5(final ViatraQueryEngine engine) {
395 return EndOfSiding_step_5.Matcher.on(engine);
396 }
397
398 public MultipleConnectedTo getMultipleConnectedTo() {
399 return MultipleConnectedTo.instance();
400 }
401
402 public MultipleConnectedTo.Matcher getMultipleConnectedTo(final ViatraQueryEngine engine) {
403 return MultipleConnectedTo.Matcher.on(engine);
404 }
207} 405}
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/MultipleConnectedTo.java b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/MultipleConnectedTo.java
new file mode 100644
index 00000000..277006c9
--- /dev/null
+++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/MultipleConnectedTo.java
@@ -0,0 +1,565 @@
1/**
2 * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql
3 */
4package modes3.queries;
5
6import java.util.Arrays;
7import java.util.Collection;
8import java.util.LinkedHashSet;
9import java.util.List;
10import java.util.Objects;
11import java.util.Optional;
12import java.util.Set;
13import java.util.function.Consumer;
14import java.util.stream.Collectors;
15import java.util.stream.Stream;
16import modes3.Segment;
17import org.apache.log4j.Logger;
18import org.eclipse.emf.ecore.EClass;
19import org.eclipse.viatra.query.runtime.api.IPatternMatch;
20import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
21import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
22import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
23import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
24import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
25import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
26import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
27import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
28import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
29import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
30import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
31import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
32import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
33import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Inequality;
34import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
35import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
36import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
37import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
38import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
39import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
40import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
41
42/**
43 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
44 *
45 * <p>Original source:
46 * <code><pre>
47 * pattern multipleConnectedTo(s : Segment) {
48 * Segment.connectedTo(s, n1);
49 * Segment.connectedTo(s, n2);
50 * n1 != n2;
51 * }
52 * </pre></code>
53 *
54 * @see Matcher
55 * @see Match
56 *
57 */
58@SuppressWarnings("all")
59public final class MultipleConnectedTo extends BaseGeneratedEMFQuerySpecification<MultipleConnectedTo.Matcher> {
60 /**
61 * Pattern-specific match representation of the modes3.queries.multipleConnectedTo pattern,
62 * to be used in conjunction with {@link Matcher}.
63 *
64 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
65 * Each instance is a (possibly partial) substitution of pattern parameters,
66 * usable to represent a match of the pattern in the result of a query,
67 * or to specify the bound (fixed) input parameters when issuing a query.
68 *
69 * @see Matcher
70 *
71 */
72 public static abstract class Match extends BasePatternMatch {
73 private Segment fS;
74
75 private static List<String> parameterNames = makeImmutableList("s");
76
77 private Match(final Segment pS) {
78 this.fS = pS;
79 }
80
81 @Override
82 public Object get(final String parameterName) {
83 switch(parameterName) {
84 case "s": return this.fS;
85 default: return null;
86 }
87 }
88
89 @Override
90 public Object get(final int index) {
91 switch(index) {
92 case 0: return this.fS;
93 default: return null;
94 }
95 }
96
97 public Segment getS() {
98 return this.fS;
99 }
100
101 @Override
102 public boolean set(final String parameterName, final Object newValue) {
103 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
104 if ("s".equals(parameterName) ) {
105 this.fS = (Segment) newValue;
106 return true;
107 }
108 return false;
109 }
110
111 public void setS(final Segment pS) {
112 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
113 this.fS = pS;
114 }
115
116 @Override
117 public String patternName() {
118 return "modes3.queries.multipleConnectedTo";
119 }
120
121 @Override
122 public List<String> parameterNames() {
123 return MultipleConnectedTo.Match.parameterNames;
124 }
125
126 @Override
127 public Object[] toArray() {
128 return new Object[]{fS};
129 }
130
131 @Override
132 public MultipleConnectedTo.Match toImmutable() {
133 return isMutable() ? newMatch(fS) : this;
134 }
135
136 @Override
137 public String prettyPrint() {
138 StringBuilder result = new StringBuilder();
139 result.append("\"s\"=" + prettyPrintValue(fS));
140 return result.toString();
141 }
142
143 @Override
144 public int hashCode() {
145 return Objects.hash(fS);
146 }
147
148 @Override
149 public boolean equals(final Object obj) {
150 if (this == obj)
151 return true;
152 if (obj == null) {
153 return false;
154 }
155 if ((obj instanceof MultipleConnectedTo.Match)) {
156 MultipleConnectedTo.Match other = (MultipleConnectedTo.Match) obj;
157 return Objects.equals(fS, other.fS);
158 } else {
159 // this should be infrequent
160 if (!(obj instanceof IPatternMatch)) {
161 return false;
162 }
163 IPatternMatch otherSig = (IPatternMatch) obj;
164 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
165 }
166 }
167
168 @Override
169 public MultipleConnectedTo specification() {
170 return MultipleConnectedTo.instance();
171 }
172
173 /**
174 * Returns an empty, mutable match.
175 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
176 *
177 * @return the empty match.
178 *
179 */
180 public static MultipleConnectedTo.Match newEmptyMatch() {
181 return new Mutable(null);
182 }
183
184 /**
185 * Returns a mutable (partial) match.
186 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
187 *
188 * @param pS the fixed value of pattern parameter s, or null if not bound.
189 * @return the new, mutable (partial) match object.
190 *
191 */
192 public static MultipleConnectedTo.Match newMutableMatch(final Segment pS) {
193 return new Mutable(pS);
194 }
195
196 /**
197 * Returns a new (partial) match.
198 * This can be used e.g. to call the matcher with a partial match.
199 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
200 * @param pS the fixed value of pattern parameter s, or null if not bound.
201 * @return the (partial) match object.
202 *
203 */
204 public static MultipleConnectedTo.Match newMatch(final Segment pS) {
205 return new Immutable(pS);
206 }
207
208 private static final class Mutable extends MultipleConnectedTo.Match {
209 Mutable(final Segment pS) {
210 super(pS);
211 }
212
213 @Override
214 public boolean isMutable() {
215 return true;
216 }
217 }
218
219 private static final class Immutable extends MultipleConnectedTo.Match {
220 Immutable(final Segment pS) {
221 super(pS);
222 }
223
224 @Override
225 public boolean isMutable() {
226 return false;
227 }
228 }
229 }
230
231 /**
232 * Generated pattern matcher API of the modes3.queries.multipleConnectedTo pattern,
233 * providing pattern-specific query methods.
234 *
235 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
236 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
237 *
238 * <p>Matches of the pattern will be represented as {@link Match}.
239 *
240 * <p>Original source:
241 * <code><pre>
242 * pattern multipleConnectedTo(s : Segment) {
243 * Segment.connectedTo(s, n1);
244 * Segment.connectedTo(s, n2);
245 * n1 != n2;
246 * }
247 * </pre></code>
248 *
249 * @see Match
250 * @see MultipleConnectedTo
251 *
252 */
253 public static class Matcher extends BaseMatcher<MultipleConnectedTo.Match> {
254 /**
255 * Initializes the pattern matcher within an existing VIATRA Query engine.
256 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
257 *
258 * @param engine the existing VIATRA Query engine in which this matcher will be created.
259 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
260 *
261 */
262 public static MultipleConnectedTo.Matcher on(final ViatraQueryEngine engine) {
263 // check if matcher already exists
264 Matcher matcher = engine.getExistingMatcher(querySpecification());
265 if (matcher == null) {
266 matcher = (Matcher)engine.getMatcher(querySpecification());
267 }
268 return matcher;
269 }
270
271 /**
272 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
273 * @return an initialized matcher
274 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
275 *
276 */
277 public static MultipleConnectedTo.Matcher create() {
278 return new Matcher();
279 }
280
281 private static final int POSITION_S = 0;
282
283 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(MultipleConnectedTo.Matcher.class);
284
285 /**
286 * Initializes the pattern matcher within an existing VIATRA Query engine.
287 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
288 *
289 * @param engine the existing VIATRA Query engine in which this matcher will be created.
290 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
291 *
292 */
293 private Matcher() {
294 super(querySpecification());
295 }
296
297 /**
298 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
299 * @param pS the fixed value of pattern parameter s, or null if not bound.
300 * @return matches represented as a Match object.
301 *
302 */
303 public Collection<MultipleConnectedTo.Match> getAllMatches(final Segment pS) {
304 return rawStreamAllMatches(new Object[]{pS}).collect(Collectors.toSet());
305 }
306
307 /**
308 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
309 * </p>
310 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
311 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
312 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
313 * @param pS the fixed value of pattern parameter s, or null if not bound.
314 * @return a stream of matches represented as a Match object.
315 *
316 */
317 public Stream<MultipleConnectedTo.Match> streamAllMatches(final Segment pS) {
318 return rawStreamAllMatches(new Object[]{pS});
319 }
320
321 /**
322 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
323 * Neither determinism nor randomness of selection is guaranteed.
324 * @param pS the fixed value of pattern parameter s, or null if not bound.
325 * @return a match represented as a Match object, or null if no match is found.
326 *
327 */
328 public Optional<MultipleConnectedTo.Match> getOneArbitraryMatch(final Segment pS) {
329 return rawGetOneArbitraryMatch(new Object[]{pS});
330 }
331
332 /**
333 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
334 * under any possible substitution of the unspecified parameters (if any).
335 * @param pS the fixed value of pattern parameter s, or null if not bound.
336 * @return true if the input is a valid (partial) match of the pattern.
337 *
338 */
339 public boolean hasMatch(final Segment pS) {
340 return rawHasMatch(new Object[]{pS});
341 }
342
343 /**
344 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
345 * @param pS the fixed value of pattern parameter s, or null if not bound.
346 * @return the number of pattern matches found.
347 *
348 */
349 public int countMatches(final Segment pS) {
350 return rawCountMatches(new Object[]{pS});
351 }
352
353 /**
354 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
355 * Neither determinism nor randomness of selection is guaranteed.
356 * @param pS the fixed value of pattern parameter s, or null if not bound.
357 * @param processor the action that will process the selected match.
358 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
359 *
360 */
361 public boolean forOneArbitraryMatch(final Segment pS, final Consumer<? super MultipleConnectedTo.Match> processor) {
362 return rawForOneArbitraryMatch(new Object[]{pS}, processor);
363 }
364
365 /**
366 * Returns a new (partial) match.
367 * This can be used e.g. to call the matcher with a partial match.
368 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
369 * @param pS the fixed value of pattern parameter s, or null if not bound.
370 * @return the (partial) match object.
371 *
372 */
373 public MultipleConnectedTo.Match newMatch(final Segment pS) {
374 return MultipleConnectedTo.Match.newMatch(pS);
375 }
376
377 /**
378 * Retrieve the set of values that occur in matches for s.
379 * @return the Set of all values or empty set if there are no matches
380 *
381 */
382 protected Stream<Segment> rawStreamAllValuesOfs(final Object[] parameters) {
383 return rawStreamAllValues(POSITION_S, parameters).map(Segment.class::cast);
384 }
385
386 /**
387 * Retrieve the set of values that occur in matches for s.
388 * @return the Set of all values or empty set if there are no matches
389 *
390 */
391 public Set<Segment> getAllValuesOfs() {
392 return rawStreamAllValuesOfs(emptyArray()).collect(Collectors.toSet());
393 }
394
395 /**
396 * Retrieve the set of values that occur in matches for s.
397 * @return the Set of all values or empty set if there are no matches
398 *
399 */
400 public Stream<Segment> streamAllValuesOfs() {
401 return rawStreamAllValuesOfs(emptyArray());
402 }
403
404 @Override
405 protected MultipleConnectedTo.Match tupleToMatch(final Tuple t) {
406 try {
407 return MultipleConnectedTo.Match.newMatch((Segment) t.get(POSITION_S));
408 } catch(ClassCastException e) {
409 LOGGER.error("Element(s) in tuple not properly typed!",e);
410 return null;
411 }
412 }
413
414 @Override
415 protected MultipleConnectedTo.Match arrayToMatch(final Object[] match) {
416 try {
417 return MultipleConnectedTo.Match.newMatch((Segment) match[POSITION_S]);
418 } catch(ClassCastException e) {
419 LOGGER.error("Element(s) in array not properly typed!",e);
420 return null;
421 }
422 }
423
424 @Override
425 protected MultipleConnectedTo.Match arrayToMatchMutable(final Object[] match) {
426 try {
427 return MultipleConnectedTo.Match.newMutableMatch((Segment) match[POSITION_S]);
428 } catch(ClassCastException e) {
429 LOGGER.error("Element(s) in array not properly typed!",e);
430 return null;
431 }
432 }
433
434 /**
435 * @return the singleton instance of the query specification of this pattern
436 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
437 *
438 */
439 public static IQuerySpecification<MultipleConnectedTo.Matcher> querySpecification() {
440 return MultipleConnectedTo.instance();
441 }
442 }
443
444 private MultipleConnectedTo() {
445 super(GeneratedPQuery.INSTANCE);
446 }
447
448 /**
449 * @return the singleton instance of the query specification
450 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
451 *
452 */
453 public static MultipleConnectedTo instance() {
454 try{
455 return LazyHolder.INSTANCE;
456 } catch (ExceptionInInitializerError err) {
457 throw processInitializerError(err);
458 }
459 }
460
461 @Override
462 protected MultipleConnectedTo.Matcher instantiate(final ViatraQueryEngine engine) {
463 return MultipleConnectedTo.Matcher.on(engine);
464 }
465
466 @Override
467 public MultipleConnectedTo.Matcher instantiate() {
468 return MultipleConnectedTo.Matcher.create();
469 }
470
471 @Override
472 public MultipleConnectedTo.Match newEmptyMatch() {
473 return MultipleConnectedTo.Match.newEmptyMatch();
474 }
475
476 @Override
477 public MultipleConnectedTo.Match newMatch(final Object... parameters) {
478 return MultipleConnectedTo.Match.newMatch((modes3.Segment) parameters[0]);
479 }
480
481 /**
482 * Inner class allowing the singleton instance of {@link MultipleConnectedTo} to be created
483 * <b>not</b> at the class load time of the outer class,
484 * but rather at the first call to {@link MultipleConnectedTo#instance()}.
485 *
486 * <p> This workaround is required e.g. to support recursion.
487 *
488 */
489 private static class LazyHolder {
490 private static final MultipleConnectedTo INSTANCE = new MultipleConnectedTo();
491
492 /**
493 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
494 * This initialization order is required to support indirect recursion.
495 *
496 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
497 *
498 */
499 private static final Object STATIC_INITIALIZER = ensureInitialized();
500
501 public static Object ensureInitialized() {
502 INSTANCE.ensureInitializedInternal();
503 return null;
504 }
505 }
506
507 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
508 private static final MultipleConnectedTo.GeneratedPQuery INSTANCE = new GeneratedPQuery();
509
510 private final PParameter parameter_s = new PParameter("s", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT);
511
512 private final List<PParameter> parameters = Arrays.asList(parameter_s);
513
514 private GeneratedPQuery() {
515 super(PVisibility.PUBLIC);
516 }
517
518 @Override
519 public String getFullyQualifiedName() {
520 return "modes3.queries.multipleConnectedTo";
521 }
522
523 @Override
524 public List<String> getParameterNames() {
525 return Arrays.asList("s");
526 }
527
528 @Override
529 public List<PParameter> getParameters() {
530 return parameters;
531 }
532
533 @Override
534 public Set<PBody> doGetContainedBodies() {
535 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
536 Set<PBody> bodies = new LinkedHashSet<>();
537 {
538 PBody body = new PBody(this);
539 PVariable var_s = body.getOrCreateVariableByName("s");
540 PVariable var_n1 = body.getOrCreateVariableByName("n1");
541 PVariable var_n2 = body.getOrCreateVariableByName("n2");
542 new TypeConstraint(body, Tuples.flatTupleOf(var_s), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
543 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
544 new ExportedParameter(body, var_s, parameter_s)
545 ));
546 // Segment.connectedTo(s, n1)
547 new TypeConstraint(body, Tuples.flatTupleOf(var_s), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
548 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
549 new TypeConstraint(body, Tuples.flatTupleOf(var_s, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment", "connectedTo")));
550 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
551 new Equality(body, var__virtual_0_, var_n1);
552 // Segment.connectedTo(s, n2)
553 new TypeConstraint(body, Tuples.flatTupleOf(var_s), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
554 PVariable var__virtual_1_ = body.getOrCreateVariableByName(".virtual{1}");
555 new TypeConstraint(body, Tuples.flatTupleOf(var_s, var__virtual_1_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment", "connectedTo")));
556 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_1_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
557 new Equality(body, var__virtual_1_, var_n2);
558 // n1 != n2
559 new Inequality(body, var_n1, var_n2);
560 bodies.add(body);
561 }
562 return bodies;
563 }
564 }
565}
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TooManyInputsOfSegment.java b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TooManyInputsOfSegment.java
index ff82dda1..d12ec23e 100644
--- a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TooManyInputsOfSegment.java
+++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TooManyInputsOfSegment.java
@@ -46,12 +46,6 @@ import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
46 * 46 *
47 * <p>Original source: 47 * <p>Original source:
48 * <code><pre> 48 * <code><pre>
49 * //{@literal @}Constraint(message = "noInputOfSegment", severity = "error", key = { S })
50 * //pattern noInputOfSegment(S : Segment) {
51 * // neg find turnout(S);
52 * // neg find output(_, S);
53 * //}
54 *
55 * {@literal @}Constraint(message = "tooManyInputsOfSegment", severity = "error", key = { S }) 49 * {@literal @}Constraint(message = "tooManyInputsOfSegment", severity = "error", key = { S })
56 * pattern tooManyInputsOfSegment(S : SimpleSegment) { 50 * pattern tooManyInputsOfSegment(S : SimpleSegment) {
57 * find output(I1, S); 51 * find output(I1, S);
@@ -251,12 +245,6 @@ public final class TooManyInputsOfSegment extends BaseGeneratedEMFQuerySpecifica
251 * 245 *
252 * <p>Original source: 246 * <p>Original source:
253 * <code><pre> 247 * <code><pre>
254 * //{@literal @}Constraint(message = "noInputOfSegment", severity = "error", key = { S })
255 * //pattern noInputOfSegment(S : Segment) {
256 * // neg find turnout(S);
257 * // neg find output(_, S);
258 * //}
259 *
260 * {@literal @}Constraint(message = "tooManyInputsOfSegment", severity = "error", key = { S }) 248 * {@literal @}Constraint(message = "tooManyInputsOfSegment", severity = "error", key = { S })
261 * pattern tooManyInputsOfSegment(S : SimpleSegment) { 249 * pattern tooManyInputsOfSegment(S : SimpleSegment) {
262 * find output(I1, S); 250 * find output(I1, S);
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TrainLocations_step_2.java b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TrainLocations_step_2.java
new file mode 100644
index 00000000..5bf153c3
--- /dev/null
+++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TrainLocations_step_2.java
@@ -0,0 +1,564 @@
1/**
2 * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql
3 */
4package modes3.queries;
5
6import java.util.Arrays;
7import java.util.Collection;
8import java.util.LinkedHashSet;
9import java.util.List;
10import java.util.Objects;
11import java.util.Optional;
12import java.util.Set;
13import java.util.function.Consumer;
14import java.util.stream.Collectors;
15import java.util.stream.Stream;
16import modes3.Train;
17import org.apache.log4j.Logger;
18import org.eclipse.emf.ecore.EClass;
19import org.eclipse.viatra.query.runtime.api.IPatternMatch;
20import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
21import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
22import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
23import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
24import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
25import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
26import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
27import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
28import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
29import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
30import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
31import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
32import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
33import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
34import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
35import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
36import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
37import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
38
39/**
40 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
41 *
42 * <p>Original source:
43 * <code><pre>
44 * //
45 * // trainLocations
46 * //
47 *
48 * pattern trainLocations_step_2(in train : Train) {
49 * // frame-{@literal >}train = model-{@literal >}trains[i0];
50 * // frame-{@literal >}location = frame-{@literal >}train-{@literal >}location;
51 * // if (frame-{@literal >}location != NULL) {
52 * // ...
53 * // }
54 *
55 * Train(train);
56 * }
57 * </pre></code>
58 *
59 * @see Matcher
60 * @see Match
61 *
62 */
63@SuppressWarnings("all")
64public final class TrainLocations_step_2 extends BaseGeneratedEMFQuerySpecification<TrainLocations_step_2.Matcher> {
65 /**
66 * Pattern-specific match representation of the modes3.queries.trainLocations_step_2 pattern,
67 * to be used in conjunction with {@link Matcher}.
68 *
69 * <p>Class fields correspond to parameters of the pattern. Fields with value null are considered unassigned.
70 * Each instance is a (possibly partial) substitution of pattern parameters,
71 * usable to represent a match of the pattern in the result of a query,
72 * or to specify the bound (fixed) input parameters when issuing a query.
73 *
74 * @see Matcher
75 *
76 */
77 public static abstract class Match extends BasePatternMatch {
78 private Train fTrain;
79
80 private static List<String> parameterNames = makeImmutableList("train");
81
82 private Match(final Train pTrain) {
83 this.fTrain = pTrain;
84 }
85
86 @Override
87 public Object get(final String parameterName) {
88 switch(parameterName) {
89 case "train": return this.fTrain;
90 default: return null;
91 }
92 }
93
94 @Override
95 public Object get(final int index) {
96 switch(index) {
97 case 0: return this.fTrain;
98 default: return null;
99 }
100 }
101
102 public Train getTrain() {
103 return this.fTrain;
104 }
105
106 @Override
107 public boolean set(final String parameterName, final Object newValue) {
108 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
109 if ("train".equals(parameterName) ) {
110 this.fTrain = (Train) newValue;
111 return true;
112 }
113 return false;
114 }
115
116 public void setTrain(final Train pTrain) {
117 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
118 this.fTrain = pTrain;
119 }
120
121 @Override
122 public String patternName() {
123 return "modes3.queries.trainLocations_step_2";
124 }
125
126 @Override
127 public List<String> parameterNames() {
128 return TrainLocations_step_2.Match.parameterNames;
129 }
130
131 @Override
132 public Object[] toArray() {
133 return new Object[]{fTrain};
134 }
135
136 @Override
137 public TrainLocations_step_2.Match toImmutable() {
138 return isMutable() ? newMatch(fTrain) : this;
139 }
140
141 @Override
142 public String prettyPrint() {
143 StringBuilder result = new StringBuilder();
144 result.append("\"train\"=" + prettyPrintValue(fTrain));
145 return result.toString();
146 }
147
148 @Override
149 public int hashCode() {
150 return Objects.hash(fTrain);
151 }
152
153 @Override
154 public boolean equals(final Object obj) {
155 if (this == obj)
156 return true;
157 if (obj == null) {
158 return false;
159 }
160 if ((obj instanceof TrainLocations_step_2.Match)) {
161 TrainLocations_step_2.Match other = (TrainLocations_step_2.Match) obj;
162 return Objects.equals(fTrain, other.fTrain);
163 } else {
164 // this should be infrequent
165 if (!(obj instanceof IPatternMatch)) {
166 return false;
167 }
168 IPatternMatch otherSig = (IPatternMatch) obj;
169 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
170 }
171 }
172
173 @Override
174 public TrainLocations_step_2 specification() {
175 return TrainLocations_step_2.instance();
176 }
177
178 /**
179 * Returns an empty, mutable match.
180 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
181 *
182 * @return the empty match.
183 *
184 */
185 public static TrainLocations_step_2.Match newEmptyMatch() {
186 return new Mutable(null);
187 }
188
189 /**
190 * Returns a mutable (partial) match.
191 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
192 *
193 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
194 * @return the new, mutable (partial) match object.
195 *
196 */
197 public static TrainLocations_step_2.Match newMutableMatch(final Train pTrain) {
198 return new Mutable(pTrain);
199 }
200
201 /**
202 * Returns a new (partial) match.
203 * This can be used e.g. to call the matcher with a partial match.
204 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
205 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
206 * @return the (partial) match object.
207 *
208 */
209 public static TrainLocations_step_2.Match newMatch(final Train pTrain) {
210 return new Immutable(pTrain);
211 }
212
213 private static final class Mutable extends TrainLocations_step_2.Match {
214 Mutable(final Train pTrain) {
215 super(pTrain);
216 }
217
218 @Override
219 public boolean isMutable() {
220 return true;
221 }
222 }
223
224 private static final class Immutable extends TrainLocations_step_2.Match {
225 Immutable(final Train pTrain) {
226 super(pTrain);
227 }
228
229 @Override
230 public boolean isMutable() {
231 return false;
232 }
233 }
234 }
235
236 /**
237 * Generated pattern matcher API of the modes3.queries.trainLocations_step_2 pattern,
238 * providing pattern-specific query methods.
239 *
240 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
241 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
242 *
243 * <p>Matches of the pattern will be represented as {@link Match}.
244 *
245 * <p>Original source:
246 * <code><pre>
247 * //
248 * // trainLocations
249 * //
250 *
251 * pattern trainLocations_step_2(in train : Train) {
252 * // frame-{@literal >}train = model-{@literal >}trains[i0];
253 * // frame-{@literal >}location = frame-{@literal >}train-{@literal >}location;
254 * // if (frame-{@literal >}location != NULL) {
255 * // ...
256 * // }
257 *
258 * Train(train);
259 * }
260 * </pre></code>
261 *
262 * @see Match
263 * @see TrainLocations_step_2
264 *
265 */
266 public static class Matcher extends BaseMatcher<TrainLocations_step_2.Match> {
267 /**
268 * Initializes the pattern matcher within an existing VIATRA Query engine.
269 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
270 *
271 * @param engine the existing VIATRA Query engine in which this matcher will be created.
272 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
273 *
274 */
275 public static TrainLocations_step_2.Matcher on(final ViatraQueryEngine engine) {
276 // check if matcher already exists
277 Matcher matcher = engine.getExistingMatcher(querySpecification());
278 if (matcher == null) {
279 matcher = (Matcher)engine.getMatcher(querySpecification());
280 }
281 return matcher;
282 }
283
284 /**
285 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
286 * @return an initialized matcher
287 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
288 *
289 */
290 public static TrainLocations_step_2.Matcher create() {
291 return new Matcher();
292 }
293
294 private static final int POSITION_TRAIN = 0;
295
296 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(TrainLocations_step_2.Matcher.class);
297
298 /**
299 * Initializes the pattern matcher within an existing VIATRA Query engine.
300 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
301 *
302 * @param engine the existing VIATRA Query engine in which this matcher will be created.
303 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
304 *
305 */
306 private Matcher() {
307 super(querySpecification());
308 }
309
310 /**
311 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
312 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
313 * @return matches represented as a Match object.
314 *
315 */
316 public Collection<TrainLocations_step_2.Match> getAllMatches(final Train pTrain) {
317 return rawStreamAllMatches(new Object[]{pTrain}).collect(Collectors.toSet());
318 }
319
320 /**
321 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
322 * </p>
323 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
324 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
325 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
326 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
327 * @return a stream of matches represented as a Match object.
328 *
329 */
330 public Stream<TrainLocations_step_2.Match> streamAllMatches(final Train pTrain) {
331 return rawStreamAllMatches(new Object[]{pTrain});
332 }
333
334 /**
335 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
336 * Neither determinism nor randomness of selection is guaranteed.
337 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
338 * @return a match represented as a Match object, or null if no match is found.
339 *
340 */
341 public Optional<TrainLocations_step_2.Match> getOneArbitraryMatch(final Train pTrain) {
342 return rawGetOneArbitraryMatch(new Object[]{pTrain});
343 }
344
345 /**
346 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
347 * under any possible substitution of the unspecified parameters (if any).
348 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
349 * @return true if the input is a valid (partial) match of the pattern.
350 *
351 */
352 public boolean hasMatch(final Train pTrain) {
353 return rawHasMatch(new Object[]{pTrain});
354 }
355
356 /**
357 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
358 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
359 * @return the number of pattern matches found.
360 *
361 */
362 public int countMatches(final Train pTrain) {
363 return rawCountMatches(new Object[]{pTrain});
364 }
365
366 /**
367 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
368 * Neither determinism nor randomness of selection is guaranteed.
369 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
370 * @param processor the action that will process the selected match.
371 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
372 *
373 */
374 public boolean forOneArbitraryMatch(final Train pTrain, final Consumer<? super TrainLocations_step_2.Match> processor) {
375 return rawForOneArbitraryMatch(new Object[]{pTrain}, processor);
376 }
377
378 /**
379 * Returns a new (partial) match.
380 * This can be used e.g. to call the matcher with a partial match.
381 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
382 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
383 * @return the (partial) match object.
384 *
385 */
386 public TrainLocations_step_2.Match newMatch(final Train pTrain) {
387 return TrainLocations_step_2.Match.newMatch(pTrain);
388 }
389
390 /**
391 * Retrieve the set of values that occur in matches for train.
392 * @return the Set of all values or empty set if there are no matches
393 *
394 */
395 protected Stream<Train> rawStreamAllValuesOftrain(final Object[] parameters) {
396 return rawStreamAllValues(POSITION_TRAIN, parameters).map(Train.class::cast);
397 }
398
399 /**
400 * Retrieve the set of values that occur in matches for train.
401 * @return the Set of all values or empty set if there are no matches
402 *
403 */
404 public Set<Train> getAllValuesOftrain() {
405 return rawStreamAllValuesOftrain(emptyArray()).collect(Collectors.toSet());
406 }
407
408 /**
409 * Retrieve the set of values that occur in matches for train.
410 * @return the Set of all values or empty set if there are no matches
411 *
412 */
413 public Stream<Train> streamAllValuesOftrain() {
414 return rawStreamAllValuesOftrain(emptyArray());
415 }
416
417 @Override
418 protected TrainLocations_step_2.Match tupleToMatch(final Tuple t) {
419 try {
420 return TrainLocations_step_2.Match.newMatch((Train) t.get(POSITION_TRAIN));
421 } catch(ClassCastException e) {
422 LOGGER.error("Element(s) in tuple not properly typed!",e);
423 return null;
424 }
425 }
426
427 @Override
428 protected TrainLocations_step_2.Match arrayToMatch(final Object[] match) {
429 try {
430 return TrainLocations_step_2.Match.newMatch((Train) match[POSITION_TRAIN]);
431 } catch(ClassCastException e) {
432 LOGGER.error("Element(s) in array not properly typed!",e);
433 return null;
434 }
435 }
436
437 @Override
438 protected TrainLocations_step_2.Match arrayToMatchMutable(final Object[] match) {
439 try {
440 return TrainLocations_step_2.Match.newMutableMatch((Train) match[POSITION_TRAIN]);
441 } catch(ClassCastException e) {
442 LOGGER.error("Element(s) in array not properly typed!",e);
443 return null;
444 }
445 }
446
447 /**
448 * @return the singleton instance of the query specification of this pattern
449 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
450 *
451 */
452 public static IQuerySpecification<TrainLocations_step_2.Matcher> querySpecification() {
453 return TrainLocations_step_2.instance();
454 }
455 }
456
457 private TrainLocations_step_2() {
458 super(GeneratedPQuery.INSTANCE);
459 }
460
461 /**
462 * @return the singleton instance of the query specification
463 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
464 *
465 */
466 public static TrainLocations_step_2 instance() {
467 try{
468 return LazyHolder.INSTANCE;
469 } catch (ExceptionInInitializerError err) {
470 throw processInitializerError(err);
471 }
472 }
473
474 @Override
475 protected TrainLocations_step_2.Matcher instantiate(final ViatraQueryEngine engine) {
476 return TrainLocations_step_2.Matcher.on(engine);
477 }
478
479 @Override
480 public TrainLocations_step_2.Matcher instantiate() {
481 return TrainLocations_step_2.Matcher.create();
482 }
483
484 @Override
485 public TrainLocations_step_2.Match newEmptyMatch() {
486 return TrainLocations_step_2.Match.newEmptyMatch();
487 }
488
489 @Override
490 public TrainLocations_step_2.Match newMatch(final Object... parameters) {
491 return TrainLocations_step_2.Match.newMatch((modes3.Train) parameters[0]);
492 }
493
494 /**
495 * Inner class allowing the singleton instance of {@link TrainLocations_step_2} to be created
496 * <b>not</b> at the class load time of the outer class,
497 * but rather at the first call to {@link TrainLocations_step_2#instance()}.
498 *
499 * <p> This workaround is required e.g. to support recursion.
500 *
501 */
502 private static class LazyHolder {
503 private static final TrainLocations_step_2 INSTANCE = new TrainLocations_step_2();
504
505 /**
506 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
507 * This initialization order is required to support indirect recursion.
508 *
509 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
510 *
511 */
512 private static final Object STATIC_INITIALIZER = ensureInitialized();
513
514 public static Object ensureInitialized() {
515 INSTANCE.ensureInitializedInternal();
516 return null;
517 }
518 }
519
520 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
521 private static final TrainLocations_step_2.GeneratedPQuery INSTANCE = new GeneratedPQuery();
522
523 private final PParameter parameter_train = new PParameter("train", "modes3.Train", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Train")), PParameterDirection.INOUT);
524
525 private final List<PParameter> parameters = Arrays.asList(parameter_train);
526
527 private GeneratedPQuery() {
528 super(PVisibility.PUBLIC);
529 }
530
531 @Override
532 public String getFullyQualifiedName() {
533 return "modes3.queries.trainLocations_step_2";
534 }
535
536 @Override
537 public List<String> getParameterNames() {
538 return Arrays.asList("train");
539 }
540
541 @Override
542 public List<PParameter> getParameters() {
543 return parameters;
544 }
545
546 @Override
547 public Set<PBody> doGetContainedBodies() {
548 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
549 Set<PBody> bodies = new LinkedHashSet<>();
550 {
551 PBody body = new PBody(this);
552 PVariable var_train = body.getOrCreateVariableByName("train");
553 new TypeConstraint(body, Tuples.flatTupleOf(var_train), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Train")));
554 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
555 new ExportedParameter(body, var_train, parameter_train)
556 ));
557 // // frame->train = model->trains[i0];// frame->location = frame->train->location;// if (frame->location != NULL) {// ...// } Train(train)
558 new TypeConstraint(body, Tuples.flatTupleOf(var_train), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Train")));
559 bodies.add(body);
560 }
561 return bodies;
562 }
563 }
564}
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TrainLocations_step_3.java b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TrainLocations_step_3.java
new file mode 100644
index 00000000..edbd4af3
--- /dev/null
+++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TrainLocations_step_3.java
@@ -0,0 +1,713 @@
1/**
2 * Generated from platform:/resource/ca.mcgill.rtgmrt.example.modes3/src/modes3/queries/Modes3Queries.vql
3 */
4package modes3.queries;
5
6import java.util.Arrays;
7import java.util.Collection;
8import java.util.LinkedHashSet;
9import java.util.List;
10import java.util.Objects;
11import java.util.Optional;
12import java.util.Set;
13import java.util.function.Consumer;
14import java.util.stream.Collectors;
15import java.util.stream.Stream;
16import modes3.Segment;
17import modes3.Train;
18import org.apache.log4j.Logger;
19import org.eclipse.emf.ecore.EClass;
20import org.eclipse.viatra.query.runtime.api.IPatternMatch;
21import org.eclipse.viatra.query.runtime.api.IQuerySpecification;
22import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine;
23import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery;
24import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification;
25import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher;
26import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch;
27import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey;
28import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey;
29import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint;
30import org.eclipse.viatra.query.runtime.matchers.psystem.PBody;
31import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
32import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality;
33import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter;
34import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
35import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter;
36import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection;
37import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility;
38import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
39import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples;
40import org.eclipse.viatra.query.runtime.util.ViatraQueryLoggingUtil;
41
42/**
43 * A pattern-specific query specification that can instantiate Matcher in a type-safe way.
44 *
45 * <p>Original source:
46 * <code><pre>
47 * pattern trainLocations_step_3(in train : Train, in location : Segment) {
48 * // results-{@literal >}matches[match_cntr].location = frame-{@literal >}location;
49 * // results-{@literal >}matches[match_cntr++].train = frame-{@literal >}train;
50 * Train(train);
51 * Train.location(train, location);
52 * }
53 * </pre></code>
54 *
55 * @see Matcher
56 * @see Match
57 *
58 */
59@SuppressWarnings("all")
60public final class TrainLocations_step_3 extends BaseGeneratedEMFQuerySpecification<TrainLocations_step_3.Matcher> {
61 /**
62 * Pattern-specific match representation of the modes3.queries.trainLocations_step_3 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 Train fTrain;
75
76 private Segment fLocation;
77
78 private static List<String> parameterNames = makeImmutableList("train", "location");
79
80 private Match(final Train pTrain, final Segment pLocation) {
81 this.fTrain = pTrain;
82 this.fLocation = pLocation;
83 }
84
85 @Override
86 public Object get(final String parameterName) {
87 switch(parameterName) {
88 case "train": return this.fTrain;
89 case "location": return this.fLocation;
90 default: return null;
91 }
92 }
93
94 @Override
95 public Object get(final int index) {
96 switch(index) {
97 case 0: return this.fTrain;
98 case 1: return this.fLocation;
99 default: return null;
100 }
101 }
102
103 public Train getTrain() {
104 return this.fTrain;
105 }
106
107 public Segment getLocation() {
108 return this.fLocation;
109 }
110
111 @Override
112 public boolean set(final String parameterName, final Object newValue) {
113 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
114 if ("train".equals(parameterName) ) {
115 this.fTrain = (Train) newValue;
116 return true;
117 }
118 if ("location".equals(parameterName) ) {
119 this.fLocation = (Segment) newValue;
120 return true;
121 }
122 return false;
123 }
124
125 public void setTrain(final Train pTrain) {
126 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
127 this.fTrain = pTrain;
128 }
129
130 public void setLocation(final Segment pLocation) {
131 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
132 this.fLocation = pLocation;
133 }
134
135 @Override
136 public String patternName() {
137 return "modes3.queries.trainLocations_step_3";
138 }
139
140 @Override
141 public List<String> parameterNames() {
142 return TrainLocations_step_3.Match.parameterNames;
143 }
144
145 @Override
146 public Object[] toArray() {
147 return new Object[]{fTrain, fLocation};
148 }
149
150 @Override
151 public TrainLocations_step_3.Match toImmutable() {
152 return isMutable() ? newMatch(fTrain, fLocation) : this;
153 }
154
155 @Override
156 public String prettyPrint() {
157 StringBuilder result = new StringBuilder();
158 result.append("\"train\"=" + prettyPrintValue(fTrain) + ", ");
159 result.append("\"location\"=" + prettyPrintValue(fLocation));
160 return result.toString();
161 }
162
163 @Override
164 public int hashCode() {
165 return Objects.hash(fTrain, fLocation);
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 TrainLocations_step_3.Match)) {
176 TrainLocations_step_3.Match other = (TrainLocations_step_3.Match) obj;
177 return Objects.equals(fTrain, other.fTrain) && Objects.equals(fLocation, other.fLocation);
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 TrainLocations_step_3 specification() {
190 return TrainLocations_step_3.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 TrainLocations_step_3.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 pTrain the fixed value of pattern parameter train, or null if not bound.
209 * @param pLocation the fixed value of pattern parameter location, or null if not bound.
210 * @return the new, mutable (partial) match object.
211 *
212 */
213 public static TrainLocations_step_3.Match newMutableMatch(final Train pTrain, final Segment pLocation) {
214 return new Mutable(pTrain, pLocation);
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 pTrain the fixed value of pattern parameter train, or null if not bound.
222 * @param pLocation the fixed value of pattern parameter location, or null if not bound.
223 * @return the (partial) match object.
224 *
225 */
226 public static TrainLocations_step_3.Match newMatch(final Train pTrain, final Segment pLocation) {
227 return new Immutable(pTrain, pLocation);
228 }
229
230 private static final class Mutable extends TrainLocations_step_3.Match {
231 Mutable(final Train pTrain, final Segment pLocation) {
232 super(pTrain, pLocation);
233 }
234
235 @Override
236 public boolean isMutable() {
237 return true;
238 }
239 }
240
241 private static final class Immutable extends TrainLocations_step_3.Match {
242 Immutable(final Train pTrain, final Segment pLocation) {
243 super(pTrain, pLocation);
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.trainLocations_step_3 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 trainLocations_step_3(in train : Train, in location : Segment) {
265 * // results-{@literal >}matches[match_cntr].location = frame-{@literal >}location;
266 * // results-{@literal >}matches[match_cntr++].train = frame-{@literal >}train;
267 * Train(train);
268 * Train.location(train, location);
269 * }
270 * </pre></code>
271 *
272 * @see Match
273 * @see TrainLocations_step_3
274 *
275 */
276 public static class Matcher extends BaseMatcher<TrainLocations_step_3.Match> {
277 /**
278 * Initializes the pattern matcher within an existing VIATRA Query engine.
279 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
280 *
281 * @param engine the existing VIATRA Query engine in which this matcher will be created.
282 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
283 *
284 */
285 public static TrainLocations_step_3.Matcher on(final ViatraQueryEngine engine) {
286 // check if matcher already exists
287 Matcher matcher = engine.getExistingMatcher(querySpecification());
288 if (matcher == null) {
289 matcher = (Matcher)engine.getMatcher(querySpecification());
290 }
291 return matcher;
292 }
293
294 /**
295 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
296 * @return an initialized matcher
297 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
298 *
299 */
300 public static TrainLocations_step_3.Matcher create() {
301 return new Matcher();
302 }
303
304 private static final int POSITION_TRAIN = 0;
305
306 private static final int POSITION_LOCATION = 1;
307
308 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(TrainLocations_step_3.Matcher.class);
309
310 /**
311 * Initializes the pattern matcher within an existing VIATRA Query engine.
312 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
313 *
314 * @param engine the existing VIATRA Query engine in which this matcher will be created.
315 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
316 *
317 */
318 private Matcher() {
319 super(querySpecification());
320 }
321
322 /**
323 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
324 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
325 * @param pLocation the fixed value of pattern parameter location, or null if not bound.
326 * @return matches represented as a Match object.
327 *
328 */
329 public Collection<TrainLocations_step_3.Match> getAllMatches(final Train pTrain, final Segment pLocation) {
330 return rawStreamAllMatches(new Object[]{pTrain, pLocation}).collect(Collectors.toSet());
331 }
332
333 /**
334 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
335 * </p>
336 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
337 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
338 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
339 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
340 * @param pLocation the fixed value of pattern parameter location, or null if not bound.
341 * @return a stream of matches represented as a Match object.
342 *
343 */
344 public Stream<TrainLocations_step_3.Match> streamAllMatches(final Train pTrain, final Segment pLocation) {
345 return rawStreamAllMatches(new Object[]{pTrain, pLocation});
346 }
347
348 /**
349 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
350 * Neither determinism nor randomness of selection is guaranteed.
351 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
352 * @param pLocation the fixed value of pattern parameter location, or null if not bound.
353 * @return a match represented as a Match object, or null if no match is found.
354 *
355 */
356 public Optional<TrainLocations_step_3.Match> getOneArbitraryMatch(final Train pTrain, final Segment pLocation) {
357 return rawGetOneArbitraryMatch(new Object[]{pTrain, pLocation});
358 }
359
360 /**
361 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
362 * under any possible substitution of the unspecified parameters (if any).
363 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
364 * @param pLocation the fixed value of pattern parameter location, or null if not bound.
365 * @return true if the input is a valid (partial) match of the pattern.
366 *
367 */
368 public boolean hasMatch(final Train pTrain, final Segment pLocation) {
369 return rawHasMatch(new Object[]{pTrain, pLocation});
370 }
371
372 /**
373 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
374 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
375 * @param pLocation the fixed value of pattern parameter location, or null if not bound.
376 * @return the number of pattern matches found.
377 *
378 */
379 public int countMatches(final Train pTrain, final Segment pLocation) {
380 return rawCountMatches(new Object[]{pTrain, pLocation});
381 }
382
383 /**
384 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
385 * Neither determinism nor randomness of selection is guaranteed.
386 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
387 * @param pLocation the fixed value of pattern parameter location, or null if not bound.
388 * @param processor the action that will process the selected match.
389 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
390 *
391 */
392 public boolean forOneArbitraryMatch(final Train pTrain, final Segment pLocation, final Consumer<? super TrainLocations_step_3.Match> processor) {
393 return rawForOneArbitraryMatch(new Object[]{pTrain, pLocation}, processor);
394 }
395
396 /**
397 * Returns a new (partial) match.
398 * This can be used e.g. to call the matcher with a partial match.
399 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
400 * @param pTrain the fixed value of pattern parameter train, or null if not bound.
401 * @param pLocation the fixed value of pattern parameter location, or null if not bound.
402 * @return the (partial) match object.
403 *
404 */
405 public TrainLocations_step_3.Match newMatch(final Train pTrain, final Segment pLocation) {
406 return TrainLocations_step_3.Match.newMatch(pTrain, pLocation);
407 }
408
409 /**
410 * Retrieve the set of values that occur in matches for train.
411 * @return the Set of all values or empty set if there are no matches
412 *
413 */
414 protected Stream<Train> rawStreamAllValuesOftrain(final Object[] parameters) {
415 return rawStreamAllValues(POSITION_TRAIN, parameters).map(Train.class::cast);
416 }
417
418 /**
419 * Retrieve the set of values that occur in matches for train.
420 * @return the Set of all values or empty set if there are no matches
421 *
422 */
423 public Set<Train> getAllValuesOftrain() {
424 return rawStreamAllValuesOftrain(emptyArray()).collect(Collectors.toSet());
425 }
426
427 /**
428 * Retrieve the set of values that occur in matches for train.
429 * @return the Set of all values or empty set if there are no matches
430 *
431 */
432 public Stream<Train> streamAllValuesOftrain() {
433 return rawStreamAllValuesOftrain(emptyArray());
434 }
435
436 /**
437 * Retrieve the set of values that occur in matches for train.
438 * </p>
439 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
440 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
441 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
442 *
443 * @return the Stream of all values or empty set if there are no matches
444 *
445 */
446 public Stream<Train> streamAllValuesOftrain(final TrainLocations_step_3.Match partialMatch) {
447 return rawStreamAllValuesOftrain(partialMatch.toArray());
448 }
449
450 /**
451 * Retrieve the set of values that occur in matches for train.
452 * </p>
453 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
454 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
455 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
456 *
457 * @return the Stream of all values or empty set if there are no matches
458 *
459 */
460 public Stream<Train> streamAllValuesOftrain(final Segment pLocation) {
461 return rawStreamAllValuesOftrain(new Object[]{null, pLocation});
462 }
463
464 /**
465 * Retrieve the set of values that occur in matches for train.
466 * @return the Set of all values or empty set if there are no matches
467 *
468 */
469 public Set<Train> getAllValuesOftrain(final TrainLocations_step_3.Match partialMatch) {
470 return rawStreamAllValuesOftrain(partialMatch.toArray()).collect(Collectors.toSet());
471 }
472
473 /**
474 * Retrieve the set of values that occur in matches for train.
475 * @return the Set of all values or empty set if there are no matches
476 *
477 */
478 public Set<Train> getAllValuesOftrain(final Segment pLocation) {
479 return rawStreamAllValuesOftrain(new Object[]{null, pLocation}).collect(Collectors.toSet());
480 }
481
482 /**
483 * Retrieve the set of values that occur in matches for location.
484 * @return the Set of all values or empty set if there are no matches
485 *
486 */
487 protected Stream<Segment> rawStreamAllValuesOflocation(final Object[] parameters) {
488 return rawStreamAllValues(POSITION_LOCATION, parameters).map(Segment.class::cast);
489 }
490
491 /**
492 * Retrieve the set of values that occur in matches for location.
493 * @return the Set of all values or empty set if there are no matches
494 *
495 */
496 public Set<Segment> getAllValuesOflocation() {
497 return rawStreamAllValuesOflocation(emptyArray()).collect(Collectors.toSet());
498 }
499
500 /**
501 * Retrieve the set of values that occur in matches for location.
502 * @return the Set of all values or empty set if there are no matches
503 *
504 */
505 public Stream<Segment> streamAllValuesOflocation() {
506 return rawStreamAllValuesOflocation(emptyArray());
507 }
508
509 /**
510 * Retrieve the set of values that occur in matches for location.
511 * </p>
512 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
513 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
514 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
515 *
516 * @return the Stream of all values or empty set if there are no matches
517 *
518 */
519 public Stream<Segment> streamAllValuesOflocation(final TrainLocations_step_3.Match partialMatch) {
520 return rawStreamAllValuesOflocation(partialMatch.toArray());
521 }
522
523 /**
524 * Retrieve the set of values that occur in matches for location.
525 * </p>
526 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
527 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
528 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
529 *
530 * @return the Stream of all values or empty set if there are no matches
531 *
532 */
533 public Stream<Segment> streamAllValuesOflocation(final Train pTrain) {
534 return rawStreamAllValuesOflocation(new Object[]{pTrain, null});
535 }
536
537 /**
538 * Retrieve the set of values that occur in matches for location.
539 * @return the Set of all values or empty set if there are no matches
540 *
541 */
542 public Set<Segment> getAllValuesOflocation(final TrainLocations_step_3.Match partialMatch) {
543 return rawStreamAllValuesOflocation(partialMatch.toArray()).collect(Collectors.toSet());
544 }
545
546 /**
547 * Retrieve the set of values that occur in matches for location.
548 * @return the Set of all values or empty set if there are no matches
549 *
550 */
551 public Set<Segment> getAllValuesOflocation(final Train pTrain) {
552 return rawStreamAllValuesOflocation(new Object[]{pTrain, null}).collect(Collectors.toSet());
553 }
554
555 @Override
556 protected TrainLocations_step_3.Match tupleToMatch(final Tuple t) {
557 try {
558 return TrainLocations_step_3.Match.newMatch((Train) t.get(POSITION_TRAIN), (Segment) t.get(POSITION_LOCATION));
559 } catch(ClassCastException e) {
560 LOGGER.error("Element(s) in tuple not properly typed!",e);
561 return null;
562 }
563 }
564
565 @Override
566 protected TrainLocations_step_3.Match arrayToMatch(final Object[] match) {
567 try {
568 return TrainLocations_step_3.Match.newMatch((Train) match[POSITION_TRAIN], (Segment) match[POSITION_LOCATION]);
569 } catch(ClassCastException e) {
570 LOGGER.error("Element(s) in array not properly typed!",e);
571 return null;
572 }
573 }
574
575 @Override
576 protected TrainLocations_step_3.Match arrayToMatchMutable(final Object[] match) {
577 try {
578 return TrainLocations_step_3.Match.newMutableMatch((Train) match[POSITION_TRAIN], (Segment) match[POSITION_LOCATION]);
579 } catch(ClassCastException e) {
580 LOGGER.error("Element(s) in array not properly typed!",e);
581 return null;
582 }
583 }
584
585 /**
586 * @return the singleton instance of the query specification of this pattern
587 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
588 *
589 */
590 public static IQuerySpecification<TrainLocations_step_3.Matcher> querySpecification() {
591 return TrainLocations_step_3.instance();
592 }
593 }
594
595 private TrainLocations_step_3() {
596 super(GeneratedPQuery.INSTANCE);
597 }
598
599 /**
600 * @return the singleton instance of the query specification
601 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
602 *
603 */
604 public static TrainLocations_step_3 instance() {
605 try{
606 return LazyHolder.INSTANCE;
607 } catch (ExceptionInInitializerError err) {
608 throw processInitializerError(err);
609 }
610 }
611
612 @Override
613 protected TrainLocations_step_3.Matcher instantiate(final ViatraQueryEngine engine) {
614 return TrainLocations_step_3.Matcher.on(engine);
615 }
616
617 @Override
618 public TrainLocations_step_3.Matcher instantiate() {
619 return TrainLocations_step_3.Matcher.create();
620 }
621
622 @Override
623 public TrainLocations_step_3.Match newEmptyMatch() {
624 return TrainLocations_step_3.Match.newEmptyMatch();
625 }
626
627 @Override
628 public TrainLocations_step_3.Match newMatch(final Object... parameters) {
629 return TrainLocations_step_3.Match.newMatch((modes3.Train) parameters[0], (modes3.Segment) parameters[1]);
630 }
631
632 /**
633 * Inner class allowing the singleton instance of {@link TrainLocations_step_3} to be created
634 * <b>not</b> at the class load time of the outer class,
635 * but rather at the first call to {@link TrainLocations_step_3#instance()}.
636 *
637 * <p> This workaround is required e.g. to support recursion.
638 *
639 */
640 private static class LazyHolder {
641 private static final TrainLocations_step_3 INSTANCE = new TrainLocations_step_3();
642
643 /**
644 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
645 * This initialization order is required to support indirect recursion.
646 *
647 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
648 *
649 */
650 private static final Object STATIC_INITIALIZER = ensureInitialized();
651
652 public static Object ensureInitialized() {
653 INSTANCE.ensureInitializedInternal();
654 return null;
655 }
656 }
657
658 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
659 private static final TrainLocations_step_3.GeneratedPQuery INSTANCE = new GeneratedPQuery();
660
661 private final PParameter parameter_train = new PParameter("train", "modes3.Train", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Train")), PParameterDirection.INOUT);
662
663 private final PParameter parameter_location = new PParameter("location", "modes3.Segment", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Segment")), PParameterDirection.INOUT);
664
665 private final List<PParameter> parameters = Arrays.asList(parameter_train, parameter_location);
666
667 private GeneratedPQuery() {
668 super(PVisibility.PUBLIC);
669 }
670
671 @Override
672 public String getFullyQualifiedName() {
673 return "modes3.queries.trainLocations_step_3";
674 }
675
676 @Override
677 public List<String> getParameterNames() {
678 return Arrays.asList("train","location");
679 }
680
681 @Override
682 public List<PParameter> getParameters() {
683 return parameters;
684 }
685
686 @Override
687 public Set<PBody> doGetContainedBodies() {
688 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
689 Set<PBody> bodies = new LinkedHashSet<>();
690 {
691 PBody body = new PBody(this);
692 PVariable var_train = body.getOrCreateVariableByName("train");
693 PVariable var_location = body.getOrCreateVariableByName("location");
694 new TypeConstraint(body, Tuples.flatTupleOf(var_train), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Train")));
695 new TypeConstraint(body, Tuples.flatTupleOf(var_location), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
696 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
697 new ExportedParameter(body, var_train, parameter_train),
698 new ExportedParameter(body, var_location, parameter_location)
699 ));
700 // // results->matches[match_cntr].location = frame->location;// results->matches[match_cntr++].train = frame->train; Train(train)
701 new TypeConstraint(body, Tuples.flatTupleOf(var_train), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Train")));
702 // Train.location(train, location)
703 new TypeConstraint(body, Tuples.flatTupleOf(var_train), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Train")));
704 PVariable var__virtual_0_ = body.getOrCreateVariableByName(".virtual{0}");
705 new TypeConstraint(body, Tuples.flatTupleOf(var_train, var__virtual_0_), new EStructuralFeatureInstancesKey(getFeatureLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Train", "location")));
706 new TypeConstraint(body, Tuples.flatTupleOf(var__virtual_0_), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Segment")));
707 new Equality(body, var__virtual_0_, var_location);
708 bodies.add(body);
709 }
710 return bodies;
711 }
712 }
713}