blob: 7d3835625530439fc2ce55a501fdbcdd9dc1bdb2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
/*
* SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/>
*
* SPDX-License-Identifier: EPL-2.0
*/
package tools.refinery.store.query.term.int_;
import tools.refinery.store.query.substitution.Substitution;
import tools.refinery.store.query.term.Term;
import tools.refinery.store.query.term.UnaryTerm;
public class RealToIntTerm extends UnaryTerm<Integer, Double> {
protected RealToIntTerm(Term<Double> body) {
super(Integer.class, Double.class, body);
}
@Override
protected Integer doEvaluate(Double bodyValue) {
return bodyValue.isNaN() ? null : bodyValue.intValue();
}
@Override
protected Term<Integer> doSubstitute(Substitution substitution, Term<Double> substitutedBody) {
return new RealToIntTerm(substitutedBody);
}
@Override
public String toString() {
return "(%s as int)".formatted(getBody());
}
}
|