net.sf.saxon.value
Class IntegerValue
- Comparable, ConversionResult, GroundedValue, Item, PullEvent, Serializable, SequenceIterable, ValueRepresentation
public abstract class IntegerValue
This class represents the XPath built-in type xs:integer. It is used for all
subtypes of xs:integer, other than user-defined subtypes. There are two implementations
of IntegerValue:
Int64Value
, which accommodates values up to 2^63, and
BigIntegerValue
, which accommodates unlimited-length integers.
ceiling , compareTo , compareTo , equals , floor , getDecimalValue , getDoubleValue , getFloatValue , getXPathComparable , hashCode , isInteger , isWholeNumber , longValue , negate , parseNumber , promote , round , roundHalfToEven , signum , toString |
asAtomic , checkPermittedContents , convert , convert , convertPrimitive , copyAsSubType , effectiveBooleanValue , equals , getCardinality , getComponent , getItemType , getLength , getPrimitiveType , getSchemaComparable , getStringValue , getStringValueCS , getTypeLabel , getTypedValue , getXPathComparable , isNaN , itemAt , iterate , process , setTypeLabel , subsequence , toString |
asItem , asItem , asIterator , asValue , checkPermittedContents , convertJavaObjectToXPath , convertToJava , convertToJava , effectiveBooleanValue , equals , fromItem , getCanonicalLexicalRepresentation , getCardinality , getItemType , getIterator , getLength , getSchemaComparable , getStringValue , getStringValueCS , itemAt , iterate , iterate , makeQNameValue , process , reduce , stringToNumber , toString |
MAX_LONG
public static final Int64Value MAX_LONG
IntegerValue representing the maximum value for a long
MINUS_ONE
public static final Int64Value MINUS_ONE
IntegerValue representing the value -1
MIN_LONG
public static final Int64Value MIN_LONG
IntegerValue representing the minimum value for a long
PLUS_ONE
public static final Int64Value PLUS_ONE
IntegerValue representing the value +1
SMALL_INTEGERS
public static final Int64Value[] SMALL_INTEGERS
Array of small integer values
ZERO
public static final Int64Value ZERO
IntegerValue representing the value zero
asBigInteger
public abstract BigInteger asBigInteger()
Get the value as a BigInteger
- the value, as a BigInteger
checkBigRange
public static boolean checkBigRange(BigInteger big,
BuiltInAtomicType type)
Check that a BigInteger is within the required range for a given integer subtype.
This method is expensive, so it should not be used unless the BigInteger is outside the range of a long.
big
- the supplied BigIntegertype
- the derived type (a built-in restriction of xs:integer) to check the value against
- true if the value is within the range for the derived type
checkRange
public static boolean checkRange(long value,
BuiltInAtomicType type)
Check that a value is in range for the specified subtype of xs:integer
value
- the value to be checkedtype
- the required item type, a subtype of xs:integer
- true if successful, false if value is out of range for the subtype
convertToSubType
public abstract ValidationFailure convertToSubType(BuiltInAtomicType type,
boolean validate)
This class allows subtypes of xs:integer to be held, as well as xs:integer values.
This method sets the required type label. Note that this method modifies the value in situ.
type
- the subtype of integer requiredvalidate
- true if validation is required, false if the caller warrants that the value
is valid for the subtype
- null if the operation succeeds, or a ValidationException if the value is out of range
getPrimitiveType
public BuiltInAtomicType getPrimitiveType()
Determine the primitive type of the value. This delivers the same answer as
getItemType().getPrimitiveItemType(). The primitive types are
the 19 primitive types of XML Schema, plus xs:integer, xs:dayTimeDuration and xs:yearMonthDuration,
and xs:untypedAtomic. For external objects, the result is AnyAtomicType.
- getPrimitiveType in interface AtomicValue
isWholeNumber
public boolean isWholeNumber()
Determine whether the value is a whole number, that is, whether it compares
equal to some integer
- isWholeNumber in interface NumericValue
- always true for this implementation
makeIntegerValue
public static IntegerValue makeIntegerValue(BigInteger value)
Factory method: makes either an Int64Value or a BigIntegerValue depending on the value supplied
value
- the supplied integer value
- the value as a BigIntegerValue or Int64Value as appropriate
minus
public abstract IntegerValue minus(IntegerValue other)
Subtract another integer
other
- the other integer
- the result of the subtraction
plus
public abstract IntegerValue plus(IntegerValue other)
Add another integer
other
- the other integer
- the result of the addition
signum
protected static int signum(int i)
Get the signum of an int
- -1 if the integer is negative, 0 if it is zero, +1 if it is positive
stringToInteger
public static ConversionResult stringToInteger(CharSequence s)
Static factory method to convert strings to integers.
s
- CharSequence representing the string to be converted
- either an Int64Value or a BigIntegerValue representing the value of the String, or
a ValidationFailure encapsulating an Exception if the value cannot be converted.
times
public abstract IntegerValue times(IntegerValue other)
Multiply by another integer
other
- the other integer
- the result of the multiplication
validateAgainstSubType
public abstract ValidationFailure validateAgainstSubType(BuiltInAtomicType type)
This class allows subtypes of xs:integer to be held, as well as xs:integer values.
This method sets the required type label. Note that this method modifies the value in situ.
type
- the subtype of integer required
- null if the operation succeeds, or a ValidationException if the value is out of range