diff options
Diffstat (limited to 'subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/InequalityCheck.java')
-rw-r--r-- | subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/InequalityCheck.java | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/InequalityCheck.java b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/InequalityCheck.java new file mode 100644 index 00000000..3f30c3c4 --- /dev/null +++ b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/InequalityCheck.java | |||
@@ -0,0 +1,77 @@ | |||
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 | *******************************************************************************/ | ||
9 | package tools.refinery.viatra.runtime.localsearch.operations.check; | ||
10 | |||
11 | import java.util.Arrays; | ||
12 | import java.util.List; | ||
13 | import java.util.function.Function; | ||
14 | |||
15 | import tools.refinery.viatra.runtime.localsearch.MatchingFrame; | ||
16 | import tools.refinery.viatra.runtime.localsearch.exceptions.LocalSearchException; | ||
17 | import tools.refinery.viatra.runtime.localsearch.matcher.ISearchContext; | ||
18 | import tools.refinery.viatra.runtime.localsearch.operations.CheckOperationExecutor; | ||
19 | import tools.refinery.viatra.runtime.localsearch.operations.ISearchOperation; | ||
20 | |||
21 | /** | ||
22 | * @author Zoltan Ujhelyi | ||
23 | * @noextend This class is not intended to be subclassed by clients. | ||
24 | */ | ||
25 | public class InequalityCheck implements ISearchOperation { | ||
26 | |||
27 | private class Executor extends CheckOperationExecutor { | ||
28 | |||
29 | @Override | ||
30 | protected boolean check(MatchingFrame frame, ISearchContext context) { | ||
31 | Object source = frame.getValue(sourceLocation); | ||
32 | Object target = frame.getValue(targetLocation); | ||
33 | if (source == null) { | ||
34 | throw new LocalSearchException("Source not bound."); | ||
35 | } | ||
36 | if (target == null) { | ||
37 | throw new LocalSearchException("Target not bound"); | ||
38 | } | ||
39 | return !source.equals(target); | ||
40 | } | ||
41 | |||
42 | @Override | ||
43 | public ISearchOperation getOperation() { | ||
44 | return InequalityCheck.this; | ||
45 | } | ||
46 | } | ||
47 | |||
48 | int sourceLocation; | ||
49 | int targetLocation; | ||
50 | |||
51 | public InequalityCheck(int sourceLocation, int targetLocation) { | ||
52 | super(); | ||
53 | this.sourceLocation = sourceLocation; | ||
54 | this.targetLocation = targetLocation; | ||
55 | } | ||
56 | |||
57 | @Override | ||
58 | public ISearchOperationExecutor createExecutor() { | ||
59 | return new Executor(); | ||
60 | } | ||
61 | |||
62 | @Override | ||
63 | public String toString() { | ||
64 | return toString(Object::toString); | ||
65 | } | ||
66 | |||
67 | @Override | ||
68 | public String toString(Function<Integer, String> variableMapping) { | ||
69 | return "check "+variableMapping.apply(sourceLocation)+" != "+variableMapping.apply(targetLocation); | ||
70 | } | ||
71 | |||
72 | @Override | ||
73 | public List<Integer> getVariablePositions() { | ||
74 | return Arrays.asList(sourceLocation, targetLocation); | ||
75 | } | ||
76 | |||
77 | } | ||