aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/interpreter/src/main/java/tools/refinery/interpreter/matchers/psystem/basicdeferred/LeftJoinConstraint.java
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/interpreter/src/main/java/tools/refinery/interpreter/matchers/psystem/basicdeferred/LeftJoinConstraint.java')
-rw-r--r--subprojects/interpreter/src/main/java/tools/refinery/interpreter/matchers/psystem/basicdeferred/LeftJoinConstraint.java82
1 files changed, 82 insertions, 0 deletions
diff --git a/subprojects/interpreter/src/main/java/tools/refinery/interpreter/matchers/psystem/basicdeferred/LeftJoinConstraint.java b/subprojects/interpreter/src/main/java/tools/refinery/interpreter/matchers/psystem/basicdeferred/LeftJoinConstraint.java
new file mode 100644
index 00000000..1c1a895e
--- /dev/null
+++ b/subprojects/interpreter/src/main/java/tools/refinery/interpreter/matchers/psystem/basicdeferred/LeftJoinConstraint.java
@@ -0,0 +1,82 @@
1/*******************************************************************************
2 * Copyright (c) 2010-2016, Tamas Szabo, Istvan Rath and Daniel Varro
3 * Copyright (c) 2024 The Refinery Authors <https://refinery.tools/>
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v. 2.0 which is available at
6 * http://www.eclipse.org/legal/epl-v20.html.
7 * SPDX-License-Identifier: EPL-2.0
8 *******************************************************************************/
9package tools.refinery.interpreter.matchers.psystem.basicdeferred;
10
11import tools.refinery.interpreter.matchers.context.IQueryMetaContext;
12import tools.refinery.interpreter.matchers.psystem.ITypeInfoProviderConstraint;
13import tools.refinery.interpreter.matchers.psystem.PBody;
14import tools.refinery.interpreter.matchers.psystem.PVariable;
15import tools.refinery.interpreter.matchers.psystem.TypeJudgement;
16import tools.refinery.interpreter.matchers.psystem.queries.PQuery;
17import tools.refinery.interpreter.matchers.tuple.Tuple;
18import tools.refinery.interpreter.matchers.tuple.Tuples;
19
20import java.util.Collections;
21import java.util.Set;
22
23public class LeftJoinConstraint extends PatternCallBasedDeferred implements ITypeInfoProviderConstraint {
24 protected PVariable resultVariable;
25 protected int optionalColumn;
26 protected Object defaultValue;
27
28 public LeftJoinConstraint(PBody pBody, Tuple actualParametersTuple, PQuery query, PVariable resultVariable,
29 int optionalColumn, Object defaultValue) {
30 super(pBody, actualParametersTuple, query, Collections.singleton(resultVariable));
31 this.resultVariable = resultVariable;
32 this.optionalColumn = optionalColumn;
33 this.defaultValue = defaultValue;
34 }
35
36 public PVariable getResultVariable() {
37 return resultVariable;
38 }
39
40 public int getOptionalColumn() {
41 return optionalColumn;
42 }
43
44 public Object getDefaultValue() {
45 return defaultValue;
46 }
47
48 @Override
49 public Set<PVariable> getDeducedVariables() {
50 return Collections.singleton(resultVariable);
51 }
52
53 @Override
54 protected void doDoReplaceVariables(PVariable obsolete, PVariable replacement) {
55 if (resultVariable.equals(obsolete)) {
56 resultVariable = replacement;
57 }
58 }
59
60 @Override
61 protected Set<PVariable> getCandidateQuantifiedVariables() {
62 return actualParametersTuple.getDistinctElements();
63 }
64
65 @Override
66 protected String toStringRest() {
67 return query.getFullyQualifiedName() + "@" + actualParametersTuple.toString() + "->"
68 + resultVariable.toString();
69 }
70
71 @Override
72 public Set<TypeJudgement> getImpliedJudgements(IQueryMetaContext context) {
73 var optionalParameter = getReferredQuery().getParameters().get(optionalColumn);
74 var unaryType = optionalParameter.getDeclaredUnaryType();
75 if (unaryType != null && !context.isEnumerable(unaryType)) {
76 // The outer join makes the result variable non-enumerable, since the default value might not be present in
77 // the model.
78 return Set.of(new TypeJudgement(unaryType, Tuples.staticArityFlatTupleOf(resultVariable)));
79 }
80 return Set.of();
81 }
82}