Skip to content

Commit 306c894

Browse files
committed
Review comments - fn:round
Use simplest function DSL methods Rename tests to .xqm
1 parent e9b6723 commit 306c894

File tree

3 files changed

+26
-24
lines changed

3 files changed

+26
-24
lines changed

exist-core/src/main/java/org/exist/xquery/functions/fn/FunRound.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,16 @@
2121
*/
2222
package org.exist.xquery.functions.fn;
2323

24-
import org.exist.dom.QName;
25-
import org.exist.xquery.*;
24+
import org.exist.xquery.Cardinality;
25+
import org.exist.xquery.FunctionSignature;
26+
import org.exist.xquery.XPathException;
27+
import org.exist.xquery.XQueryContext;
2628
import org.exist.xquery.value.*;
2729

2830
import java.math.RoundingMode;
29-
import java.util.Objects;
31+
32+
import static org.exist.xquery.FunctionDSL.optParam;
33+
import static org.exist.xquery.functions.fn.FnModule.functionSignature;
3034

3135
/**
3236
* Implement fn:round() function
@@ -36,7 +40,7 @@
3640
*/
3741
public class FunRound extends FunRoundBase {
3842

39-
private static final QName qName = new QName("round", Function.BUILTIN_FUNCTION_NS);
43+
private static final String FN_NAME = "round";
4044
private static final String description = "The function returns the nearest (that is, numerically closest) " +
4145
"value to $arg that is a multiple of ten to the power of minus $precision. " +
4246
"If two such values are equally near (for example, if the fractional part in $arg is exactly .5), " +
@@ -61,11 +65,11 @@ public class FunRound extends FunRoundBase {
6165
private static final FunctionReturnSequenceType returnType = new FunctionReturnSequenceType(Type.NUMBER, Cardinality.ZERO_OR_ONE, "the rounded value");
6266

6367
public static final FunctionSignature[] FN_ROUND_SIGNATURES = {
64-
FunctionDSL.functionSignature(FunRound.qName, FunRound.description, FunRound.returnType,
65-
new FunctionParameterSequenceType("arg", Type.NUMBER, Cardinality.ZERO_OR_ONE, "The input number")),
66-
FunctionDSL.functionSignature(FunRound.qName, FunRound.description, FunRound.returnType,
67-
new FunctionParameterSequenceType("arg", Type.NUMBER, Cardinality.ZERO_OR_ONE, "The input number"),
68-
new FunctionParameterSequenceType("precision", Type.INTEGER, Cardinality.ZERO_OR_ONE, "The input number"))
68+
functionSignature(FN_NAME, FunRound.description, FunRound.returnType,
69+
optParam("arg", Type.NUMBER, "The input number")),
70+
functionSignature(FN_NAME, FunRound.description, FunRound.returnType,
71+
optParam("arg", Type.NUMBER, "The input number"),
72+
optParam("precision", Type.INTEGER, "The input number"))
6973
};
7074

7175
public FunRound(final XQueryContext context, final FunctionSignature signature) {

exist-core/src/main/java/org/exist/xquery/functions/fn/FunRoundHalfToEven.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,18 @@
2121
*/
2222
package org.exist.xquery.functions.fn;
2323

24-
import org.exist.dom.QName;
25-
import org.exist.xquery.*;
26-
import org.exist.xquery.value.FunctionParameterSequenceType;
24+
import org.exist.xquery.Cardinality;
25+
import org.exist.xquery.FunctionSignature;
26+
import org.exist.xquery.XQueryContext;
2727
import org.exist.xquery.value.FunctionReturnSequenceType;
28-
import org.exist.xquery.value.IntegerValue;
29-
import org.exist.xquery.value.Item;
3028
import org.exist.xquery.value.NumericValue;
31-
import org.exist.xquery.value.Sequence;
32-
import org.exist.xquery.value.SequenceType;
3329
import org.exist.xquery.value.Type;
3430

3531
import java.math.RoundingMode;
3632

33+
import static org.exist.xquery.FunctionDSL.optParam;
34+
import static org.exist.xquery.functions.fn.FnModule.functionSignature;
35+
3736
/**
3837
* Implements the fn:round-half-to-even() function.
3938
*
@@ -45,7 +44,7 @@
4544
*/
4645
public class FunRoundHalfToEven extends FunRoundBase {
4746

48-
private static final QName qName = new QName("round-half-to-even", Function.BUILTIN_FUNCTION_NS);
47+
private static final String FN_NAME = "round-half-to-even";
4948

5049
protected static final String FUNCTION_DESCRIPTION_1_PARAM =
5150
"The value returned is the nearest (that is, numerically closest) " +
@@ -78,16 +77,15 @@ public class FunRoundHalfToEven extends FunRoundBase {
7877
"If $arg is of type xs:float or xs:double, rounding occurs on the " +
7978
"value of the mantissa computed with exponent = 0.";
8079

81-
protected static final FunctionParameterSequenceType ARG_PARAM = new FunctionParameterSequenceType("arg", Type.NUMBER, Cardinality.ZERO_OR_ONE, "The input number");
82-
protected static final FunctionParameterSequenceType PRECISION_PARAM = new FunctionParameterSequenceType("precision", Type.INTEGER, Cardinality.EXACTLY_ONE, "The precision factor");
8380
protected static final FunctionReturnSequenceType RETURN_TYPE = new FunctionReturnSequenceType(Type.NUMBER, Cardinality.ZERO_OR_ONE, "the rounded value");
8481

8582
public static final FunctionSignature[] FN_ROUND_HALF_TO_EVEN_SIGNATURES = {
86-
FunctionDSL.functionSignature(FunRoundHalfToEven.qName, FunRoundHalfToEven.FUNCTION_DESCRIPTION_1_PARAM + FunRoundHalfToEven.FUNCTION_DESCRIPTION_COMMON, FunRoundHalfToEven.RETURN_TYPE,
87-
new FunctionParameterSequenceType("arg", Type.NUMBER, Cardinality.ZERO_OR_ONE, "The input number")),
88-
FunctionDSL.functionSignature(FunRoundHalfToEven.qName, FunRoundHalfToEven.FUNCTION_DESCRIPTION_2_PARAM + FunRoundHalfToEven.FUNCTION_DESCRIPTION_COMMON, RETURN_TYPE,
89-
new FunctionParameterSequenceType("arg", Type.NUMBER, Cardinality.ZERO_OR_ONE, "The input number"),
90-
new FunctionParameterSequenceType("precision", Type.INTEGER, Cardinality.ZERO_OR_ONE, "The input number")) };
83+
functionSignature(FN_NAME, FunRoundHalfToEven.FUNCTION_DESCRIPTION_1_PARAM + FunRoundHalfToEven.FUNCTION_DESCRIPTION_COMMON, FunRoundHalfToEven.RETURN_TYPE,
84+
optParam("arg", Type.NUMBER, "The input number")),
85+
functionSignature(FN_NAME, FunRoundHalfToEven.FUNCTION_DESCRIPTION_2_PARAM + FunRoundHalfToEven.FUNCTION_DESCRIPTION_COMMON, RETURN_TYPE,
86+
optParam("arg", Type.NUMBER, "The input number"),
87+
optParam("precision", Type.INTEGER, "Precision to round to"))
88+
};
9189

9290
public FunRoundHalfToEven(final XQueryContext context,
9391
final FunctionSignature signature) {
File renamed without changes.

0 commit comments

Comments
 (0)