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(String msg,
CharSequence s) |
protected static ValidationFailure |
badDuration(String msg,
CharSequence s,
String errorCode) |
AtomicValue |
copyAsSubType(AtomicType typeLabel)
Create a copy of this atomic value, with a different type label
|
DecimalValue |
divide(DurationValue other)
Divide a duration by a another duration
|
boolean |
equals(Object other)
Test if the two durations are of equal length.
|
AtomicValue |
getComponent(int 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
|
CharSequence |
getPrimitiveStringValue()
Convert to string
|
BuiltInAtomicType |
getPrimitiveType()
Determine the primitive type of the value.
|
Comparable |
getSchemaComparable()
Get a Comparable value that implements the XML Schema ordering comparison semantics for this value.
|
static 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)
|
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(CharSequence s)
Static factory method: create a duration value from a supplied string, in
ISO 8601 format [-]PnYnMnDTnHnMnS
|
protected static ConversionResult |
makeDuration(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)
|
DurationValue |
normalizeDuration()
Deprecated.
since 9.0 - the method does nothing
|
protected void |
normalizeZeroDuration()
Ensure that a zero duration is considered positive
|
int |
signum()
Return the signum of the value
|
protected static int |
simpleInteger(String s)
Parse a simple unsigned integer
|
DurationValue |
subtract(DurationValue other)
Subtract two durations
|
asAtomic, checkPermittedContents, effectiveBooleanValue, getCanonicalLexicalRepresentation, getCardinality, getItemType, getStringValue, getStringValueCS, head, identityHashCode, isIdentical, isIdentical, isNaN, itemAt, iterate, iterator, process, setTypeLabel, toString
getLength, 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 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 microsecondsIllegalArgumentException
- 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.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(CharSequence s)
s
- a string in the lexical space of xs:durationValidationFailure
if the
supplied string is lexically invalid.protected static ConversionResult makeDuration(CharSequence s, boolean allowYM, boolean allowDT)
protected static ValidationFailure badDuration(String msg, CharSequence s)
protected static ValidationFailure badDuration(String msg, CharSequence s, String errorCode)
protected static int simpleInteger(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 DurationValue normalizeDuration()
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 BigDecimal getTotalSeconds()
public CharSequence getPrimitiveStringValue()
getPrimitiveStringValue
in class AtomicValue
public double getLengthInSeconds()
public AtomicValue getComponent(int component) throws XPathException
getComponent
in class AtomicValue
component
- identifies the required component, as a constant defined in class
AccessorFn
, for example AccessorFn.HOURS
XPathException
- 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(Object other)
equals
in class AtomicValue
other
- the other valueClassCastException
- if the other value is not an xs:duration or subtype thereofpublic 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 DecimalValue divide(DurationValue other) throws XPathException
other
- the duration to divide byXPathException
public Comparable getSchemaComparable()
getSchemaComparable
in interface AtomicSequence
getSchemaComparable
in class AtomicValue
public static Comparable getSchemaComparable(DurationValue value)
value
- the duration for which a comparison key is requiredCopyright (c) 2004-2014 Saxonica Limited. All rights reserved.