diff options
author | Kristóf Marussy <marussy@mit.bme.hu> | 2020-11-02 02:02:40 +0100 |
---|---|---|
committer | Kristóf Marussy <marussy@mit.bme.hu> | 2020-11-02 02:02:40 +0100 |
commit | f06427cd7375551582461f91b3458339a8227f9b (patch) | |
tree | 97bc6ec85f4c384e5080a6611b492caf460b6ce9 /Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TrainLocations_step_3.java | |
parent | Must unit propagation (diff) | |
download | VIATRA-Generator-f06427cd7375551582461f91b3458339a8227f9b.tar.gz VIATRA-Generator-f06427cd7375551582461f91b3458339a8227f9b.tar.zst VIATRA-Generator-f06427cd7375551582461f91b3458339a8227f9b.zip |
Optimizing generator with linear objective functions
Diffstat (limited to 'Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TrainLocations_step_3.java')
-rw-r--r-- | Domains/ca.mcgill.rtgmrt.example.modes3/vql-gen/modes3/queries/TrainLocations_step_3.java | 713 |
1 files changed, 713 insertions, 0 deletions
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 | */ | ||
4 | package modes3.queries; | ||
5 | |||
6 | import java.util.Arrays; | ||
7 | import java.util.Collection; | ||
8 | import java.util.LinkedHashSet; | ||
9 | import java.util.List; | ||
10 | import java.util.Objects; | ||
11 | import java.util.Optional; | ||
12 | import java.util.Set; | ||
13 | import java.util.function.Consumer; | ||
14 | import java.util.stream.Collectors; | ||
15 | import java.util.stream.Stream; | ||
16 | import modes3.Segment; | ||
17 | import modes3.Train; | ||
18 | import org.apache.log4j.Logger; | ||
19 | import org.eclipse.emf.ecore.EClass; | ||
20 | import org.eclipse.viatra.query.runtime.api.IPatternMatch; | ||
21 | import org.eclipse.viatra.query.runtime.api.IQuerySpecification; | ||
22 | import org.eclipse.viatra.query.runtime.api.ViatraQueryEngine; | ||
23 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFPQuery; | ||
24 | import org.eclipse.viatra.query.runtime.api.impl.BaseGeneratedEMFQuerySpecification; | ||
25 | import org.eclipse.viatra.query.runtime.api.impl.BaseMatcher; | ||
26 | import org.eclipse.viatra.query.runtime.api.impl.BasePatternMatch; | ||
27 | import org.eclipse.viatra.query.runtime.emf.types.EClassTransitiveInstancesKey; | ||
28 | import org.eclipse.viatra.query.runtime.emf.types.EStructuralFeatureInstancesKey; | ||
29 | import org.eclipse.viatra.query.runtime.matchers.backend.QueryEvaluationHint; | ||
30 | import org.eclipse.viatra.query.runtime.matchers.psystem.PBody; | ||
31 | import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable; | ||
32 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.Equality; | ||
33 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
34 | import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
35 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameter; | ||
36 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PParameterDirection; | ||
37 | import org.eclipse.viatra.query.runtime.matchers.psystem.queries.PVisibility; | ||
38 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple; | ||
39 | import org.eclipse.viatra.query.runtime.matchers.tuple.Tuples; | ||
40 | import 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") | ||
60 | public 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 | } | ||