Overview | Package | Class | Deprecated | 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:
  Serializable, Comparable, SequenceIterable, Item, ValueRepresentation

Direct Known Subclasses:
  DayTimeDurationValue, YearMonthDurationValue

    public class DurationValue

extends AtomicValue

A value of type xs:duration

See Also:
  Serialized Form

Field Summary

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

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

Constructor Summary
`DurationValue(boolean positive, int years, int months, int days, int hours, int minutes, int seconds, int microseconds)`
`DurationValue(boolean positive, int years, int months, int days, int hours, int minutes, int seconds, int microseconds, AtomicType type)`
`DurationValue(CharSequence s)` Constructor: create a duration value from a supplied string, in ISO 8601 format [-]PnYnMnDTnHnMnS

Method Summary
`DurationValue` | `add(DurationValue other)` Add two durations
`AtomicValue` | `convertPrimitive(BuiltInAtomicType requiredType, boolean validate, XPathContext context)` Convert to target data type
`Object` | `convertToJava(Class target, XPathContext context)` Convert to Java object (for passing to external functions)
`AtomicValue` | `copy(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
`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
`String` | `getStringValue()` Convert the value to a string, using the serialization rules.
`CharSequence` | `getStringValueCS()` Convert to string
`Comparable` | `getXPathComparable()` Get a Comparable value that implements the XPath ordering comparison semantics for this value.
`int` | `getYears()` Get the year component
`int` | `hashCode()` Return a hash code to support the equals() function
`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.
`int` | `signum()` Return the signum of the value
`DurationValue` | `subtract(DurationValue other)` Subtract two durations

Methods inherited from class net.sf.saxon.value.AtomicValue
`checkPermittedContents, convert, convert, effectiveBooleanValue, getCardinality, getItemType, getLength, getTypedValue, getTypeLabel, hasBuiltInType, isMultiValued, itemAt, iterate, process, setTypeLabel, toString`

Methods inherited from class net.sf.saxon.value.Value
`asItem, asItem, asIterator, asValue, compareTo, convert, convertJavaObjectToXPath, fromItem, getCanonicalLexicalRepresentation, getIterator, iterate, makeQNameValue, reduce, stringToNumber`

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

Constructor Detail

### DurationValue

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

### DurationValue

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

### DurationValue

    public DurationValue(CharSequence s)
                  throws XPathException

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

  Throws:
    `XPathException`

Method Detail

### copy

    public AtomicValue copy(AtomicType typeLabel)

  Create a copy of this atomic value, with a different type label

  Specified by:
    `copy` in class `AtomicValue`
  Parameters:
    `typeLabel` - the type label of the new copy. The caller is responsible for checking that the value actually conforms to this type.

### getPrimitiveType

    public BuiltInAtomicType getPrimitiveType()

  Determine the primitive type of the value. This delivers the same answer as getItemType().getPrimitiveItemType(). The primitive types are the 19 primitive types of XML Schema, plus xs:integer, xs:dayTimeDuration and xs:yearMonthDuration, and xs:untypedAtomic. For external objects, the result is AnyAtomicType.

  Specified by:
    `getPrimitiveType` in class `AtomicValue`

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

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

### getYears

    public int getYears()

  Get the year component

  Returns:
    the number of years in the normalized duration; always positive

### getMonths

    public int getMonths()

  Get the months component

  Returns:
    the number of months in the normalized duration; always positive

### getDays

    public int getDays()

  Get the days component

  Returns:
    the number of days in the normalized duration; always positive

### getHours

    public int getHours()

  Get the hours component

  Returns:
    the number of hours in the normalized duration; always positive

### getMinutes

    public int getMinutes()

  Get the minutes component

  Returns:
    the number of minutes in the normalized duration; always positive

### getSeconds

    public int getSeconds()

  Get the seconds component

  Returns:
    the number of whole seconds in the normalized duration; always positive

### getMicroseconds

    public int getMicroseconds()

  Get the microseconds component

  Returns:
    the number of microseconds in the normalized duration; always positive

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

  Specified by:
    `getStringValue` in interface `Item`
  Specified by:
    `getStringValue` in interface `ValueRepresentation`
  Specified by:
    `getStringValue` in class `AtomicValue`
  Returns:
    the string value of the item
  See Also:
    `Item.getStringValueCS()`

### getStringValueCS

    public CharSequence getStringValueCS()

  Convert to string

  Specified by:
    `getStringValueCS` in interface `Item`
  Specified by:
    `getStringValueCS` in interface `ValueRepresentation`
  Overrides:
    `getStringValueCS` in class `AtomicValue`
  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.)

### convertToJava

    public Object convertToJava(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 normalized value

  Overrides:
    `getComponent` in class `AtomicValue`
  Throws:
    `XPathException`

### equals

    public boolean equals(Object other)

  Test if the two durations are of equal length.

  Overrides:
    `equals` in class `Value`
  Throws:
    `ClassCastException` - if the other value is not an xs:duration or subtype thereof

### hashCode

    public int hashCode()

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

  Overrides:
    `hashCode` in class `Value`

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

### getXPathComparable

    public Comparable getXPathComparable()

  Get a Comparable value that implements the XPath ordering comparison semantics for this value. Returns null if the value is not comparable according to XPath rules. The default implementation returns the value itself. This is modified for types such as xs:duration which allow ordering comparisons in XML Schema, but not in XPath.

  Overrides:
    `getXPathComparable` in class `AtomicValue`

### getSchemaComparable

    public Comparable getSchemaComparable()

  Get a Comparable value that implements the XML Schema ordering comparison semantics for this value. This implementation handles the ordering rules for durations in XML Schema. It is overridden for the two subtypes DayTimeDuration and YearMonthDuration.

  Overrides:
    `getSchemaComparable` in class `Value`

### getSchemaComparable

    public static Comparable getSchemaComparable(DurationValue value)

  Get a Comparable value that implements the XML Schema ordering comparison semantics for this value. This implementation handles the ordering rules for durations in XML Schema.

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

Copyright (C) Michael H. Kay. All rights reserved.