net.sf.saxon.value
Class DurationValue

java.lang.Object
  extended by net.sf.saxon.value.Value
      extended by net.sf.saxon.value.AtomicValue
          extended by net.sf.saxon.value.DurationValue
All Implemented Interfaces:
Serializable, Comparable, Expression, Item
Direct Known Subclasses:
MonthDurationValue, SecondsDurationValue

public class DurationValue
extends AtomicValue
implements Comparable

A value of type xs:duration

See Also:
Serialized Form

Field Summary
protected  int days
           
protected  int hours
           
protected  int milliseconds
           
protected  int minutes
           
protected  int months
           
protected  boolean negative
           
protected  int seconds
           
protected  int years
           
 
Constructor Summary
protected DurationValue()
          Private constructor for internal use
  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
protected  void badDuration(String msg, CharSequence s)
           
 int compareTo(Object other)
          Compare the value to another duration value
 int conversionPreference(Class required)
          Get conversion preference for this value to a Java class.
 AtomicValue convert(int requiredType)
          Convert to target data type
 Object convertToJava(Class target)
          Convert to Java object (for passing to external functions)
 void display(int level, NamePool pool)
          Diagnostic print of expression structure
 boolean equals(Object other)
          Test if the two durations are of equal length.
 AtomicValue getComponent(int component)
          Get a component of the value
 ItemType getItemType()
          Determine the data type of the exprssion
 double getLengthInSeconds()
          Get length of duration in seconds, assuming an average length of month.
 String getStringValue()
          Convert to string
 int hashCode()
           
 DurationValue multiply(double factor)
          Multiply a duration by a number
 DurationValue subtract(DurationValue other)
          Subtract two durations
 
Methods inherited from class net.sf.saxon.value.AtomicValue
convert, convert, effectiveBooleanValue, evaluateAsString, evaluateItem, getCardinality, getPrimitiveValue, getTypedValue, iterate
 
Methods inherited from class net.sf.saxon.value.Value
analyze, asItem, asValue, collapseWhitespace, getDependencies, getSpecialProperties, getSubExpressions, inverse, normalizeWhitespace, promote, simplify, stringToInteger, stringToNumber, trimWhitespace
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, 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

milliseconds

protected int milliseconds
Constructor Detail

DurationValue

protected DurationValue()
Private constructor for internal use


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

badDuration

protected void badDuration(String msg,
                           CharSequence s)
                    throws XPathException
Throws:
XPathException

convert

public AtomicValue convert(int requiredType)
                    throws XPathException
Convert to target data type

Specified by:
convert in class AtomicValue
Parameters:
requiredType - an integer identifying the required atomic type
Returns:
an AtomicValue, a value of the required type
Throws:
XPathException - if the conversion is not possible

getStringValue

public String getStringValue()
Convert to string

Specified by:
getStringValue in interface Item
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()
Determine the data type of the exprssion

Specified by:
getItemType in interface Expression
Returns:
Type.DURATION,

conversionPreference

public int conversionPreference(Class required)
Get conversion preference for this value to a Java class. A low result indicates higher preference.

Overrides:
conversionPreference in class AtomicValue

convertToJava

public Object convertToJava(Class target)
                     throws XPathException
Convert to Java object (for passing to external functions)

Overrides:
convertToJava in class AtomicValue
Parameters:
target - The class required by the external function
Returns:
an object of the target class
Throws:
XPathException

getComponent

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

Overrides:
getComponent in class AtomicValue
Throws:
XPathException

compareTo

public int compareTo(Object other)
Compare the value to another duration value

Specified by:
compareTo in interface Comparable
Parameters:
other - The other dateTime value
Returns:
negative value if this one is the shorter duration, 0 if they are equal, positive value if this one is the longer duration. For this purpose, a year is considered to be equal to 365.242199 days.
Throws:
ClassCastException - if the other value is not a DurationValue (the parameter is declared as Object to satisfy the Comparable interface)

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.

Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

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

multiply

public DurationValue multiply(double factor)
                       throws XPathException
Multiply a duration by a number

Throws:
XPathException

display

public void display(int level,
                    NamePool pool)
Diagnostic print of expression structure

Specified by:
display in interface Expression
Parameters:
level - indentation level for this expression