| Prev Class | Next Class | Frames | No Frames |
| Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
Durationnet.sf.saxon.xqj.SaxonDurationpublic class SaxonDurationextends DurationDurationValue.
The JAXP specification for this class defines it in terms of XML Schema 1.0 semantics. This defines a structure
with six independent components (year, month, day, hour, minute, second). This implementation is more aligned
to the XPath 2.0 semantics of the data type, which essentially defines duration as an integer number of months plus
a decimal number of seconds.
Constructor Summary | |
| |
Method Summary | |
Duration |
|
void |
|
int |
|
DurationValue |
|
Number |
|
int |
|
QName |
|
int |
|
boolean |
|
Duration |
|
Duration |
|
Duration |
|
Duration |
|
public SaxonDuration(DurationValue duration)
Create a SaxonDuration that wraps a supplied DurationValue
- Parameters:
duration- the value to be wrapped.
public Duration add(Duration rhs)
Computes a new duration whose value isthis+rhs. This implementation follows the XPath semantics. This means that the operation will fail if the duration is not a yearMonthDuration or a dayTimeDuration.
- Parameters:
rhs-Durationto add to thisDuration
- Returns:
- non-null valid Duration object.
- See Also:
subtract(javax.xml.datatype.Duration)
public void addTo(Calendar calendar)
Adds this duration to ajava.util.Calendarobject. Callsjava.util.Calendar.add(int,int)in the order of YEARS, MONTHS, DAYS, HOURS, MINUTES, SECONDS, and MILLISECONDS if those fields are present. Because thejava.util.Calendarclass uses int to hold values, there are cases where this method won't work correctly (for example if values of fields exceed the range of int.) Also, since this duration class is a Gregorian duration, this method will not work correctly if the givenjava.util.Calendarobject is based on some other calendar systems. Any fractional parts of thisDurationobject beyond milliseconds will be simply ignored. For example, if this duration is "P1.23456S", then 1 is added to SECONDS, 234 is added to MILLISECONDS, and the rest will be unused. Note that becausejava.util.Calendar.add(int, int)is using int,Durationwith values beyond the range of int in its fields will cause overflow/underflow to the givenjava.util.Calendar.javax.xml.datatype.XMLGregorianCalendar.add(javax.xml.datatype.Duration)provides the same basic operation as this method while avoiding the overflow/underflow issues.
- Parameters:
calendar- A calendar object whose value will be modified.
public int compare(Duration rhs)
Partial order relation comparison with thisDurationinstance. This implementation follows the XPath semantics. This means that the result is defined only for dayTimeDuration and yearMonthDuration values, and the result is never indeterminate. Return:
javax.xml.datatype.DatatypeConstants.LESSERif thisDurationis shorter thandurationparameterjavax.xml.datatype.DatatypeConstants.EQUALif thisDurationis equal todurationparameterjavax.xml.datatype.DatatypeConstants.GREATERif thisDurationis longer thandurationparameterjavax.xml.datatype.DatatypeConstants.INDETERMINATEif a conclusive partial order relation cannot be determined
- Parameters:
rhs- duration to compare
- Returns:
- the relationship between
thisDurationanddurationparameter asjavax.xml.datatype.DatatypeConstants.LESSER,javax.xml.datatype.DatatypeConstants.EQUAL,javax.xml.datatype.DatatypeConstants.GREATERorjavax.xml.datatype.DatatypeConstants.INDETERMINATE.
- See Also:
isShorterThan(javax.xml.datatype.Duration),isLongerThan(javax.xml.datatype.Duration)
public DurationValue getDurationValue()
Get the underlying DurationValue
- Returns:
- the underlying DurationValue
public Number getField(DatatypeConstants.Field field)
Gets the value of a field. Fields of a duration object may contain arbitrary large value. Therefore this method is designed to return aNumberobject. In case of YEARS, MONTHS, DAYS, HOURS, and MINUTES, the returned number will be a non-negative integer. In case of seconds, the returned number may be a non-negative decimal value. The Saxon implementation of duration uses normalized values. This means that the YEARS and DAYS fields may be arbitrarily large, but other components will be limited in size: for example MINUTES will never exceed 60 and MONTHS will never exceed 12.
- Parameters:
field- one of the six Field constants (YEARS, MONTHS, DAYS, HOURS, MINUTES, or SECONDS.)
- Returns:
- If the specified field is present, this method returns a non-null non-negative
Numberobject that represents its value. If it is not present, return null. For YEARS, MONTHS, DAYS, HOURS, and MINUTES, this method returns ajava.math.BigIntegerobject. For SECONDS, this method returns ajava.math.BigDecimal.
public int getSign()
Returns the sign of this duration in -1,0, or 1.
- Returns:
- -1 if this duration is negative, 0 if the duration is zero, and 1 if the duration is positive.
public QName getXMLSchemaType()
Get the type of this duration, as one of the values xs:duration, xs:dayTimeDuration, or xs:yearMonthDuration. (Note that the XML Schema namespace URI is used, whereas the current implementation of the superclass uses a provisional URI allocated in a 2003 W3C working draft)
- Returns:
- the type of this duration, as one of the values xs:duration, xs:dayTimeDuration, or xs:yearMonthDuration
public int hashCode()
Returns a hash code consistent with the definition of the equals method.
- See Also:
Object.hashCode()
public boolean isSet(DatatypeConstants.Field field)
Checks if a field is set. In this implementation, all fields are always set.
- Parameters:
field- one of the six Field constants (YEARS, MONTHS, DAYS, HOURS, MINUTES, or SECONDS.)
- Returns:
- This implementation always returns true.
public Duration multiply(BigDecimal factor)
Computes a new duration whose value isfactortimes longer than the value of this duration. This implementation follows the XPath semantics. This means that it is defined only on yearMonthDuration and dayTimeDuration. Other cases produce an IllegalStateException.
- Parameters:
factor- to multiply by
- Returns:
- returns a non-null valid
Durationobject
public Duration negate()
Returns a newDurationobject whose value is-this. Since theDurationclass is immutable, this method doesn't change the value of this object. It simply computes a new Duration object and returns it.
- Returns:
- always return a non-null valid
Durationobject.
public Duration normalizeWith(Calendar startTimeInstant)
Converts the years and months fields into the days field by using a specific time instant as the reference point. This implementation does not support this method
- Parameters:
startTimeInstant-Calendarreference point.
- Returns:
Durationof years and months of thisDurationas days.
public Duration subtract(Duration rhs)
Computes a new duration whose value isthis-rhs. This implementation follows the XPath semantics. This means that the operation will fail if the duration is not a yearMonthDuration or a dayTimeDuration.
- Parameters:
rhs-Durationto subtract from thisDuration
- Returns:
- non-null valid Duration object.
- See Also:
add(javax.xml.datatype.Duration)