Skip to content

Commit 9e78c73

Browse files
committed
[refactor] DoubleValue constructor
- use switch-statement for readability
1 parent 956376c commit 9e78c73

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

exist-core/src/main/java/org/exist/xquery/value/DoubleValue.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,15 @@ public DoubleValue(final String stringValue) throws XPathException {
7474
public DoubleValue(final Expression expression, final String stringValue) throws XPathException {
7575
super(expression);
7676
try {
77-
if ("INF".equals(stringValue)) {
78-
value = Double.POSITIVE_INFINITY;
79-
} else if ("-INF".equals(stringValue)) {
80-
value = Double.NEGATIVE_INFINITY;
81-
} else if ("NaN".equals(stringValue)) {
82-
value = Double.NaN;
83-
} else {
84-
value = Double.parseDouble(stringValue);
85-
}
77+
value = switch (stringValue) {
78+
case "INF" -> Double.POSITIVE_INFINITY;
79+
case "-INF" -> Double.NEGATIVE_INFINITY;
80+
case "NaN" -> Double.NaN;
81+
default -> Double.parseDouble(stringValue);
82+
};
8683
} catch (final NumberFormatException e) {
87-
throw new XPathException(getExpression(), ErrorCodes.FORG0001, "cannot construct " + Type.getTypeName(this.getItemType()) +
88-
" from '" + stringValue + "'");
84+
throw new XPathException(getExpression(), ErrorCodes.FORG0001,
85+
"Cannot construct " + Type.getTypeName(getItemType()) + " from '" + stringValue + "'");
8986
}
9087
}
9188

0 commit comments

Comments
 (0)