public class DurationValue extends AtomicValue implements AtomicMatchKey
| Modifier and Type | Class and Description |
|---|---|
static class |
DurationValue.DurationComparable
DurationValueComparable is a Comparable value that acts as a surrogate for a Duration,
having ordering rules that implement the XML Schema specification.
|
| Modifier and Type | Field and Description |
|---|---|
protected int |
_months |
protected int |
_nanoseconds |
protected boolean |
_negative |
protected long |
_seconds |
typeLabel| Modifier | Constructor and Description |
|---|---|
protected |
DurationValue()
Private constructor for internal use
|
|
DurationValue(boolean positive,
int years,
int months,
int days,
int hours,
int minutes,
long seconds,
int microseconds)
Constructor for xs:duration taking the components of the duration.
|
|
DurationValue(boolean positive,
int years,
int months,
int days,
int hours,
int minutes,
long seconds,
int microseconds,
AtomicType type)
Constructor for xs:duration taking the components of the duration, plus a user-specified
type which must be a subtype of xs:duration.
|
|
DurationValue(int years,
int months,
int days,
int hours,
int minutes,
long seconds,
int nanoseconds,
AtomicType type)
Constructor for xs:duration taking the components of the duration, plus a user-specified
type which must be a subtype of xs:duration.
|
| Modifier and Type | Method and Description |
|---|---|
DurationValue |
add(DurationValue other)
Add two durations
|
protected static ValidationFailure |
badDuration(java.lang.String msg,
UnicodeString s) |
protected static ValidationFailure |
badDuration(java.lang.String msg,
UnicodeString s,
java.lang.String errorCode) |
AtomicValue |
copyAsSubType(AtomicType typeLabel)
Create a copy of this atomic value, with a different type label
|
DurationValue |
divide(double factor)
Divide a duration by a number
|
BigDecimalValue |
divide(DurationValue other)
Divide a duration by a another duration
|
boolean |
equals(java.lang.Object other)
Test if the two durations are of equal length.
|
protected static void |
formatFractionalSeconds(UnicodeBuilder sb,
int seconds,
long nanosecs) |
AtomicValue |
getComponent(AccessorFn.Component component)
Get a component of the normalized value
|
int |
getDays()
Get the days component
|
int |
getHours()
Get the hours component
|
double |
getLengthInSeconds()
Get length of duration in seconds, assuming an average length of month.
|
int |
getMicroseconds()
Get the microseconds component
|
int |
getMinutes()
Get the minutes component
|
int |
getMonths()
Get the months component
|
int |
getNanoseconds()
Get the nanoseconds component
|
UnicodeString |
getPrimitiveStringValue()
Convert to string
|
BuiltInAtomicType |
getPrimitiveType()
Determine the primitive type of the value.
|
DurationValue.DurationComparable |
getSchemaComparable()
Get a Comparable value that implements the XML Schema ordering comparison semantics for this value.
|
int |
getSeconds()
Get the seconds component
|
int |
getTotalMonths()
Get the total number of months (ignoring the days/hours/minutes/seconds)
|
java.math.BigDecimal |
getTotalSeconds()
Get the total number of seconds (ignoring the years/months)
|
XPathComparable |
getXPathComparable(StringCollator collator,
int implicitTimezone)
Get an object value that implements the XPath equality and ordering comparison semantics for this value.
|
AtomicMatchKey |
getXPathMatchKey(StringCollator collator,
int implicitTimezone)
Get an object value that implements the XPath equality and ordering comparison semantics for this value.
|
int |
getYears()
Get the year component
|
int |
hashCode()
Returns a hash code value for the object.
|
static ConversionResult |
makeDuration(UnicodeString s)
Static factory method: create a duration value from a supplied string, in
ISO 8601 format [-]PnYnMnDTnHnMnS
|
protected static ConversionResult |
makeDuration(UnicodeString s,
boolean allowYM,
boolean allowDT) |
DurationValue |
multiply(java.math.BigDecimal factor)
Multiply a duration by a decimal
|
DurationValue |
multiply(double factor)
Multiply a duration by a double
|
DurationValue |
multiply(long factor)
Multiply a duration by an integer
|
DurationValue |
negate()
Negate a duration (same as subtracting from zero, but it preserves the type of the original duration)
|
protected void |
normalizeZeroDuration()
Ensure that a zero duration is considered positive
|
int |
signum()
Return the signum of the value
|
protected static int |
simpleInteger(java.lang.String s)
Parse a simple unsigned integer
|
DurationValue |
subtract(DurationValue other)
Subtract two durations
|
asAtomic, asMapKey, atomize, checkPermittedContents, checkValidInJavascript, effectiveBooleanValue, getCanonicalLexicalRepresentation, getCardinality, getGenre, getItemType, getLength, getUnicodeStringValue, getUType, head, identityHashCode, isIdentical, isIdentical, isNaN, isUntypedAtomic, itemAt, iterate, iterator, setTypeLabel, show, toShortString, toStringclone, finalize, getClass, notify, notifyAll, wait, wait, waitasAtomicgetStringValue, isStreamed, reduce, subsequenceasIterable, concatenate, containsNode, materializemakeRepeatableprotected boolean _negative
protected int _months
protected long _seconds
protected int _nanoseconds
protected DurationValue()
public DurationValue(boolean positive,
int years,
int months,
int days,
int hours,
int minutes,
long seconds,
int microseconds)
throws java.lang.IllegalArgumentException
Note: For historic reasons this constructor only supports microsecond precision. To get nanosecond
precision, use the constructor DurationValue(int, int, int, int, int, long, int, AtomicType).
positive - true if the duration is positive, false if negative. For a negative duration
the components are all supplied as positive integers (or zero).years - the number of yearsmonths - the number of monthsdays - the number of dayshours - the number of hoursminutes - the number of minutesseconds - the number of secondsmicroseconds - the number of microsecondsjava.lang.IllegalArgumentException - if the size of the duration exceeds implementation-defined
limits: specifically, if the total number of months exceeds 2^31, or if the total number
of seconds exceeds 2^63.public DurationValue(boolean positive,
int years,
int months,
int days,
int hours,
int minutes,
long seconds,
int microseconds,
AtomicType type)
Note: for historic reasons this constructor was written to expect microseconds rather than nanoseconds.
To supply nanoseconds, use the alternative constructor
DurationValue(int, int, int, int, int, long, int, AtomicType).
positive - true if the duration is positive, false if negative. For a negative duration
the components are all supplied as positive integers (or zero).years - the number of yearsmonths - the number of monthsdays - the number of dayshours - the number of hoursminutes - the number of minutesseconds - the number of seconds (long to allow copying)microseconds - the number of microsecondstype - the user-defined subtype of xs:duration. Note that this constructor cannot
be used to create an instance of xs:dayTimeDuration or xs:yearMonthDuration.java.lang.IllegalArgumentException - if the size of the duration exceeds implementation-defined
limits: specifically, if the total number of months exceeds 2^31, or if the total number
of seconds exceeds 2^63.public DurationValue(int years,
int months,
int days,
int hours,
int minutes,
long seconds,
int nanoseconds,
AtomicType type)
If the duration is positive, all the components must be supplied as positive (or zero) integers. If the duration is negative, all the components must be supplied as negative (or zero) integers.
years - the number of yearsmonths - the number of monthsdays - the number of dayshours - the number of hoursminutes - the number of minutesseconds - the number of seconds (long to allow copying)nanoseconds - the number of nanosecondstype - the user-defined subtype of xs:duration. Note that this constructor cannot
be used to create an instance of xs:dayTimeDuration or xs:yearMonthDuration.java.lang.IllegalArgumentException - if the size of the duration exceeds implementation-defined
limits: specifically, if the total number of months exceeds 2^31, or if the total number
of seconds exceeds 2^63.protected static void formatFractionalSeconds(UnicodeBuilder sb, int seconds, long nanosecs)
protected void normalizeZeroDuration()
public static ConversionResult makeDuration(UnicodeString s)
s - a string in the lexical space of xs:durationValidationFailure if the
supplied string is lexically invalid.protected static ConversionResult makeDuration(UnicodeString s, boolean allowYM, boolean allowDT)
protected static ValidationFailure badDuration(java.lang.String msg, UnicodeString s)
protected static ValidationFailure badDuration(java.lang.String msg, UnicodeString s, java.lang.String errorCode)
protected static int simpleInteger(java.lang.String s)
s - the string containing the sequence of digits. No sign or whitespace is allowed.public AtomicValue copyAsSubType(AtomicType typeLabel)
copyAsSubType in class AtomicValuetypeLabel - 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 AtomicValuepublic int signum()
public int getYears()
public int getMonths()
public int getDays()
public int getHours()
public int getMinutes()
public int getSeconds()
public int getMicroseconds()
public int getNanoseconds()
public int getTotalMonths()
public java.math.BigDecimal getTotalSeconds()
public UnicodeString getPrimitiveStringValue()
getPrimitiveStringValue in class AtomicValuepublic double getLengthInSeconds()
public AtomicValue getComponent(AccessorFn.Component component)
getComponent in class AtomicValuecomponent - the required componentpublic AtomicMatchKey getXPathMatchKey(StringCollator collator, int implicitTimezone)
getXPathMatchKey in class AtomicValuecollator - collation used for comparing string valuesimplicitTimezone - the XPath dynamic evaluation context, used in cases where the comparison is contextpublic XPathComparable getXPathComparable(StringCollator collator, int implicitTimezone) throws NoDynamicContextException
AtomicValuegetXPathComparable in class AtomicValuecollator - the collation to be used when comparing stringsimplicitTimezone - the implicit timezone in the dynamic context, used when comparing
dates/times with and without timezoneNoDynamicContextException - if the supplied implicit timezone is "NO_TIMEZONE" (meaning
unknown), and the implicit timezone is actually required because the value in question is a date/time
value with no timezone. This can cause a failure to evaluate expressions statically (because the implicit
timezone is not known statically), and it will then be caught, meaning that the expression has to be
evaluated dynamically.public boolean equals(java.lang.Object other)
equals in class AtomicValueother - the other valuejava.lang.ClassCastException - if the other value is not an xs:duration or subtype thereofpublic int hashCode()
AtomicValuehashCode in class AtomicValuepublic DurationValue add(DurationValue other) throws XPathException
other - the duration to be added to this oneXPathException - if an error is detectedpublic DurationValue subtract(DurationValue other) throws XPathException
other - the duration to be subtracted from this oneXPathException - if an error is detectedpublic DurationValue negate()
public DurationValue multiply(long factor) throws XPathException
factor - the number to multiply byXPathException - if an error is detectedpublic DurationValue multiply(double factor) throws XPathException
factor - the number to multiply byXPathException - if an error is detectedpublic DurationValue multiply(java.math.BigDecimal factor) throws XPathException
factor - the number to multiply byXPathException - if an error is detectedpublic DurationValue divide(double factor) throws XPathException
factor - the number to divide byXPathException - if an error is detectedpublic BigDecimalValue divide(DurationValue other) throws XPathException
other - the duration to divide byXPathException - if an error is detectedpublic DurationValue.DurationComparable getSchemaComparable()
Copyright (c) 2004-2022 Saxonica Limited. All rights reserved.