aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/nobase/AbstractIteratingExtendOperationExecutor.java
diff options
context:
space:
mode:
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.java54
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 *******************************************************************************/
9package tools.refinery.viatra.runtime.localsearch.operations.extend.nobase;
10
11import java.util.Collections;
12import java.util.Spliterator;
13import java.util.Spliterators;
14import java.util.stream.Stream;
15import java.util.stream.StreamSupport;
16
17import org.eclipse.emf.common.notify.Notifier;
18import org.eclipse.emf.ecore.EObject;
19import org.eclipse.emf.ecore.resource.Resource;
20import org.eclipse.emf.ecore.resource.ResourceSet;
21import tools.refinery.viatra.runtime.emf.EMFScope;
22import 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 */
31abstract 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}