net.sf.saxon.value
Class MonthDurationValue

java.lang.Object
  extended bynet.sf.saxon.value.Value
      extended bynet.sf.saxon.value.AtomicValue
          extended bynet.sf.saxon.value.DurationValue
              extended bynet.sf.saxon.value.MonthDurationValue
All Implemented Interfaces:
java.lang.Comparable, Expression, Item, java.io.Serializable, ValueRepresentation

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, microseconds, minutes, months, negative, seconds, 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
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, XPathContext context)
          Add two year-month-durations
 int compareTo(java.lang.Object other)
          Compare the value to another duration value
 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)
          Find the ratio between two durations
static MonthDurationValue fromMonths(int months)
          Construct a duration value as a number of months.
 ItemType getItemType(TypeHierarchy th)
          Determine the data type of the exprssion
 int getLengthInMonths()
          Get the number of months in the duration
 java.lang.CharSequence getStringValueCS()
          Convert to string
 DurationValue multiply(double n, XPathContext context)
          Multiply duration by a number.
 void normalize()
          Normalize the value, for example 90M becomes 1H30M
 DurationValue subtract(DurationValue other, XPathContext context)
          Subtract two year-month-durations
 
Methods inherited from class net.sf.saxon.value.DurationValue
badDuration, convertPrimitive, equals, getComponent, getLengthInSeconds, getStringValue, hashCode, normalizeDuration, normalizeZeroDuration, schemaEquals
 
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
 

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

getStringValueCS

public java.lang.CharSequence getStringValueCS()
Convert to string

Specified by:
getStringValueCS in interface Item
Overrides:
getStringValueCS 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,
                              XPathContext context)
                       throws XPathException
Multiply duration by a number. Also used when dividing a duration by a number

Overrides:
multiply in class DurationValue
Throws:
XPathException

divide

public DecimalValue divide(DurationValue other,
                           XPathContext context)
                    throws XPathException
Find the ratio between two durations

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

add

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

Overrides:
add in class DurationValue
Throws:
XPathException

subtract

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

Overrides:
subtract in class DurationValue
Throws:
XPathException

getItemType

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

Specified by:
getItemType in interface Expression
Overrides:
getItemType in class DurationValue
Parameters:
th -
Returns:
Type.YEAR_MONTH_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 DurationValue
Throws:
XPathException

compareTo

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

Specified by:
compareTo in interface java.lang.Comparable
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)