diff options
Diffstat (limited to 'subprojects/store-query/src/main/java/tools/refinery/store/query/literal/CallLiteral.java')
-rw-r--r-- | subprojects/store-query/src/main/java/tools/refinery/store/query/literal/CallLiteral.java | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/subprojects/store-query/src/main/java/tools/refinery/store/query/literal/CallLiteral.java b/subprojects/store-query/src/main/java/tools/refinery/store/query/literal/CallLiteral.java index 29772aee..2d0e4e97 100644 --- a/subprojects/store-query/src/main/java/tools/refinery/store/query/literal/CallLiteral.java +++ b/subprojects/store-query/src/main/java/tools/refinery/store/query/literal/CallLiteral.java | |||
@@ -6,13 +6,17 @@ | |||
6 | package tools.refinery.store.query.literal; | 6 | package tools.refinery.store.query.literal; |
7 | 7 | ||
8 | import tools.refinery.store.query.Constraint; | 8 | import tools.refinery.store.query.Constraint; |
9 | import tools.refinery.store.query.InvalidQueryException; | ||
9 | import tools.refinery.store.query.equality.LiteralEqualityHelper; | 10 | import tools.refinery.store.query.equality.LiteralEqualityHelper; |
11 | import tools.refinery.store.query.equality.LiteralHashCodeHelper; | ||
10 | import tools.refinery.store.query.substitution.Substitution; | 12 | import tools.refinery.store.query.substitution.Substitution; |
11 | import tools.refinery.store.query.term.ParameterDirection; | 13 | import tools.refinery.store.query.term.ParameterDirection; |
12 | import tools.refinery.store.query.term.Variable; | 14 | import tools.refinery.store.query.term.Variable; |
13 | 15 | ||
14 | import java.util.*; | 16 | import java.util.*; |
15 | 17 | ||
18 | // {@link Object#equals(Object)} is implemented by {@link AbstractLiteral}. | ||
19 | @SuppressWarnings("squid:S2160") | ||
16 | public final class CallLiteral extends AbstractCallLiteral implements CanNegate<CallLiteral> { | 20 | public final class CallLiteral extends AbstractCallLiteral implements CanNegate<CallLiteral> { |
17 | private final CallPolarity polarity; | 21 | private final CallPolarity polarity; |
18 | 22 | ||
@@ -22,10 +26,14 @@ public final class CallLiteral extends AbstractCallLiteral implements CanNegate< | |||
22 | int arity = target.arity(); | 26 | int arity = target.arity(); |
23 | if (polarity.isTransitive()) { | 27 | if (polarity.isTransitive()) { |
24 | if (arity != 2) { | 28 | if (arity != 2) { |
25 | throw new IllegalArgumentException("Transitive closures can only take binary relations"); | 29 | throw new InvalidQueryException("Transitive closures can only take binary relations"); |
26 | } | 30 | } |
27 | if (parameters.get(0).isDataVariable() || parameters.get(1).isDataVariable()) { | 31 | if (parameters.get(0).isDataVariable() || parameters.get(1).isDataVariable()) { |
28 | throw new IllegalArgumentException("Transitive closures can only be computed over nodes"); | 32 | throw new InvalidQueryException("Transitive closures can only be computed over nodes"); |
33 | } | ||
34 | if (parameters.get(0).getDirection() != ParameterDirection.OUT || | ||
35 | parameters.get(1).getDirection() != ParameterDirection.OUT) { | ||
36 | throw new InvalidQueryException("Transitive closures cannot take input parameters"); | ||
29 | } | 37 | } |
30 | } | 38 | } |
31 | this.polarity = polarity; | 39 | this.polarity = polarity; |
@@ -85,22 +93,18 @@ public final class CallLiteral extends AbstractCallLiteral implements CanNegate< | |||
85 | } | 93 | } |
86 | 94 | ||
87 | @Override | 95 | @Override |
88 | public CallLiteral negate() { | 96 | public int hashCodeWithSubstitution(LiteralHashCodeHelper helper) { |
89 | return new CallLiteral(polarity.negate(), getTarget(), getArguments()); | 97 | return Objects.hash(super.hashCodeWithSubstitution(helper), polarity); |
90 | } | 98 | } |
91 | 99 | ||
92 | @Override | 100 | @Override |
93 | public boolean equals(Object o) { | 101 | public CallLiteral negate() { |
94 | if (this == o) return true; | 102 | return new CallLiteral(polarity.negate(), getTarget(), getArguments()); |
95 | if (o == null || getClass() != o.getClass()) return false; | ||
96 | if (!super.equals(o)) return false; | ||
97 | CallLiteral that = (CallLiteral) o; | ||
98 | return polarity == that.polarity; | ||
99 | } | 103 | } |
100 | 104 | ||
101 | @Override | 105 | @Override |
102 | public int hashCode() { | 106 | public AbstractCallLiteral withArguments(Constraint newTarget, List<Variable> newArguments) { |
103 | return Objects.hash(super.hashCode(), polarity); | 107 | return new CallLiteral(polarity, newTarget, newArguments); |
104 | } | 108 | } |
105 | 109 | ||
106 | @Override | 110 | @Override |