Package net.sf.saxon.value
Class IntegerValue
- java.lang.Object
-
- net.sf.saxon.value.AtomicValue
-
- net.sf.saxon.value.NumericValue
-
- net.sf.saxon.value.DecimalValue
-
- net.sf.saxon.value.IntegerValue
-
- All Implemented Interfaces:
java.lang.Comparable<NumericValue>,java.lang.Iterable<AtomicValue>,AtomicMatchKey,AtomicSequence,GroundedValue,IdentityComparable,Item,Sequence,ConversionResult
- Direct Known Subclasses:
BigIntegerValue,Int64Value
public abstract class IntegerValue extends DecimalValue
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, andBigIntegerValue, which accommodates unlimited-length integers.- Since:
- 9.8: changed in 9.8 to make this class a subclass of the new abstract class DecimalValue, to better reflect the XDM type hierarchy
-
-
Field Summary
-
Fields inherited from class net.sf.saxon.value.AtomicValue
typeLabel
-
Fields inherited from interface net.sf.saxon.expr.sort.AtomicMatchKey
NaN_MATCH_KEY
-
-
Constructor Summary
Constructors Constructor Description IntegerValue()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract java.math.BigIntegerasBigInteger()Get the value as a BigIntegerstatic ValidationFailurecastableAsInteger(java.lang.CharSequence input)Determine whether a string is castable as an integerstatic booleancheckBigRange(java.math.BigInteger big, BuiltInAtomicType type)Check that a BigInteger is within the required range for a given integer subtype.static booleancheckRange(long value, BuiltInAtomicType type)Check that a value is in range for the specified subtype of xs:integerabstract ValidationFailureconvertToSubType(BuiltInAtomicType type, boolean validate)This class allows subtypes of xs:integer to be held, as well as xs:integer values.abstract NumericValuediv(IntegerValue other)Divide by another integerNumericValuediv(IntegerValue other, Location locator)Divide by another integer, providing location information for any exceptionabstract java.math.BigDecimalgetDecimalValue()Get the numeric value converted to a decimalstatic IntegerValuegetMaxInclusive(BuiltInAtomicType type)Get the maxInclusive facet for a built-in integer subtypestatic IntegerValuegetMinInclusive(BuiltInAtomicType type)Get the minInclusive facet for a built-in integer subtypeBuiltInAtomicTypegetPrimitiveType()Determine the primitive type of the value.abstract IntegerValueidiv(IntegerValue other)Integer divide by another integerIntegerValueidiv(IntegerValue other, Location locator)Integer divide by another integer, providing location information for any exceptionbooleanisIdentical(AtomicValue v)Determine whether two atomic values are identical, as determined by XML Schema rules.booleanisWholeNumber()Determine whether the value is a whole number, that is, whether it compares equal to some integerstatic ConversionResultmakeIntegerValue(double value)Convert a double to an integerstatic IntegerValuemakeIntegerValue(java.math.BigInteger value)Factory method: makes either an Int64Value or a BigIntegerValue depending on the value suppliedstatic ConversionResultmakeIntegerValue(DoubleValue doubleValue)Convert a double to an integerabstract IntegerValueminus(IntegerValue other)Subtract another integerabstract IntegerValuemod(IntegerValue other)Take modulo another integerIntegerValuemod(IntegerValue other, Location locator)Take modulo another integer, providing location information for any exceptionabstract IntegerValueplus(IntegerValue other)Add another integerprotected static intsignum(int i)Get the signum of an intstatic ConversionResultstringToInteger(java.lang.CharSequence s)Static factory method to convert strings to integers.abstract IntegerValuetimes(IntegerValue other)Multiply by another integerabstract ValidationFailurevalidateAgainstSubType(BuiltInAtomicType type)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
abs, asSubscript, ceiling, compareTo, compareTo, effectiveBooleanValue, equals, floor, getDoubleValue, getFloatValue, getXPathComparable, hashCode, isInteger, isNegativeZero, longValue, negate, parseNumber, round, roundHalfToEven, signum, toString
-
Methods inherited from class net.sf.saxon.value.AtomicValue
asAtomic, asMapKey, atomize, checkPermittedContents, checkValidInJavascript, copyAsSubType, getCanonicalLexicalRepresentation, getCardinality, getComponent, getGenre, getItemType, getLength, getPrimitiveStringValue, getSchemaComparable, getStringValue, getStringValueCS, getUType, head, identityHashCode, isIdentical, isNaN, itemAt, iterate, iterator, setTypeLabel
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.sf.saxon.expr.sort.AtomicMatchKey
asAtomic
-
Methods inherited from interface net.sf.saxon.om.GroundedValue
asIterable, concatenate, containsNode, materialize
-
Methods inherited from interface net.sf.saxon.om.Item
isStreamed, reduce, subsequence, toShortString
-
Methods inherited from interface net.sf.saxon.om.Sequence
makeRepeatable
-
-
-
-
Method Detail
-
makeIntegerValue
public static IntegerValue makeIntegerValue(java.math.BigInteger value)
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
-
makeIntegerValue
public static ConversionResult makeIntegerValue(double value)
Convert a double to an integer- Parameters:
value- the double to be converted- Returns:
- the result of the conversion, or the validation failure if the input is NaN or infinity
-
makeIntegerValue
public static ConversionResult makeIntegerValue(DoubleValue doubleValue)
Convert a double to an integer- Parameters:
doubleValue- the double to be converted- Returns:
- the result of the conversion, or the validation failure if the input is NaN or infinity
-
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.- 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
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.- Parameters:
type- the subtype of integer required- Returns:
- null if the operation succeeds, or a ValidationException if the value is out of range
-
checkRange
public static boolean checkRange(long value, BuiltInAtomicType type)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
-
getMinInclusive
public static IntegerValue getMinInclusive(BuiltInAtomicType type)
Get the minInclusive facet for a built-in integer subtype- Parameters:
type- the built-in type, which must be derived from xs:integer- Returns:
- the value of the minInclusive facet if there is a lower limit, or null if not
-
getMaxInclusive
public static IntegerValue getMaxInclusive(BuiltInAtomicType type)
Get the maxInclusive facet for a built-in integer subtype- Parameters:
type- the built-in type, which must be derived from xs:integer- Returns:
- the value of the minInclusive facet if there is a lower limit, or null if not
-
checkBigRange
public static boolean checkBigRange(java.math.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.- 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
public static ConversionResult stringToInteger(java.lang.CharSequence s)
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.
-
castableAsInteger
public static ValidationFailure castableAsInteger(java.lang.CharSequence input)
Determine whether a string is castable as an integer- Parameters:
input- the string to be tested- Returns:
- null if the string is castable to an integer, or a validation failure otherwise
-
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.- Specified by:
getPrimitiveTypein classAtomicValue- Returns:
- the primitive type
-
getDecimalValue
public abstract java.math.BigDecimal getDecimalValue()
Get the numeric value converted to a decimal- Specified by:
getDecimalValuein classNumericValue- Returns:
- a decimal representing this numeric value;
-
isWholeNumber
public boolean isWholeNumber()
Determine whether the value is a whole number, that is, whether it compares equal to some integer- Specified by:
isWholeNumberin classNumericValue- Returns:
- always true for this implementation
-
plus
public abstract IntegerValue plus(IntegerValue other)
Add another integer- Parameters:
other- the other integer- Returns:
- the result of the addition
-
minus
public abstract IntegerValue minus(IntegerValue other)
Subtract another integer- Parameters:
other- the other integer- Returns:
- the result of the subtraction
-
times
public abstract IntegerValue times(IntegerValue other)
Multiply by another integer- Parameters:
other- the other integer- Returns:
- the result of the multiplication
-
div
public abstract NumericValue div(IntegerValue other) throws XPathException
Divide by another integer- Parameters:
other- the other integer- Returns:
- the result of the division
- Throws:
XPathException- if the other integer is zero
-
div
public NumericValue div(IntegerValue other, Location locator) throws XPathException
Divide by another integer, providing location information for any exception- Parameters:
other- the other integerlocator- the location of the expression, for use in diagnostics- Returns:
- the result of the division
- Throws:
XPathException- if the other integer is zero
-
mod
public abstract IntegerValue mod(IntegerValue other) throws XPathException
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
-
mod
public IntegerValue mod(IntegerValue other, Location locator) throws XPathException
Take modulo another integer, providing location information for any exception- Parameters:
other- the other integerlocator- the location of the expression, for use in diagnostics- Returns:
- the result of the division
- Throws:
XPathException- if the other integer is zero
-
idiv
public abstract IntegerValue idiv(IntegerValue other) throws XPathException
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
-
idiv
public IntegerValue idiv(IntegerValue other, Location locator) throws XPathException
Integer divide by another integer, providing location information for any exception- Parameters:
other- the other integerlocator- the location of the expression, for use in diagnostics- Returns:
- the result of the division
- Throws:
XPathException- if the other integer is zero
-
asBigInteger
public abstract java.math.BigInteger 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
-
isIdentical
public boolean isIdentical(AtomicValue v)
Determine whether two atomic values are identical, as determined by XML Schema rules. This is a stronger test than equality (even schema-equality); for example two dateTime values are not identical unless they are in the same timezone.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.
- Overrides:
isIdenticalin classAtomicValue- Parameters:
v- the other value to be compared with this one- Returns:
- true if the two values are identical, false otherwise.
-
-