Package net.sf.saxon.value
Class IntegerValue
java.lang.Object
net.sf.saxon.value.Value
net.sf.saxon.value.AtomicValue
net.sf.saxon.value.NumericValue
net.sf.saxon.value.IntegerValue
- All Implemented Interfaces:
Serializable
,Comparable
,PullEvent
,SequenceIterable
,GroundedValue
,Item
,ValueRepresentation
,ConversionResult
- Direct Known Subclasses:
BigIntegerValue
,Int64Value
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.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Int64Value
IntegerValue representing the maximum value for a longstatic final Int64Value
IntegerValue representing the minimum value for a longstatic final Int64Value
IntegerValue representing the value -1static final Int64Value
IntegerValue representing the value +1static final Int64Value[]
Array of small integer valuesstatic final Int64Value
IntegerValue representing the value zeroFields inherited from class net.sf.saxon.value.AtomicValue
typeLabel
Fields inherited from class net.sf.saxon.value.Value
EMPTY_CLASS_ARRAY, INDETERMINATE_ORDERING
Fields inherited from interface net.sf.saxon.om.ValueRepresentation
EMPTY_VALUE_ARRAY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract BigInteger
Get the value as a BigIntegerstatic boolean
checkBigRange
(BigInteger big, BuiltInAtomicType type) Check that a BigInteger is within the required range for a given integer subtype.static boolean
checkRange
(long value, BuiltInAtomicType type) Check that a value is in range for the specified subtype of xs:integerabstract ValidationFailure
convertToSubType
(BuiltInAtomicType type, boolean validate) This class allows subtypes of xs:integer to be held, as well as xs:integer values.abstract NumericValue
div
(IntegerValue other) Divide by another integerDetermine the primitive type of the value.abstract IntegerValue
idiv
(IntegerValue other) Integer divide by another integerboolean
Determine whether the value is a whole number, that is, whether it compares equal to some integerstatic IntegerValue
makeIntegerValue
(BigInteger value) Factory method: makes either an Int64Value or a BigIntegerValue depending on the value suppliedabstract IntegerValue
minus
(IntegerValue other) Subtract another integerabstract IntegerValue
mod
(IntegerValue other) Take modulo another integerabstract IntegerValue
plus
(IntegerValue other) Add another integerprotected static int
signum
(int i) Get the signum of an intstatic ConversionResult
Static factory method to convert strings to integers.abstract IntegerValue
times
(IntegerValue other) Multiply by another integerabstract ValidationFailure
This class allows subtypes of xs:integer to be held, as well as xs:integer values.Methods inherited from class net.sf.saxon.value.NumericValue
ceiling, compareTo, compareTo, equals, floor, getDecimalValue, getDoubleValue, getFloatValue, getXPathComparable, hashCode, isInteger, longValue, negate, parseNumber, promote, round, roundHalfToEven, signum, toString
Methods inherited from class net.sf.saxon.value.AtomicValue
asAtomic, checkPermittedContents, convert, convert, convertPrimitive, copyAsSubType, effectiveBooleanValue, getCardinality, getComponent, getItemType, getLength, getSchemaComparable, getStringValue, getStringValueCS, getTypedValue, getTypeLabel, isNaN, itemAt, iterate, process, setTypeLabel, subsequence
Methods inherited from class net.sf.saxon.value.Value
asItem, asItem, asIterator, asValue, convertToJava, fromItem, getCanonicalLexicalRepresentation, getIterator, iterate, makeQNameValue, reduce, stringToNumber
-
Field Details
-
MINUS_ONE
IntegerValue representing the value -1 -
ZERO
IntegerValue representing the value zero -
PLUS_ONE
IntegerValue representing the value +1 -
SMALL_INTEGERS
Array of small integer values -
MAX_LONG
IntegerValue representing the maximum value for a long -
MIN_LONG
IntegerValue representing the minimum value for a long
-
-
Constructor Details
-
IntegerValue
public IntegerValue()
-
-
Method Details
-
makeIntegerValue
Factory method: makes either an Int64Value or a BigIntegerValue depending on the value supplied- Parameters:
value
- the supplied integer value- Returns:
- the value as a BigIntegerValue or Int64Value as appropriate
-
convertToSubType
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.- Parameters:
type
- the subtype of integer requiredvalidate
- true if validation is required, false if the caller warrants that the value is valid for the subtype- Returns:
- null if the operation succeeds, or a ValidationException if the value is out of range
-
validateAgainstSubType
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.- Parameters:
type
- the subtype of integer required- Returns:
- null if the operation succeeds, or a ValidationException if the value is out of range
-
checkRange
Check that a value is in range for the specified subtype of xs:integer- Parameters:
value
- the value to be checkedtype
- the required item type, a subtype of xs:integer- Returns:
- true if successful, false if value is out of range for the subtype
-
checkBigRange
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.- Parameters:
big
- the supplied BigIntegertype
- the derived type (a built-in restriction of xs:integer) to check the value against- Returns:
- true if the value is within the range for the derived type
-
stringToInteger
Static factory method to convert strings to integers.- Parameters:
s
- CharSequence representing the string to be converted- Returns:
- either an Int64Value or a BigIntegerValue representing the value of the String, or a ValidationFailure encapsulating an Exception if the value cannot be converted.
-
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.- Specified by:
getPrimitiveType
in classAtomicValue
- Returns:
- the primitive type
-
isWholeNumber
public boolean isWholeNumber()Determine whether the value is a whole number, that is, whether it compares equal to some integer- Specified by:
isWholeNumber
in classNumericValue
- Returns:
- always true for this implementation
-
plus
Add another integer- Parameters:
other
- the other integer- Returns:
- the result of the addition
-
minus
Subtract another integer- Parameters:
other
- the other integer- Returns:
- the result of the subtraction
-
times
Multiply by another integer- Parameters:
other
- the other integer- Returns:
- the result of the multiplication
-
div
Divide by another integer- Parameters:
other
- the other integer- Returns:
- the result of the division
- Throws:
XPathException
- if the other integer is zero
-
mod
Take modulo another integer- Parameters:
other
- the other integer- Returns:
- the result of the modulo operation (the remainder)
- Throws:
XPathException
- if the other integer is zero
-
idiv
Integer divide by another integer- Parameters:
other
- the other integer- Returns:
- the result of the integer division
- Throws:
XPathException
- if the other integer is zero
-
asBigInteger
Get the value as a BigInteger- Returns:
- the value, as a BigInteger
-
signum
protected static int signum(int i) Get the signum of an int- Parameters:
i
- the int- Returns:
- -1 if the integer is negative, 0 if it is zero, +1 if it is positive
-