net.sf.saxon.value
Class MonthDurationValue

java.lang.Object
  |
  +--net.sf.saxon.value.Value
        |
        +--net.sf.saxon.value.AtomicValue
              |
              +--net.sf.saxon.value.DurationValue
                    |
                    +--net.sf.saxon.value.MonthDurationValue
All Implemented Interfaces:
java.lang.Comparable, Expression, Item, java.io.Serializable

public final class MonthDurationValue
extends DurationValue
implements java.lang.Comparable

A value of type xsd:yearMonthDuration

See Also:
Serialized Form

Field Summary
 
Fields inherited from class net.sf.saxon.value.DurationValue
days, hours, milliseconds, minutes, months, negative, seconds, years
 
Constructor Summary
MonthDurationValue(java.lang.CharSequence s)
          Constructor: create a duration value from a supplied string, in ISO 8601 format [+|-]PnYnM
 
Method Summary
 DurationValue add(DurationValue other)
          Add two year-month-durations
 int compareTo(java.lang.Object other)
          Compare the value to another duration value
 int conversionPreference(java.lang.Class required, Configuration config)
          Get conversion preference for this value to a Java class.
 java.lang.Object convertToJava(java.lang.Class target, Configuration config)
          Convert to Java object (for passing to external functions)
 void display(int level, NamePool pool)
          Diagnostic print of expression structure
 DoubleValue divide(DurationValue other)
          Find the ratio between two durations
static MonthDurationValue fromMonths(int months)
          Construct a duration value as a number of months.
 ItemType getItemType()
          Determine the data type of the exprssion
 int getLengthInMonths()
          Get the number of months in the duration
 java.lang.String getStringValue()
          Convert to string
 DurationValue multiply(double n)
          Multiply duration by a number
 void normalize()
          Normalize the value, for example 90M becomes 1H30M
 DurationValue subtract(DurationValue other)
          Subtract two year-month-durations
 
Methods inherited from class net.sf.saxon.value.DurationValue
badDuration, convert, equals, getComponent, getLengthInSeconds, hashCode
 
Methods inherited from class net.sf.saxon.value.AtomicValue
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, stringToNumber, trimWhitespace
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MonthDurationValue

public MonthDurationValue(java.lang.CharSequence s)
                   throws XPathException
Constructor: create a duration value from a supplied string, in ISO 8601 format [+|-]PnYnM

Method Detail

getStringValue

public java.lang.String getStringValue()
Convert to string

Specified by:
getStringValue in interface Item
Overrides:
getStringValue in class DurationValue
Returns:
ISO 8601 representation.

normalize

public void normalize()
Normalize the value, for example 90M becomes 1H30M


getLengthInMonths

public int getLengthInMonths()
Get the number of months in the duration


fromMonths

public static MonthDurationValue fromMonths(int months)
Construct a duration value as a number of months.


multiply

public DurationValue multiply(double n)
Multiply duration by a number

Overrides:
multiply in class DurationValue

divide

public DoubleValue divide(DurationValue other)
                   throws XPathException
Find the ratio between two durations

Overrides:
divide in class DurationValue
Parameters:
other - the dividend
Returns:
the ratio, as a double
Throws:
XPathException

add

public DurationValue add(DurationValue other)
                  throws XPathException
Add two year-month-durations

Overrides:
add in class DurationValue
XPathException

subtract

public DurationValue subtract(DurationValue other)
                       throws XPathException
Subtract two year-month-durations

Overrides:
subtract in class DurationValue
XPathException

getItemType

public ItemType getItemType()
Determine the data type of the exprssion

Specified by:
getItemType in interface Expression
Overrides:
getItemType in class DurationValue
Returns:
Type.YEAR_MONTH_DURATION,

conversionPreference

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

Overrides:
conversionPreference in class DurationValue

convertToJava

public java.lang.Object convertToJava(java.lang.Class target,
                                      Configuration config)
                               throws XPathException
Convert to Java object (for passing to external functions)

Overrides:
convertToJava in class DurationValue
Parameters:
target - The class required by the external function
config - The configuration (needed for access to schema information)
Returns:
an object of the target class
XPathException

compareTo

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

Specified by:
compareTo in interface java.lang.Comparable
Overrides:
compareTo in class DurationValue
Parameters:
other - The other dateTime value
Returns:
negative value if this one is the earler, 0 if they are chronologically equal, positive value if this one is the later. For this purpose, dateTime values with an unknown timezone are considered to be UTC values (the Comparable interface requires a total ordering).
Throws:
java.lang.ClassCastException - if the other value is not a DateTimeValue (the parameter is declared as Object to satisfy the Comparable interface)

display

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

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