Package net.sf.saxon.value
Class DurationValue
- java.lang.Object
-
- net.sf.saxon.value.Value
-
- net.sf.saxon.value.AtomicValue
-
- net.sf.saxon.value.DurationValue
-
- All Implemented Interfaces:
java.io.Serializable,Expression,Item,ValueRepresentation
- Direct Known Subclasses:
MonthDurationValue,SecondsDurationValue
public class DurationValue extends AtomicValue
A value of type xs:duration- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected intdaysprotected inthoursprotected intmicrosecondsprotected intminutesprotected intmonthsprotected booleannegativeprotected booleannormalizedprotected intsecondsprotected intyears-
Fields inherited from class net.sf.saxon.value.Value
EMPTY_CLASS_ARRAY
-
Fields inherited from interface net.sf.saxon.expr.Expression
EVALUATE_METHOD, ITERATE_METHOD, PROCESS_METHOD
-
Fields inherited from interface net.sf.saxon.om.ValueRepresentation
EMPTY_VALUE_ARRAY
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedDurationValue()Private constructor for internal useDurationValue(boolean positive, int years, int months, int days, int hours, int minutes, int seconds, int microseconds)DurationValue(java.lang.CharSequence s)Constructor: create a duration value from a supplied string, in ISO 8601 format [-]PnYnMnDTnHnMnS
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DurationValueadd(DurationValue other)Add two durationsprotected voidbadDuration(java.lang.String msg, java.lang.CharSequence s)AtomicValueconvertPrimitive(BuiltInAtomicType requiredType, boolean validate, XPathContext context)Convert to target data typejava.lang.ObjectconvertToJava(java.lang.Class target, XPathContext context)Convert to Java object (for passing to external functions)DecimalValuedivide(DurationValue other)Divide a duration by a another durationbooleanequals(java.lang.Object other)Test if the two durations are of equal length.AtomicValuegetComponent(int component)Get a component of the normalized valueItemTypegetItemType(TypeHierarchy th)Determine the data type of the exprssiondoublegetLengthInSeconds()Get length of duration in seconds, assuming an average length of month.java.lang.StringgetStringValue()Convert the value to a string, using the serialization rules.java.lang.CharSequencegetStringValueCS()Convert to stringinthashCode()Return a hash code to support the equals() functionDurationValuemultiply(double factor)Multiply a duration by a numberDurationValuenegate()Negate a duration (same as subtracting from zero, but it preserves the type of the original duration)DurationValuenormalizeDuration()Normalize the duration, so that months<12, hours<24, minutes<60, seconds<60.protected voidnormalizeZeroDuration()intsignum()Return the signum of the valueDurationValuesubtract(DurationValue other)Subtract two durations-
Methods inherited from class net.sf.saxon.value.AtomicValue
checkPermittedContents, convert, convert, display, effectiveBooleanValue, evaluateAsString, evaluateItem, getCardinality, getImplementationMethod, getLength, getPrimitiveValue, getTypedValue, hasBuiltInType, iterate, process, toString
-
Methods inherited from class net.sf.saxon.value.Value
asItem, asIterator, asValue, convert, convertJavaObjectToXPath, getDependencies, getIterator, getParentExpression, getSpecialProperties, itemAt, iterateSubExpressions, makeQNameValue, optimize, promote, reduce, simplify, stringToNumber, typeCheck
-
-
-
-
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(java.lang.CharSequence s) throws XPathExceptionConstructor: create a duration value from a supplied string, in ISO 8601 format [-]PnYnMnDTnHnMnS- Throws:
XPathException
-
-
Method Detail
-
normalizeZeroDuration
protected void normalizeZeroDuration()
-
badDuration
protected void badDuration(java.lang.String msg, java.lang.CharSequence s) throws XPathException- Throws:
XPathException
-
convertPrimitive
public AtomicValue convertPrimitive(BuiltInAtomicType requiredType, boolean validate, XPathContext context)
Convert to target data type- Specified by:
convertPrimitivein classAtomicValue- Parameters:
requiredType- an integer identifying the required atomic typevalidate- if set to false, the caller asserts that the value is known to be validcontext-- Returns:
- an AtomicValue, a value of the required type; or a
ValidationErrorValueif the value cannot be converted.
-
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 (bugzilla 3369)- Returns:
- a new, normalized duration
-
signum
public int signum()
Return the signum of the value- Returns:
- -1 if the duration is negative, zero if it is zero-length, +1 if it is positive
-
getStringValue
public java.lang.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.- Specified by:
getStringValuein interfaceItem- Specified by:
getStringValuein interfaceValueRepresentation- Specified by:
getStringValuein classAtomicValue- Returns:
- the string value of the item
- See Also:
Item.getStringValueCS()
-
getStringValueCS
public java.lang.CharSequence getStringValueCS()
Convert to string- Specified by:
getStringValueCSin interfaceItem- Specified by:
getStringValueCSin interfaceValueRepresentation- Overrides:
getStringValueCSin classAtomicValue- Returns:
- ISO 8601 representation.
- See Also:
Item.getStringValue()
-
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.)
-
getItemType
public ItemType getItemType(TypeHierarchy th)
Determine the data type of the exprssion- Specified by:
getItemTypein interfaceExpression- Overrides:
getItemTypein classValue- Parameters:
th-- Returns:
- Type.DURATION,
-
convertToJava
public java.lang.Object convertToJava(java.lang.Class target, XPathContext context) throws XPathExceptionConvert to Java object (for passing to external functions)- Overrides:
convertToJavain classValue- Throws:
XPathException
-
getComponent
public AtomicValue getComponent(int component) throws XPathException
Get a component of the normalized value- Overrides:
getComponentin classAtomicValue- Throws:
XPathException
-
equals
public boolean equals(java.lang.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.
-
hashCode
public int hashCode()
Description copied from class:ValueReturn a hash code to support the equals() function
-
add
public DurationValue add(DurationValue other) throws XPathException
Add two durations- Throws:
XPathException
-
subtract
public DurationValue subtract(DurationValue other) throws XPathException
Subtract two durations- Throws:
XPathException
-
negate
public DurationValue negate()
Negate a duration (same as subtracting from zero, but it preserves the type of the original duration)
-
multiply
public DurationValue multiply(double factor) throws XPathException
Multiply a duration by a number- Throws:
XPathException
-
divide
public DecimalValue divide(DurationValue other) throws XPathException
Divide a duration by a another duration- Throws:
XPathException
-
-