net.sf.saxon.value
public class DurationValue extends AtomicValue
Field Summary | |
---|---|
protected int | microseconds |
protected int | months |
protected boolean | negative |
protected long | seconds |
Constructor Summary | |
---|---|
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. |
Method Summary | |
---|---|
DurationValue | add(DurationValue other)
Add two durations
|
protected static ValidationFailure | badDuration(String msg, CharSequence s) |
ConversionResult | convertPrimitive(BuiltInAtomicType requiredType, boolean validate, XPathContext context)
Convert to target data type
|
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
|
Object | getXPathComparable(boolean ordered, StringCollator collator, XPathContext context)
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
|
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()
Normalize the duration, so that months<12, hours<24, minutes<60, seconds<60.
|
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
|
Parameters: 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 years months the number of months days the number of days hours the number of hours minutes the number of minutes seconds the number of seconds microseconds the number of microseconds
Throws: 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.
Parameters: 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 years months the number of months days the number of days hours the number of hours minutes the number of minutes seconds the number of seconds (long to allow copying) microseconds the number of microseconds type the user-defined subtype of xs:duration. Note that this constructor cannot be used to create an instance of xs:dayTimeDuration or xs:yearMonthDuration.
Throws: 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.
Parameters: other the duration to be added to this one
Returns: the sum of the two durations
Parameters: requiredType an integer identifying the required atomic type validate if set to false, the caller asserts that the value is known to be valid context the XPath dynamic context
Returns: an AtomicValue, a value of the required type; or a ValidationFailure if the value cannot be converted.
Parameters: typeLabel the type label of the new copy. The caller is responsible for checking that the value actually conforms to this type.
Parameters: other the duration to divide by
Returns: the result of the division
Throws: ClassCastException if the other value is not an xs:duration or subtype thereof
Returns: the number of days in the normalized duration; always positive
Returns: the number of hours in the normalized duration; always positive
Returns: the duration in seconds, as a double
Returns: the number of microseconds in the normalized duration; always positive
Returns: the number of minutes in the normalized duration; always positive
Returns: the number of months in the normalized duration; always positive
Returns: ISO 8601 representation.
Returns: a suitable Comparable
Parameters: value the duration for which a comparison key is required
Returns: a suitable Comparable
Returns: the number of whole seconds in the normalized duration; always positive
Parameters: 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 values context the XPath dynamic evaluation context, used in cases where the comparison is context sensitive @return an Object whose equals() and hashCode() methods implement the XPath comparison semantics with respect to this atomic value. If ordered is specified, the result will either be null if no ordering is defined, or will be a Comparable
Returns: the number of years in the normalized duration; always positive
Parameters: s a string in the lexical space of xs:duration
Returns: the constructed xs:duration value, or a ValidationFailure if the supplied string is lexically invalid.
Parameters: factor the number to multiply by
Returns: the result of the multiplication
Returns: the original duration with its sign reversed, retaining its type
Deprecated: since 9.0 - the method does nothing
Normalize the duration, so that months<12, hours<24, minutes<60, seconds<60. Since durations are now always normalized, this method has become a no-op, but is retained for backwards compatibilityReturns: the duration unchanged
Returns: -1 if the duration is negative, zero if it is zero-length, +1 if it is positive
Parameters: s the string containing the sequence of digits. No sign or whitespace is allowed.
Returns: the integer. Return -1 if the string is not a sequence of digits or exceeds 2^31
Parameters: other the duration to be subtracted from this one
Returns: the difference of the two durations