net.sf.saxon.value

Class DurationValue

public class DurationValue extends AtomicValue

A value of type xs:duration
Field Summary
protected intdays
protected inthours
protected intmicroseconds
protected intminutes
protected intmonths
protected booleannegative
protected intseconds
protected intyears
Constructor Summary
protected DurationValue()
Private constructor for internal use
DurationValue(boolean positive, int years, int months, int days, int hours, int minutes, int seconds, int microseconds)
DurationValue(CharSequence s)
Constructor: create a duration value from a supplied string, in ISO 8601 format [-]PnYnMnDTnHnMnS
Method Summary
DurationValueadd(DurationValue other, XPathContext context)
Add two durations
protected voidbadDuration(String msg, CharSequence s)
AtomicValueconvertPrimitive(BuiltInAtomicType requiredType, boolean validate, XPathContext context)
Convert to target data type
ObjectconvertToJava(Class target, XPathContext context)
Convert to Java object (for passing to external functions)
DecimalValuedivide(DurationValue other, XPathContext context)
Divide a duration by a another duration
booleanequals(Object other)
Test if the two durations are of equal length.
AtomicValuegetComponent(int component)
Get a component of the value
ItemTypegetItemType(TypeHierarchy th)
Determine the data type of the exprssion
doublegetLengthInSeconds()
Get length of duration in seconds, assuming an average length of month.
StringgetStringValue()
Convert the value to a string, using the serialization rules.
CharSequencegetStringValueCS()
Convert to string
inthashCode()
DurationValuemultiply(double factor, XPathContext context)
Multiply a duration by a number
DurationValuenormalizeDuration()
Normalize the duration, so that months<12, hours<24, minutes<60, seconds<60.
protected voidnormalizeZeroDuration()
booleanschemaEquals(Value obj)
Compare two values for equality.
DurationValuesubtract(DurationValue other, XPathContext context)
Subtract two durations

Field Detail

days

protected int days

hours

protected int hours

microseconds

protected int microseconds

minutes

protected int minutes

months

protected int months

negative

protected boolean negative

seconds

protected int seconds

years

protected int years

Constructor Detail

DurationValue

protected DurationValue()
Private constructor for internal use

DurationValue

public DurationValue(boolean positive, int years, int months, int days, int hours, int minutes, int seconds, int microseconds)

DurationValue

public DurationValue(CharSequence s)
Constructor: create a duration value from a supplied string, in ISO 8601 format [-]PnYnMnDTnHnMnS

Method Detail

add

public DurationValue add(DurationValue other, XPathContext context)
Add two durations

badDuration

protected void badDuration(String msg, CharSequence s)

convertPrimitive

public AtomicValue convertPrimitive(BuiltInAtomicType requiredType, boolean validate, XPathContext context)
Convert to target data type

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

Returns: an AtomicValue, a value of the required type; or a ValidationErrorValue if the value cannot be converted.

convertToJava

public Object convertToJava(Class target, XPathContext context)
Convert to Java object (for passing to external functions)

divide

public DecimalValue divide(DurationValue other, XPathContext context)
Divide a duration by a another duration

equals

public boolean equals(Object other)
Test if the two durations are of equal length. Note: this function is defined in XPath 2.0, but its semantics are currently unclear.

getComponent

public AtomicValue getComponent(int component)
Get a component of the value

getItemType

public ItemType getItemType(TypeHierarchy th)
Determine the data type of the exprssion

Parameters: th

Returns: Type.DURATION,

getLengthInSeconds

public double getLengthInSeconds()
Get length of duration in seconds, assuming an average length of month. (Note, this defines a total ordering on durations which is different from the partial order defined in XML Schema; XPath 2.0 currently avoids defining an ordering at all. But the ordering here is consistent with the ordering of the two duration subtypes in XPath 2.0.)

getStringValue

public String getStringValue()
Convert the value to a string, using the serialization rules. For atomic values this is the same as a cast; for sequence values it gives a space-separated list. This method is refined for AtomicValues so that it never throws an Exception.

getStringValueCS

public CharSequence getStringValueCS()
Convert to string

Returns: ISO 8601 representation.

hashCode

public int hashCode()

multiply

public DurationValue multiply(double factor, XPathContext context)
Multiply a duration by a number

normalizeDuration

public DurationValue normalizeDuration()
Normalize the duration, so that months<12, hours<24, minutes<60, seconds<60. At present we do this when converting to a string. It's possible that it should be done immediately on constructing the duration (so that component extraction functions get the normalized value). We're awaiting clarification of the spec...

normalizeZeroDuration

protected void normalizeZeroDuration()

schemaEquals

public boolean schemaEquals(Value obj)
Compare two values for equality. This supports the matching rules in XML Schema, which say that two durations are equal only if all six components are equal (thus 12 months does not equal one year).

subtract

public DurationValue subtract(DurationValue other, XPathContext context)
Subtract two durations