Class DurationValue
java.lang.Object
net.sf.saxon.value.Value
net.sf.saxon.value.AtomicValue
net.sf.saxon.value.DurationValue
- All Implemented Interfaces:
Serializable, Expression, Item, ValueRepresentation
- Direct Known Subclasses:
MonthDurationValue, SecondsDurationValue
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected intprotected intprotected intprotected intprotected booleanprotected booleanprotected intprotected intFields inherited from class Value
EMPTY_CLASS_ARRAYFields inherited from interface Expression
EVALUATE_METHOD, ITERATE_METHOD, PROCESS_METHODFields inherited from interface ValueRepresentation
EMPTY_VALUE_ARRAY -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedPrivate constructor for internal useDurationValue(boolean positive, int years, int months, int days, int hours, int minutes, int seconds, int microseconds) Constructor: create a duration value from a supplied string, in ISO 8601 format [-]PnYnMnDTnHnMnS -
Method Summary
Modifier and TypeMethodDescriptionadd(DurationValue other) Add two durationsprotected voidbadDuration(String msg, CharSequence s) convertPrimitive(BuiltInAtomicType requiredType, boolean validate, XPathContext context) Convert to target data typeconvertToJava(Class target, XPathContext context) Convert to Java object (for passing to external functions)divide(DurationValue other) Divide a duration by a another durationbooleanTest if the two durations are of equal length.getComponent(int component) Get a component of the normalized valueDetermine the data type of the exprssiondoubleGet length of duration in seconds, assuming an average length of month.Convert the value to a string, using the serialization rules.Convert to stringinthashCode()Return a hash code to support the equals() functionmultiply(double factor) Multiply a duration by a numbernegate()Negate a duration (same as subtracting from zero, but it preserves the type of the original duration)Normalize the duration, so that monthsinvalid input: '<'12, hoursinvalid input: '<'24, minutesinvalid input: '<'60, secondsinvalid input: '<'60.protected voidintsignum()Return the signum of the valuesubtract(DurationValue other) Subtract two durationsMethods inherited from class AtomicValue
checkPermittedContents, convert, convert, display, effectiveBooleanValue, evaluateAsString, evaluateItem, getCardinality, getImplementationMethod, getLength, getPrimitiveValue, getTypedValue, hasBuiltInType, iterate, process, toStringMethods inherited from class Value
asItem, asIterator, asValue, convert, convertJavaObjectToXPath, getDependencies, getIterator, getParentExpression, getSpecialProperties, itemAt, iterateSubExpressions, makeQNameValue, optimize, promote, reduce, simplify, stringToNumber, typeCheck
-
Field Details
-
negative
protected boolean negative -
years
protected int years -
months
protected int months -
days
protected int days -
hours
protected int hours -
minutes
protected int minutes -
seconds
protected int seconds -
microseconds
protected int microseconds -
normalized
protected boolean normalized
-
-
Constructor Details
-
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
Constructor: create a duration value from a supplied string, in ISO 8601 format [-]PnYnMnDTnHnMnS- Throws:
XPathException
-
-
Method Details
-
normalizeZeroDuration
protected void normalizeZeroDuration() -
badDuration
- 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
Normalize the duration, so that monthsinvalid input: '<'12, hoursinvalid input: '<'24, minutesinvalid input: '<'60, secondsinvalid input: '<'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
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:
-
getStringValueCS
Convert to string- Specified by:
getStringValueCSin interfaceItem- Specified by:
getStringValueCSin interfaceValueRepresentation- Overrides:
getStringValueCSin classAtomicValue- Returns:
- ISO 8601 representation.
- See Also:
-
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
Determine the data type of the exprssion- Specified by:
getItemTypein interfaceExpression- Overrides:
getItemTypein classValue- Parameters:
th-- Returns:
- Type.DURATION,
-
convertToJava
Convert to Java object (for passing to external functions)- Overrides:
convertToJavain classValue- Throws:
XPathException
-
getComponent
Get a component of the normalized value- Overrides:
getComponentin classAtomicValue- Throws:
XPathException
-
equals
Test if the two durations are of equal length. Note: this function is defined in XPath 2.0, but its semantics are currently unclear.- Overrides:
equalsin classValue- Throws:
ClassCastException- if the other value is not an xs:duration or subtype thereof
-
hashCode
-
add
Add two durations- Throws:
XPathException
-
subtract
Subtract two durations- Throws:
XPathException
-
negate
Negate a duration (same as subtracting from zero, but it preserves the type of the original duration) -
multiply
Multiply a duration by a number- Throws:
XPathException
-
divide
Divide a duration by a another duration- Throws:
XPathException
-