Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## 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:
  Expression, Item, java.io.Serializable, ValueRepresentation

Direct Known Subclasses:
  MonthDurationValue, SecondsDurationValue

public class DurationValue
extends AtomicValue

A value of type xs:duration

See Also:
  Serialized Form

Field Summary
`protected int` | `days`
`protected int` | `hours`
`protected int` | `microseconds`
`protected int` | `minutes`
`protected int` | `months`
`protected boolean` | `negative`
`protected int` | `seconds`
`protected int` | `years`

Fields inherited from class net.sf.saxon.value.Value
`EMPTY_CLASS_ARRAY`

Fields inherited from interface net.sf.saxon.om.ValueRepresentation
`EMPTY_VALUE_ARRAY`

Fields inherited from interface net.sf.saxon.expr.Expression
`EVALUATE_METHOD, ITERATE_METHOD, PROCESS_METHOD`

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(java.lang.CharSequence s)` Constructor: create a duration value from a supplied string, in ISO 8601 format [+|-]PnYnMnDTnHnMnS

Method Summary
`DurationValue` | `add(DurationValue other, XPathContext context)` Add two durations
`protected void` | `badDuration(java.lang.String msg, java.lang.CharSequence s)`
`AtomicValue` | `convertPrimitive(BuiltInAtomicType requiredType, boolean validate, XPathContext context)` Convert to target data type
`java.lang.Object` | `convertToJava(java.lang.Class target, XPathContext context)` Convert to Java object (for passing to external functions)
`DecimalValue` | `divide(DurationValue other, XPathContext context)` Divide a duration by a another duration
`boolean` | `equals(java.lang.Object other)` Test if the two durations are of equal length.
`AtomicValue` | `getComponent(int component)` Get a component of the value
`ItemType` | `getItemType(TypeHierarchy th)` Determine the data type of the exprssion
`double` | `getLengthInSeconds()` Get length of duration in seconds, assuming an average length of month.
`java.lang.String` | `getStringValue()` Convert the value to a string, using the serialization rules.
`java.lang.CharSequence` | `getStringValueCS()` Convert to string
`int` | `hashCode()` Return a hash code to support the equals() function
`DurationValue` | `multiply(double factor, XPathContext context)` Multiply a duration by a number
`DurationValue` | `normalizeDuration()` Normalize the duration, so that months<12, hours<24, minutes<60, seconds<60.
`boolean` | `schemaEquals(Value obj)` Compare two values for equality.
`DurationValue` | `subtract(DurationValue other, XPathContext context)` 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, collapseWhitespace, convert, convertJavaObjectToXPath, getDependencies, getIterator, getParentExpression, getSpecialProperties, itemAt, iterateSubExpressions, makeQNameValue, normalizeWhitespace, optimize, promote, reduce, simplify, stringToNumber, trimWhitespace, typeCheck`

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

Field Detail

### 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

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 XPathException

  Constructor: create a duration value from a supplied string, in ISO 8601 format [+|-]PnYnMnDTnHnMnS

Method Detail

### 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:
    `convertPrimitive` in class `AtomicValue`
  Parameters:
    `requiredType` - an integer identifying the required atomic type
    `context` -
    `validate` - true if validation is required. If set to false, the caller guarantees that the value is valid for the target data type, and that further validation is therefore not required. Note that a validation failure may be reported even if validation was not requested.
  Returns:
    an AtomicValue, a value of the required type; or an ErrorValue

### 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...

### 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:
    `getStringValue` in interface `Item`
  Specified by:
    `getStringValue` in class `AtomicValue`

### getStringValueCS

    public java.lang.CharSequence getStringValueCS()

  Convert to string

  Specified by:
    `getStringValueCS` in interface `Item`
  Overrides:
    `getStringValueCS` in class `AtomicValue`
  Returns:
    ISO 8601 representation.

### 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:
    `getItemType` in interface `Expression`
  Overrides:
    `getItemType` in class `Value`
  Parameters:
    `th` -
  Returns:
    Type.DURATION,

### convertToJava

    public java.lang.Object convertToJava(java.lang.Class target,
                                          XPathContext context)
                                   throws XPathException

  Convert to Java object (for passing to external functions)

  Overrides:
    `convertToJava` in class `Value`
  Throws:
    `XPathException`

### getComponent

    public AtomicValue getComponent(int component)
                             throws XPathException

  Get a component of the value

  Overrides:
    `getComponent` in class `AtomicValue`
  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.

  Overrides:
    `equals` in class `Value`

### hashCode

    public int hashCode()

  Description copied from class: `Value`
  Return a hash code to support the equals() function

  Overrides:
    `hashCode` in class `Value`

### 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).

  Overrides:
    `schemaEquals` in class `AtomicValue`

### add

    public DurationValue add(DurationValue other,
                             XPathContext context)
                      throws XPathException

  Add two durations

  Throws:
    `XPathException`

### subtract

    public DurationValue subtract(DurationValue other,
                                  XPathContext context)
                           throws XPathException

  Subtract two durations

  Throws:
    `XPathException`

### multiply

    public DurationValue multiply(double factor,
                                  XPathContext context)
                           throws XPathException

  Multiply a duration by a number

  Throws:
    `XPathException`

### divide

    public DecimalValue divide(DurationValue other,
                               XPathContext context)
                        throws XPathException

  Divide a duration by a another duration

  Throws:
    `XPathException`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD