aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/StructuralFeatureCheck.java
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/StructuralFeatureCheck.java')
-rw-r--r--subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/StructuralFeatureCheck.java91
1 files changed, 0 insertions, 91 deletions
diff --git a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/StructuralFeatureCheck.java b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/StructuralFeatureCheck.java
deleted file mode 100644
index a3e5bc40..00000000
--- a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/StructuralFeatureCheck.java
+++ /dev/null
@@ -1,91 +0,0 @@
1/*******************************************************************************
2 * Copyright (c) 2010-2013, Zoltan Ujhelyi, Istvan Rath and Daniel Varro
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.check;
10
11import java.util.Arrays;
12import java.util.Collection;
13import java.util.List;
14import java.util.Objects;
15import java.util.function.Function;
16
17import org.eclipse.emf.ecore.EObject;
18import org.eclipse.emf.ecore.EStructuralFeature;
19import tools.refinery.viatra.runtime.localsearch.MatchingFrame;
20import tools.refinery.viatra.runtime.localsearch.exceptions.LocalSearchException;
21import tools.refinery.viatra.runtime.localsearch.matcher.ISearchContext;
22import tools.refinery.viatra.runtime.localsearch.operations.CheckOperationExecutor;
23import tools.refinery.viatra.runtime.localsearch.operations.ISearchOperation;
24
25/**
26 * A simple operation that checks whether a {@link EStructuralFeature} connects two selected variables.
27 * @noextend This class is not intended to be subclassed by clients.
28 */
29public class StructuralFeatureCheck implements ISearchOperation {
30
31 private class Executor extends CheckOperationExecutor {
32
33 @Override
34 protected boolean check(MatchingFrame frame, ISearchContext context) {
35 Objects.requireNonNull(frame.getValue(sourcePosition), () -> String.format("Invalid plan, variable %s unbound", sourcePosition));
36 Objects.requireNonNull(frame.getValue(targetPosition), () -> String.format("Invalid plan, variable %s unbound", targetPosition));
37 try {
38 EObject source = (EObject) frame.getValue(sourcePosition);
39 if(! feature.getEContainingClass().isSuperTypeOf(source.eClass()) ){
40 // TODO planner should ensure the proper supertype relation, see bug 500968
41 return false;
42 }
43 Object target = frame.getValue(targetPosition);
44 if (feature.isMany()) {
45 return ((Collection<?>) source.eGet(feature)).contains(target);
46 } else {
47 return target.equals(source.eGet(feature));
48 }
49 } catch (ClassCastException e) {
50 throw new LocalSearchException(LocalSearchException.TYPE_ERROR, e);
51 }
52 }
53
54 @Override
55 public ISearchOperation getOperation() {
56 return StructuralFeatureCheck.this;
57 }
58 }
59
60 int sourcePosition;
61 int targetPosition;
62 EStructuralFeature feature;
63
64 public StructuralFeatureCheck(int sourcePosition, int targetPosition, EStructuralFeature feature) {
65 super();
66 this.sourcePosition = sourcePosition;
67 this.targetPosition = targetPosition;
68 this.feature = feature;
69 }
70
71 @Override
72 public ISearchOperationExecutor createExecutor() {
73 return new Executor();
74 }
75
76 @Override
77 public String toString() {
78 return toString(Object::toString);
79 }
80
81 @Override
82 public String toString(Function<Integer, String> variableMapping) {
83 return "check "+feature.getContainerClass().getSimpleName()+"."+feature.getName()+"(+"+variableMapping.apply(sourcePosition)+", +"+variableMapping.apply(targetPosition)+")";
84 }
85
86 @Override
87 public List<Integer> getVariablePositions() {
88 return Arrays.asList(sourcePosition, targetPosition);
89 }
90
91}