public final class DecimalValue extends NumericValue
Modifier and Type | Class and Description |
---|---|
protected static class |
DecimalValue.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 BigDecimal |
BIG_DECIMAL_ONE_MILLION |
static int |
DIVIDE_PRECISION |
static DecimalValue |
ONE |
static DecimalValue |
THREE |
static DecimalValue |
THREE_POINT_ONE |
static DecimalValue |
TWO |
static DecimalValue |
ZERO |
NaN_MATCH_KEY, typeLabel
Constructor and Description |
---|
DecimalValue(BigDecimal value)
Constructor supplying a BigDecimal
|
DecimalValue(double in)
Constructor supplying a double
|
DecimalValue(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
|
static boolean |
castableAsDecimal(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(Object other)
Compare the value to another numeric value
|
AtomicValue |
copyAsSubType(AtomicType typeLabel)
Create a copy of this atomic value, with a difNferent type label
|
static FastStringBuffer |
decimalToString(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
|
CharSequence |
getCanonicalLexicalRepresentation()
Get the canonical lexical representation as defined in XML Schema.
|
BigDecimal |
getDecimalValue()
Get the value
|
double |
getDoubleValue()
Get the numeric value as a double
|
float |
getFloatValue()
Get the numeric value converted to a float
|
CharSequence |
getPrimitiveStringValue()
Get the value as a String
|
BuiltInAtomicType |
getPrimitiveType()
Determine the primitive type of the value.
|
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(CharSequence in,
boolean validate)
Factory method to construct a DecimalValue from a string
|
NumericValue |
negate()
Negate the value
|
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, checkPermittedContents, getCardinality, getComponent, getItemType, getStringValue, getStringValueCS, head, identityHashCode, isIdentical, isNaN, itemAt, iterate, iterator, process, setTypeLabel
getLength, reduce, subsequence
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
asAtomic
getLength
reduce, subsequence
public static final int DIVIDE_PRECISION
public static final BigDecimal BIG_DECIMAL_ONE_MILLION
public static final DecimalValue ZERO
public static final DecimalValue ONE
public static final DecimalValue TWO
public static final DecimalValue THREE
public static final DecimalValue THREE_POINT_ONE
public DecimalValue(BigDecimal value)
value
- the value of the DecimalValuepublic DecimalValue(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 DecimalValue(long in)
in
- the value of the DecimalValuepublic static ConversionResult makeDecimalValue(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 boolean castableAsDecimal(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 BigDecimal getDecimalValue()
getDecimalValue
in class NumericValue
public int hashCode()
hashCode
in class NumericValue
NumericValue.hashCode()
public boolean effectiveBooleanValue()
AtomicValue
effectiveBooleanValue
in interface GroundedValue
effectiveBooleanValue
in class AtomicValue
public CharSequence getCanonicalLexicalRepresentation()
getCanonicalLexicalRepresentation
in interface AtomicSequence
getCanonicalLexicalRepresentation
in class AtomicValue
public CharSequence getPrimitiveStringValue()
getPrimitiveStringValue
in class AtomicValue
public static FastStringBuffer decimalToString(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 NumericValue abs()
abs
in class NumericValue
public int compareTo(Object other)
compareTo
in interface Comparable
compareTo
in class NumericValue
other
- The other numeric valuepublic int compareTo(long other)
compareTo
in class NumericValue
other
- the value to be compared withpublic 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-2014 Saxonica Limited. All rights reserved.