public class DurationValue extends AtomicValue implements AtomicMatchKey
Modifier and Type | Field and Description |
---|---|
protected int |
microseconds |
protected int |
months |
protected boolean |
negative |
protected long |
seconds |
NaN_MATCH_KEY, 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.
|
Modifier and Type | Method and Description |
---|---|
DurationValue |
add(DurationValue other)
Add two durations
|
protected static ValidationFailure |
badDuration(java.lang.String msg,
java.lang.CharSequence s) |
protected static ValidationFailure |
badDuration(java.lang.String msg,
java.lang.CharSequence s,
java.lang.String errorCode) |
AtomicValue |
copyAsSubType(AtomicType typeLabel)
Create a copy of this atomic value, with a different type label
|
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.
|
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
|
java.lang.CharSequence |
getPrimitiveStringValue()
Convert to string
|
BuiltInAtomicType |
getPrimitiveType()
Determine the primitive type of the value.
|
java.lang.Comparable |
getSchemaComparable()
Get a Comparable value that implements the XML Schema ordering comparison semantics for this value.
|
static java.lang.Comparable |
getSchemaComparable(DurationValue value)
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)
|
AtomicMatchKey |
getXPathComparable(boolean ordered,
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() |
static ConversionResult |
makeDuration(java.lang.CharSequence s)
Static factory method: create a duration value from a supplied string, in
ISO 8601 format [-]PnYnMnDTnHnMnS
|
protected static ConversionResult |
makeDuration(java.lang.CharSequence s,
boolean allowYM,
boolean allowDT) |
DurationValue |
multiply(double factor)
Multiply a duration by a number
|
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, getItemType, getStringValue, getStringValueCS, getUType, head, identityHashCode, isIdentical, isIdentical, isNaN, itemAt, iterate, iterator, process, setTypeLabel, toString
getLength, isStreamed, reduce, subsequence
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
asAtomic
getLength
reduce, subsequence
protected boolean negative
protected int months
protected long seconds
protected int microseconds
protected DurationValue()
public DurationValue(boolean positive, int years, int months, int days, int hours, int minutes, long seconds, int microseconds) throws java.lang.IllegalArgumentException
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)
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.protected void normalizeZeroDuration()
public static ConversionResult makeDuration(java.lang.CharSequence s)
s
- a string in the lexical space of xs:durationValidationFailure
if the
supplied string is lexically invalid.protected static ConversionResult makeDuration(java.lang.CharSequence s, boolean allowYM, boolean allowDT)
protected static ValidationFailure badDuration(java.lang.String msg, java.lang.CharSequence s)
protected static ValidationFailure badDuration(java.lang.String msg, java.lang.CharSequence 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 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 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 getTotalMonths()
public java.math.BigDecimal getTotalSeconds()
public java.lang.CharSequence getPrimitiveStringValue()
getPrimitiveStringValue
in class AtomicValue
public double getLengthInSeconds()
public AtomicValue getComponent(AccessorFn.Component component) throws XPathException
getComponent
in class AtomicValue
component
- the required componentXPathException
- if a dynamic error occurspublic AtomicMatchKey getXPathComparable(boolean ordered, StringCollator collator, int implicitTimezone)
getXPathComparable
in class AtomicValue
ordered
- true if an ordered comparison is required. In this case the result is null if the
type is unordered; in other cases the returned value will be a Comparable.collator
- collation used for comparing string valuesimplicitTimezone
- the XPath dynamic evaluation context, used in cases where the comparison is contextpublic boolean equals(java.lang.Object other)
equals
in class AtomicValue
other
- the other valuejava.lang.ClassCastException
- if the other value is not an xs:duration or subtype thereofpublic int hashCode()
hashCode
in class java.lang.Object
public DurationValue add(DurationValue other) throws XPathException
other
- the duration to be added to this oneXPathException
public DurationValue subtract(DurationValue other) throws XPathException
other
- the duration to be subtracted from this oneXPathException
public DurationValue negate()
public DurationValue multiply(double factor) throws XPathException
factor
- the number to multiply byXPathException
public BigDecimalValue divide(DurationValue other) throws XPathException
other
- the duration to divide byXPathException
public java.lang.Comparable getSchemaComparable()
getSchemaComparable
in interface AtomicSequence
getSchemaComparable
in class AtomicValue
public static java.lang.Comparable getSchemaComparable(DurationValue value)
value
- the duration for which a comparison key is requiredCopyright (c) 2004-2018 Saxonica Limited. All rights reserved.