diff options
author | Kristóf Marussy <kristof@marussy.com> | 2023-08-19 02:31:57 +0200 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2023-08-19 02:31:57 +0200 |
commit | 9adbb3d49899a87b3026c11cb4ba3ff77f4fb75b (patch) | |
tree | fad77963c1dc9028b0a767ac3ad69a174c8eb8c6 /subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/nobase/AbstractIteratingExtendOperationExecutor.java | |
parent | feat: predicate semantics (diff) | |
download | refinery-9adbb3d49899a87b3026c11cb4ba3ff77f4fb75b.tar.gz refinery-9adbb3d49899a87b3026c11cb4ba3ff77f4fb75b.tar.zst refinery-9adbb3d49899a87b3026c11cb4ba3ff77f4fb75b.zip |
chore: import VIATRA source
Make our modifications more maintainable by editing the source code directly
instead of using reflection.
Diffstat (limited to 'subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/nobase/AbstractIteratingExtendOperationExecutor.java')
-rw-r--r-- | subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/nobase/AbstractIteratingExtendOperationExecutor.java | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/nobase/AbstractIteratingExtendOperationExecutor.java b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/nobase/AbstractIteratingExtendOperationExecutor.java new file mode 100644 index 00000000..954d4c88 --- /dev/null +++ b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/nobase/AbstractIteratingExtendOperationExecutor.java | |||
@@ -0,0 +1,54 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2016, Grill Balázs, IncQuery Labs Ltd. | ||
3 | * This program and the accompanying materials are made available under the | ||
4 | * terms of the Eclipse Public License v. 2.0 which is available at | ||
5 | * http://www.eclipse.org/legal/epl-v20.html. | ||
6 | * | ||
7 | * SPDX-License-Identifier: EPL-2.0 | ||
8 | *******************************************************************************/ | ||
9 | package tools.refinery.viatra.runtime.localsearch.operations.extend.nobase; | ||
10 | |||
11 | import java.util.Collections; | ||
12 | import java.util.Spliterator; | ||
13 | import java.util.Spliterators; | ||
14 | import java.util.stream.Stream; | ||
15 | import java.util.stream.StreamSupport; | ||
16 | |||
17 | import org.eclipse.emf.common.notify.Notifier; | ||
18 | import org.eclipse.emf.ecore.EObject; | ||
19 | import org.eclipse.emf.ecore.resource.Resource; | ||
20 | import org.eclipse.emf.ecore.resource.ResourceSet; | ||
21 | import tools.refinery.viatra.runtime.emf.EMFScope; | ||
22 | import tools.refinery.viatra.runtime.localsearch.operations.extend.SingleValueExtendOperationExecutor; | ||
23 | |||
24 | /** | ||
25 | * This abstract class provides a utility method for extenders to iterate over the given scope. | ||
26 | * | ||
27 | * @author Grill Balázs | ||
28 | * @noextend This class is not intended to be subclassed by clients. | ||
29 | * | ||
30 | */ | ||
31 | abstract class AbstractIteratingExtendOperationExecutor<T> extends SingleValueExtendOperationExecutor<T> { | ||
32 | |||
33 | private final EMFScope scope; | ||
34 | |||
35 | public AbstractIteratingExtendOperationExecutor(int position, EMFScope scope) { | ||
36 | super(position); | ||
37 | this.scope = scope; | ||
38 | } | ||
39 | |||
40 | protected Stream<Notifier> getModelContents() { | ||
41 | return scope.getScopeRoots().stream().map(input -> { | ||
42 | if (input instanceof ResourceSet) { | ||
43 | return ((ResourceSet) input).getAllContents(); | ||
44 | } else if (input instanceof Resource) { | ||
45 | return ((Resource) input).getAllContents(); | ||
46 | } else if (input instanceof EObject) { | ||
47 | return ((EObject) input).eAllContents(); | ||
48 | } | ||
49 | return Collections.<Notifier> emptyIterator(); | ||
50 | }).map(i -> StreamSupport.stream(Spliterators.spliteratorUnknownSize(i, Spliterator.ORDERED), false)) | ||
51 | .flatMap(i -> i); | ||
52 | } | ||
53 | |||
54 | } | ||