aboutsummaryrefslogtreecommitdiffstats
path: root/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/InputsOfTurnout.java
diff options
context:
space:
mode:
Diffstat (limited to 'Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/InputsOfTurnout.java')
-rw-r--r--Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/InputsOfTurnout.java570
1 files changed, 570 insertions, 0 deletions
diff --git a/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/InputsOfTurnout.java b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/InputsOfTurnout.java
new file mode 100644
index 00000000..2f2eea11
--- /dev/null
+++ b/Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/InputsOfTurnout.java
@@ -0,0 +1,570 @@
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.Turnout;
17import modes3.queries.Adjacent;
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.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.ExportedParameter;
32import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Inequality;
33import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall;
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 inputsOfTurnout(T : Turnout) {
48 * find adjacent(I1, T);
49 * find adjacent(I2, T);
50 * find adjacent(I3, T);
51 * I1 != I2;
52 * I1 != I3;
53 * I2 != I3;
54 * }
55 * </pre></code>
56 *
57 * @see Matcher
58 * @see Match
59 *
60 */
61@SuppressWarnings("all")
62public final class InputsOfTurnout extends BaseGeneratedEMFQuerySpecification<InputsOfTurnout.Matcher> {
63 /**
64 * Pattern-specific match representation of the modes3.queries.inputsOfTurnout 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 Turnout fT;
77
78 private static List<String> parameterNames = makeImmutableList("T");
79
80 private Match(final Turnout pT) {
81 this.fT = pT;
82 }
83
84 @Override
85 public Object get(final String parameterName) {
86 switch(parameterName) {
87 case "T": return this.fT;
88 default: return null;
89 }
90 }
91
92 @Override
93 public Object get(final int index) {
94 switch(index) {
95 case 0: return this.fT;
96 default: return null;
97 }
98 }
99
100 public Turnout getT() {
101 return this.fT;
102 }
103
104 @Override
105 public boolean set(final String parameterName, final Object newValue) {
106 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
107 if ("T".equals(parameterName) ) {
108 this.fT = (Turnout) newValue;
109 return true;
110 }
111 return false;
112 }
113
114 public void setT(final Turnout pT) {
115 if (!isMutable()) throw new java.lang.UnsupportedOperationException();
116 this.fT = pT;
117 }
118
119 @Override
120 public String patternName() {
121 return "modes3.queries.inputsOfTurnout";
122 }
123
124 @Override
125 public List<String> parameterNames() {
126 return InputsOfTurnout.Match.parameterNames;
127 }
128
129 @Override
130 public Object[] toArray() {
131 return new Object[]{fT};
132 }
133
134 @Override
135 public InputsOfTurnout.Match toImmutable() {
136 return isMutable() ? newMatch(fT) : this;
137 }
138
139 @Override
140 public String prettyPrint() {
141 StringBuilder result = new StringBuilder();
142 result.append("\"T\"=" + prettyPrintValue(fT));
143 return result.toString();
144 }
145
146 @Override
147 public int hashCode() {
148 return Objects.hash(fT);
149 }
150
151 @Override
152 public boolean equals(final Object obj) {
153 if (this == obj)
154 return true;
155 if (obj == null) {
156 return false;
157 }
158 if ((obj instanceof InputsOfTurnout.Match)) {
159 InputsOfTurnout.Match other = (InputsOfTurnout.Match) obj;
160 return Objects.equals(fT, other.fT);
161 } else {
162 // this should be infrequent
163 if (!(obj instanceof IPatternMatch)) {
164 return false;
165 }
166 IPatternMatch otherSig = (IPatternMatch) obj;
167 return Objects.equals(specification(), otherSig.specification()) && Arrays.deepEquals(toArray(), otherSig.toArray());
168 }
169 }
170
171 @Override
172 public InputsOfTurnout specification() {
173 return InputsOfTurnout.instance();
174 }
175
176 /**
177 * Returns an empty, mutable match.
178 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
179 *
180 * @return the empty match.
181 *
182 */
183 public static InputsOfTurnout.Match newEmptyMatch() {
184 return new Mutable(null);
185 }
186
187 /**
188 * Returns a mutable (partial) match.
189 * Fields of the mutable match can be filled to create a partial match, usable as matcher input.
190 *
191 * @param pT the fixed value of pattern parameter T, or null if not bound.
192 * @return the new, mutable (partial) match object.
193 *
194 */
195 public static InputsOfTurnout.Match newMutableMatch(final Turnout pT) {
196 return new Mutable(pT);
197 }
198
199 /**
200 * Returns a new (partial) match.
201 * This can be used e.g. to call the matcher with a partial match.
202 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
203 * @param pT the fixed value of pattern parameter T, or null if not bound.
204 * @return the (partial) match object.
205 *
206 */
207 public static InputsOfTurnout.Match newMatch(final Turnout pT) {
208 return new Immutable(pT);
209 }
210
211 private static final class Mutable extends InputsOfTurnout.Match {
212 Mutable(final Turnout pT) {
213 super(pT);
214 }
215
216 @Override
217 public boolean isMutable() {
218 return true;
219 }
220 }
221
222 private static final class Immutable extends InputsOfTurnout.Match {
223 Immutable(final Turnout pT) {
224 super(pT);
225 }
226
227 @Override
228 public boolean isMutable() {
229 return false;
230 }
231 }
232 }
233
234 /**
235 * Generated pattern matcher API of the modes3.queries.inputsOfTurnout pattern,
236 * providing pattern-specific query methods.
237 *
238 * <p>Use the pattern matcher on a given model via {@link #on(ViatraQueryEngine)},
239 * e.g. in conjunction with {@link ViatraQueryEngine#on(QueryScope)}.
240 *
241 * <p>Matches of the pattern will be represented as {@link Match}.
242 *
243 * <p>Original source:
244 * <code><pre>
245 * pattern inputsOfTurnout(T : Turnout) {
246 * find adjacent(I1, T);
247 * find adjacent(I2, T);
248 * find adjacent(I3, T);
249 * I1 != I2;
250 * I1 != I3;
251 * I2 != I3;
252 * }
253 * </pre></code>
254 *
255 * @see Match
256 * @see InputsOfTurnout
257 *
258 */
259 public static class Matcher extends BaseMatcher<InputsOfTurnout.Match> {
260 /**
261 * Initializes the pattern matcher within an existing VIATRA Query engine.
262 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
263 *
264 * @param engine the existing VIATRA Query engine in which this matcher will be created.
265 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
266 *
267 */
268 public static InputsOfTurnout.Matcher on(final ViatraQueryEngine engine) {
269 // check if matcher already exists
270 Matcher matcher = engine.getExistingMatcher(querySpecification());
271 if (matcher == null) {
272 matcher = (Matcher)engine.getMatcher(querySpecification());
273 }
274 return matcher;
275 }
276
277 /**
278 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
279 * @return an initialized matcher
280 * @noreference This method is for internal matcher initialization by the framework, do not call it manually.
281 *
282 */
283 public static InputsOfTurnout.Matcher create() {
284 return new Matcher();
285 }
286
287 private static final int POSITION_T = 0;
288
289 private static final Logger LOGGER = ViatraQueryLoggingUtil.getLogger(InputsOfTurnout.Matcher.class);
290
291 /**
292 * Initializes the pattern matcher within an existing VIATRA Query engine.
293 * If the pattern matcher is already constructed in the engine, only a light-weight reference is returned.
294 *
295 * @param engine the existing VIATRA Query engine in which this matcher will be created.
296 * @throws ViatraQueryRuntimeException if an error occurs during pattern matcher creation
297 *
298 */
299 private Matcher() {
300 super(querySpecification());
301 }
302
303 /**
304 * Returns the set of all matches of the pattern that conform to the given fixed values of some parameters.
305 * @param pT the fixed value of pattern parameter T, or null if not bound.
306 * @return matches represented as a Match object.
307 *
308 */
309 public Collection<InputsOfTurnout.Match> getAllMatches(final Turnout pT) {
310 return rawStreamAllMatches(new Object[]{pT}).collect(Collectors.toSet());
311 }
312
313 /**
314 * Returns a stream of all matches of the pattern that conform to the given fixed values of some parameters.
315 * </p>
316 * <strong>NOTE</strong>: It is important not to modify the source model while the stream is being processed.
317 * If the match set of the pattern changes during processing, the contents of the stream is <strong>undefined</strong>.
318 * In such cases, either rely on {@link #getAllMatches()} or collect the results of the stream in end-user code.
319 * @param pT the fixed value of pattern parameter T, or null if not bound.
320 * @return a stream of matches represented as a Match object.
321 *
322 */
323 public Stream<InputsOfTurnout.Match> streamAllMatches(final Turnout pT) {
324 return rawStreamAllMatches(new Object[]{pT});
325 }
326
327 /**
328 * Returns an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
329 * Neither determinism nor randomness of selection is guaranteed.
330 * @param pT the fixed value of pattern parameter T, or null if not bound.
331 * @return a match represented as a Match object, or null if no match is found.
332 *
333 */
334 public Optional<InputsOfTurnout.Match> getOneArbitraryMatch(final Turnout pT) {
335 return rawGetOneArbitraryMatch(new Object[]{pT});
336 }
337
338 /**
339 * Indicates whether the given combination of specified pattern parameters constitute a valid pattern match,
340 * under any possible substitution of the unspecified parameters (if any).
341 * @param pT the fixed value of pattern parameter T, or null if not bound.
342 * @return true if the input is a valid (partial) match of the pattern.
343 *
344 */
345 public boolean hasMatch(final Turnout pT) {
346 return rawHasMatch(new Object[]{pT});
347 }
348
349 /**
350 * Returns the number of all matches of the pattern that conform to the given fixed values of some parameters.
351 * @param pT the fixed value of pattern parameter T, or null if not bound.
352 * @return the number of pattern matches found.
353 *
354 */
355 public int countMatches(final Turnout pT) {
356 return rawCountMatches(new Object[]{pT});
357 }
358
359 /**
360 * Executes the given processor on an arbitrarily chosen match of the pattern that conforms to the given fixed values of some parameters.
361 * Neither determinism nor randomness of selection is guaranteed.
362 * @param pT the fixed value of pattern parameter T, or null if not bound.
363 * @param processor the action that will process the selected match.
364 * @return true if the pattern has at least one match with the given parameter values, false if the processor was not invoked
365 *
366 */
367 public boolean forOneArbitraryMatch(final Turnout pT, final Consumer<? super InputsOfTurnout.Match> processor) {
368 return rawForOneArbitraryMatch(new Object[]{pT}, processor);
369 }
370
371 /**
372 * Returns a new (partial) match.
373 * This can be used e.g. to call the matcher with a partial match.
374 * <p>The returned match will be immutable. Use {@link #newEmptyMatch()} to obtain a mutable match object.
375 * @param pT the fixed value of pattern parameter T, or null if not bound.
376 * @return the (partial) match object.
377 *
378 */
379 public InputsOfTurnout.Match newMatch(final Turnout pT) {
380 return InputsOfTurnout.Match.newMatch(pT);
381 }
382
383 /**
384 * Retrieve the set of values that occur in matches for T.
385 * @return the Set of all values or empty set if there are no matches
386 *
387 */
388 protected Stream<Turnout> rawStreamAllValuesOfT(final Object[] parameters) {
389 return rawStreamAllValues(POSITION_T, parameters).map(Turnout.class::cast);
390 }
391
392 /**
393 * Retrieve the set of values that occur in matches for T.
394 * @return the Set of all values or empty set if there are no matches
395 *
396 */
397 public Set<Turnout> getAllValuesOfT() {
398 return rawStreamAllValuesOfT(emptyArray()).collect(Collectors.toSet());
399 }
400
401 /**
402 * Retrieve the set of values that occur in matches for T.
403 * @return the Set of all values or empty set if there are no matches
404 *
405 */
406 public Stream<Turnout> streamAllValuesOfT() {
407 return rawStreamAllValuesOfT(emptyArray());
408 }
409
410 @Override
411 protected InputsOfTurnout.Match tupleToMatch(final Tuple t) {
412 try {
413 return InputsOfTurnout.Match.newMatch((Turnout) t.get(POSITION_T));
414 } catch(ClassCastException e) {
415 LOGGER.error("Element(s) in tuple not properly typed!",e);
416 return null;
417 }
418 }
419
420 @Override
421 protected InputsOfTurnout.Match arrayToMatch(final Object[] match) {
422 try {
423 return InputsOfTurnout.Match.newMatch((Turnout) match[POSITION_T]);
424 } catch(ClassCastException e) {
425 LOGGER.error("Element(s) in array not properly typed!",e);
426 return null;
427 }
428 }
429
430 @Override
431 protected InputsOfTurnout.Match arrayToMatchMutable(final Object[] match) {
432 try {
433 return InputsOfTurnout.Match.newMutableMatch((Turnout) match[POSITION_T]);
434 } catch(ClassCastException e) {
435 LOGGER.error("Element(s) in array not properly typed!",e);
436 return null;
437 }
438 }
439
440 /**
441 * @return the singleton instance of the query specification of this pattern
442 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
443 *
444 */
445 public static IQuerySpecification<InputsOfTurnout.Matcher> querySpecification() {
446 return InputsOfTurnout.instance();
447 }
448 }
449
450 private InputsOfTurnout() {
451 super(GeneratedPQuery.INSTANCE);
452 }
453
454 /**
455 * @return the singleton instance of the query specification
456 * @throws ViatraQueryRuntimeException if the pattern definition could not be loaded
457 *
458 */
459 public static InputsOfTurnout instance() {
460 try{
461 return LazyHolder.INSTANCE;
462 } catch (ExceptionInInitializerError err) {
463 throw processInitializerError(err);
464 }
465 }
466
467 @Override
468 protected InputsOfTurnout.Matcher instantiate(final ViatraQueryEngine engine) {
469 return InputsOfTurnout.Matcher.on(engine);
470 }
471
472 @Override
473 public InputsOfTurnout.Matcher instantiate() {
474 return InputsOfTurnout.Matcher.create();
475 }
476
477 @Override
478 public InputsOfTurnout.Match newEmptyMatch() {
479 return InputsOfTurnout.Match.newEmptyMatch();
480 }
481
482 @Override
483 public InputsOfTurnout.Match newMatch(final Object... parameters) {
484 return InputsOfTurnout.Match.newMatch((modes3.Turnout) parameters[0]);
485 }
486
487 /**
488 * Inner class allowing the singleton instance of {@link InputsOfTurnout} to be created
489 * <b>not</b> at the class load time of the outer class,
490 * but rather at the first call to {@link InputsOfTurnout#instance()}.
491 *
492 * <p> This workaround is required e.g. to support recursion.
493 *
494 */
495 private static class LazyHolder {
496 private static final InputsOfTurnout INSTANCE = new InputsOfTurnout();
497
498 /**
499 * Statically initializes the query specification <b>after</b> the field {@link #INSTANCE} is assigned.
500 * This initialization order is required to support indirect recursion.
501 *
502 * <p> The static initializer is defined using a helper field to work around limitations of the code generator.
503 *
504 */
505 private static final Object STATIC_INITIALIZER = ensureInitialized();
506
507 public static Object ensureInitialized() {
508 INSTANCE.ensureInitializedInternal();
509 return null;
510 }
511 }
512
513 private static class GeneratedPQuery extends BaseGeneratedEMFPQuery {
514 private static final InputsOfTurnout.GeneratedPQuery INSTANCE = new GeneratedPQuery();
515
516 private final PParameter parameter_T = new PParameter("T", "modes3.Turnout", new EClassTransitiveInstancesKey((EClass)getClassifierLiteralSafe("http://www.ece.mcgill.ca/wcet/modes3", "Turnout")), PParameterDirection.INOUT);
517
518 private final List<PParameter> parameters = Arrays.asList(parameter_T);
519
520 private GeneratedPQuery() {
521 super(PVisibility.PUBLIC);
522 }
523
524 @Override
525 public String getFullyQualifiedName() {
526 return "modes3.queries.inputsOfTurnout";
527 }
528
529 @Override
530 public List<String> getParameterNames() {
531 return Arrays.asList("T");
532 }
533
534 @Override
535 public List<PParameter> getParameters() {
536 return parameters;
537 }
538
539 @Override
540 public Set<PBody> doGetContainedBodies() {
541 setEvaluationHints(new QueryEvaluationHint(null, QueryEvaluationHint.BackendRequirement.UNSPECIFIED));
542 Set<PBody> bodies = new LinkedHashSet<>();
543 {
544 PBody body = new PBody(this);
545 PVariable var_T = body.getOrCreateVariableByName("T");
546 PVariable var_I1 = body.getOrCreateVariableByName("I1");
547 PVariable var_I2 = body.getOrCreateVariableByName("I2");
548 PVariable var_I3 = body.getOrCreateVariableByName("I3");
549 new TypeConstraint(body, Tuples.flatTupleOf(var_T), new EClassTransitiveInstancesKey((EClass)getClassifierLiteral("http://www.ece.mcgill.ca/wcet/modes3", "Turnout")));
550 body.setSymbolicParameters(Arrays.<ExportedParameter>asList(
551 new ExportedParameter(body, var_T, parameter_T)
552 ));
553 // find adjacent(I1, T)
554 new PositivePatternCall(body, Tuples.flatTupleOf(var_I1, var_T), Adjacent.instance().getInternalQueryRepresentation());
555 // find adjacent(I2, T)
556 new PositivePatternCall(body, Tuples.flatTupleOf(var_I2, var_T), Adjacent.instance().getInternalQueryRepresentation());
557 // find adjacent(I3, T)
558 new PositivePatternCall(body, Tuples.flatTupleOf(var_I3, var_T), Adjacent.instance().getInternalQueryRepresentation());
559 // I1 != I2
560 new Inequality(body, var_I1, var_I2);
561 // I1 != I3
562 new Inequality(body, var_I1, var_I3);
563 // I2 != I3
564 new Inequality(body, var_I2, var_I3);
565 bodies.add(body);
566 }
567 return bodies;
568 }
569 }
570}