diff options
Diffstat (limited to 'subprojects/logic/src/main/java/tools/refinery/logic/term/int_/RealToIntTerm.java')
-rw-r--r-- | subprojects/logic/src/main/java/tools/refinery/logic/term/int_/RealToIntTerm.java | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/subprojects/logic/src/main/java/tools/refinery/logic/term/int_/RealToIntTerm.java b/subprojects/logic/src/main/java/tools/refinery/logic/term/int_/RealToIntTerm.java new file mode 100644 index 00000000..7611af90 --- /dev/null +++ b/subprojects/logic/src/main/java/tools/refinery/logic/term/int_/RealToIntTerm.java | |||
@@ -0,0 +1,31 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
6 | package tools.refinery.logic.term.int_; | ||
7 | |||
8 | import tools.refinery.logic.term.Term; | ||
9 | import tools.refinery.logic.term.UnaryTerm; | ||
10 | import tools.refinery.logic.substitution.Substitution; | ||
11 | |||
12 | public class RealToIntTerm extends UnaryTerm<Integer, Double> { | ||
13 | protected RealToIntTerm(Term<Double> body) { | ||
14 | super(Integer.class, Double.class, body); | ||
15 | } | ||
16 | |||
17 | @Override | ||
18 | protected Integer doEvaluate(Double bodyValue) { | ||
19 | return bodyValue.isNaN() ? null : bodyValue.intValue(); | ||
20 | } | ||
21 | |||
22 | @Override | ||
23 | protected Term<Integer> doSubstitute(Substitution substitution, Term<Double> substitutedBody) { | ||
24 | return new RealToIntTerm(substitutedBody); | ||
25 | } | ||
26 | |||
27 | @Override | ||
28 | public String toString() { | ||
29 | return "(%s as int)".formatted(getBody()); | ||
30 | } | ||
31 | } | ||