public final class BigDecimalValue extends DecimalValue
Modifier and Type | Class and Description |
---|---|
protected static class |
BigDecimalValue.DecimalComparable
A Comparable that performs comparison of a DecimalValue either with another
DecimalValue or with some other representation of an XPath numeric value
|
Modifier and Type | Field and Description |
---|---|
static java.math.BigDecimal |
BIG_DECIMAL_ONE_BILLION |
static java.math.BigDecimal |
BIG_DECIMAL_ONE_MILLION |
static int |
DIVIDE_PRECISION |
static java.math.BigDecimal |
MAX_INT |
static BigDecimalValue |
ONE |
static BigDecimalValue |
THREE |
static BigDecimalValue |
TWO |
static BigDecimalValue |
ZERO |
typeLabel
NaN_MATCH_KEY
Constructor and Description |
---|
BigDecimalValue(java.math.BigDecimal value)
Constructor supplying a BigDecimal
|
BigDecimalValue(double in)
Constructor supplying a double
|
BigDecimalValue(long in)
Constructor supplying a long integer
|
Modifier and Type | Method and Description |
---|---|
NumericValue |
abs()
Get the absolute value as defined by the XPath abs() function
|
int |
asSubscript()
Test whether a number is a possible subscript into a sequence, that is,
a whole number greater than zero and less than 2^31
|
static boolean |
castableAsDecimal(java.lang.CharSequence in)
Test whether a string is castable to a decimal value
|
NumericValue |
ceiling()
Implement the XPath ceiling() function
|
int |
compareTo(long other)
Compare the value to a long
|
int |
compareTo(NumericValue other)
Compare the value to another numeric value
|
AtomicValue |
copyAsSubType(AtomicType typeLabel)
Create a copy of this atomic value, with a different type label
|
static FastStringBuffer |
decimalToString(java.math.BigDecimal value,
FastStringBuffer fsb)
Convert a decimal value to a string, using the XPath rules for formatting
|
boolean |
effectiveBooleanValue()
Get the effective boolean value of the value.
|
NumericValue |
floor()
Implement the XPath floor() function
|
java.lang.CharSequence |
getCanonicalLexicalRepresentation()
Get the canonical lexical representation as defined in XML Schema.
|
java.math.BigDecimal |
getDecimalValue()
Get the value
|
double |
getDoubleValue()
Get the numeric value as a double
|
float |
getFloatValue()
Get the numeric value converted to a float
|
java.lang.CharSequence |
getPrimitiveStringValue()
Get the value as a String
|
BuiltInAtomicType |
getPrimitiveType()
Determine the primitive type of the value.
|
java.lang.Comparable |
getSchemaComparable()
Get an object that implements XML Schema comparison semantics
|
int |
hashCode()
Get the hashCode.
|
boolean |
isIdentical(AtomicValue v)
Determine whether two atomic values are identical, as determined by XML Schema rules.
|
boolean |
isWholeNumber()
Determine whether the value is a whole number, that is, whether it compares
equal to some integer
|
long |
longValue()
Return the numeric value as a Java long.
|
static ConversionResult |
makeDecimalValue(java.lang.CharSequence in,
boolean validate)
Factory method to construct a DecimalValue from a string
|
NumericValue |
negate()
Negate the value
|
static BigDecimalValue |
parse(java.lang.CharSequence in)
Factory method to construct a DecimalValue from a string, throwing an unchecked exception
if the value is invalid
|
NumericValue |
round(int scale)
Implement the XPath round() function
|
NumericValue |
roundHalfToEven(int scale)
Implement the XPath round-half-to-even() function
|
int |
signum()
Determine whether the value is negative, zero, or positive
|
equals, getXPathComparable, isInteger, isNegativeZero, parseNumber, toString
asAtomic, asMapKey, atomize, checkPermittedContents, checkValidInJavascript, getCardinality, getComponent, getGenre, getItemType, getLength, getStringValue, getStringValueCS, getUType, head, identityHashCode, isIdentical, isNaN, itemAt, iterate, iterator, process, setTypeLabel
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
asAtomic
isStreamed, reduce, subsequence, toGroundedValue, toShortString
asIterable, materialize
makeRepeatable
public static final int DIVIDE_PRECISION
public static final java.math.BigDecimal BIG_DECIMAL_ONE_MILLION
public static final java.math.BigDecimal BIG_DECIMAL_ONE_BILLION
public static final BigDecimalValue ZERO
public static final BigDecimalValue ONE
public static final BigDecimalValue TWO
public static final BigDecimalValue THREE
public static final java.math.BigDecimal MAX_INT
public BigDecimalValue(java.math.BigDecimal value)
value
- the value of the DecimalValuepublic BigDecimalValue(double in) throws ValidationException
in
- the value of the DecimalValueValidationException
- if the supplied value cannot be converted, typically because it is INF or NaN.public BigDecimalValue(long in)
in
- the value of the DecimalValuepublic static ConversionResult makeDecimalValue(java.lang.CharSequence in, boolean validate)
in
- the value of the DecimalValuevalidate
- true if validation is required; false if the caller knows that the value is validpublic static BigDecimalValue parse(java.lang.CharSequence in) throws java.lang.NumberFormatException
in
- the lexical representation of the DecimalValuejava.lang.NumberFormatException
- if the value is invalidpublic static boolean castableAsDecimal(java.lang.CharSequence in)
in
- the string to be testedpublic AtomicValue copyAsSubType(AtomicType typeLabel)
copyAsSubType
in class AtomicValue
typeLabel
- the type label of the new copy. The caller is responsible for checking that
the value actually conforms to this type.public BuiltInAtomicType getPrimitiveType()
getPrimitiveType
in class AtomicValue
public double getDoubleValue()
getDoubleValue
in class NumericValue
public float getFloatValue()
getFloatValue
in class NumericValue
public long longValue() throws XPathException
longValue
in class NumericValue
XPathException
- if the value cannot be convertedpublic java.math.BigDecimal getDecimalValue()
getDecimalValue
in class NumericValue
public int hashCode()
hashCode
in class NumericValue
NumericValue.hashCode()
public boolean effectiveBooleanValue()
NumericValue
effectiveBooleanValue
in interface GroundedValue<AtomicValue>
effectiveBooleanValue
in class NumericValue
public java.lang.CharSequence getCanonicalLexicalRepresentation()
getCanonicalLexicalRepresentation
in interface AtomicSequence
getCanonicalLexicalRepresentation
in class AtomicValue
public java.lang.CharSequence getPrimitiveStringValue()
getPrimitiveStringValue
in class AtomicValue
public static FastStringBuffer decimalToString(java.math.BigDecimal value, FastStringBuffer fsb)
value
- the decimal value to be convertedfsb
- the FastStringBuffer to which the value is to be appendedpublic NumericValue negate()
negate
in class NumericValue
public NumericValue floor()
floor
in class NumericValue
public NumericValue ceiling()
ceiling
in class NumericValue
public NumericValue round(int scale)
round
in class NumericValue
scale
- the number of decimal places required in the result (supply 0 for rounding to an integer)public NumericValue roundHalfToEven(int scale)
roundHalfToEven
in class NumericValue
scale
- the decimal position for rounding: e.g. 2 rounds to a
multiple of 0.01, while -2 rounds to a multiple of 100public int signum()
signum
in class NumericValue
public boolean isWholeNumber()
isWholeNumber
in class NumericValue
public int asSubscript()
asSubscript
in class NumericValue
public NumericValue abs()
abs
in class NumericValue
public int compareTo(NumericValue other)
compareTo
in interface java.lang.Comparable<NumericValue>
compareTo
in class NumericValue
other
- The other numeric valuepublic int compareTo(long other)
compareTo
in class NumericValue
other
- the value to be compared withpublic java.lang.Comparable getSchemaComparable()
getSchemaComparable
in interface AtomicSequence
getSchemaComparable
in class AtomicValue
public boolean isIdentical(AtomicValue v)
Note that even this check ignores the type annotation of the value. The integer 3 and the short 3 are considered identical, even though they are not fully interchangeable. "Identical" means the same point in the value space, regardless of type annotation.
NaN is identical to itself.
isIdentical
in class AtomicValue
v
- the other value to be compared with this oneCopyright (c) 2004-2020 Saxonica Limited. All rights reserved.