|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object javax.xml.datatype.Duration net.sf.saxon.xqj.SaxonDuration
public class SaxonDuration
Saxon implementation of the JAXP class javax.xml.datatype.Duration. This is currently used only by the XQJ
interface for XQuery: the normal representation of a duration in Saxon is the class DurationValue
.
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 | |
---|---|
SaxonDuration(DurationValue duration)
Create a SaxonDuration that wraps a supplied DurationValue |
Method Summary | |
---|---|
Duration |
add(Duration rhs)
Computes a new duration whose value is this+rhs . |
void |
addTo(Calendar calendar)
Adds this duration to a Calendar object. |
int |
compare(Duration rhs)
Partial order relation comparison with this Duration instance. |
DurationValue |
getDurationValue()
Get the underlying DurationValue |
Number |
getField(DatatypeConstants.Field field)
Gets the value of a field. |
int |
getSign()
Returns the sign of this duration in -1,0, or 1. |
QName |
getXMLSchemaType()
Get the type of this duration, as one of the values xs:duration, xs:dayTimeDuration, or xs:yearMonthDuration. |
int |
hashCode()
Returns a hash code consistent with the definition of the equals method. |
boolean |
isSet(DatatypeConstants.Field field)
Checks if a field is set. |
Duration |
multiply(BigDecimal factor)
Computes a new duration whose value is factor times
longer than the value of this duration. |
Duration |
negate()
Returns a new Duration object whose
value is -this . |
Duration |
normalizeWith(Calendar startTimeInstant)
Converts the years and months fields into the days field by using a specific time instant as the reference point. |
Duration |
subtract(Duration rhs)
Computes a new duration whose value is this-rhs . |
Methods inherited from class javax.xml.datatype.Duration |
---|
addTo, equals, getDays, getHours, getMinutes, getMonths, getSeconds, getTimeInMillis, getTimeInMillis, getYears, isLongerThan, isShorterThan, multiply, toString |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public SaxonDuration(DurationValue duration)
duration
- the value to be wrapped.Method Detail |
---|
public DurationValue getDurationValue()
public QName getXMLSchemaType()
getXMLSchemaType
in class Duration
public int getSign()
getSign
in class Duration
public Number getField(DatatypeConstants.Field field)
Number
object.
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.
getField
in class Duration
field
- one of the six Field constants (YEARS, MONTHS, DAYS, HOURS,
MINUTES, or SECONDS.)
Number
object that
represents its value. If it is not present, return null.
For YEARS, MONTHS, DAYS, HOURS, and MINUTES, this method
returns a BigInteger
object. For SECONDS, this
method returns a BigDecimal
.
NullPointerException
- If the field
is null
.public boolean isSet(DatatypeConstants.Field field)
isSet
in class Duration
field
- one of the six Field constants (YEARS, MONTHS, DAYS, HOURS,
MINUTES, or SECONDS.)
public Duration add(Duration rhs)
Computes a new duration whose value is this+rhs
.
This implementation follows the XPath semantics. This means that the operation will fail if the duration is not a yearMonthDuration or a dayTimeDuration.
add
in class Duration
rhs
- Duration
to add to this Duration
NullPointerException
- If the rhs parameter is null.
IllegalStateException
- If the durations are not both dayTimeDurations, or
both yearMonthDurations.subtract(javax.xml.datatype.Duration)
public Duration subtract(Duration rhs)
Computes a new duration whose value is this-rhs
.
This implementation follows the XPath semantics. This means that the operation will fail if the duration is not a yearMonthDuration or a dayTimeDuration.
subtract
in class Duration
rhs
- Duration
to subtract from this Duration
NullPointerException
- If the rhs parameter is null.
IllegalStateException
- If the durations are not both dayTimeDurations, or
both yearMonthDurations.add(javax.xml.datatype.Duration)
public void addTo(Calendar calendar)
Calendar
object.
Calls Calendar.add(int,int)
in the
order of YEARS, MONTHS, DAYS, HOURS, MINUTES, SECONDS, and MILLISECONDS
if those fields are present. Because the Calendar
class
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 given Calendar
object is based on some other calendar systems.
Any fractional parts of this Duration
object
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 because Calendar.add(int, int)
is using
int, Duration
with values beyond the
range of int in its fields
will cause overflow/underflow to the given Calendar
.
XMLGregorianCalendar.add(javax.xml.datatype.Duration)
provides the same
basic operation as this method while avoiding
the overflow/underflow issues.
addTo
in class Duration
calendar
- A calendar object whose value will be modified.
NullPointerException
- if the calendar parameter is null.public Duration multiply(BigDecimal factor)
factor
times
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.
multiply
in class Duration
factor
- to multiply by
Duration
object
IllegalStateException
- if operation produces fraction in
the months field.
NullPointerException
- if the factor
parameter is
null
.public Duration negate()
Duration
object whose
value is -this
.
Since the Duration
class is immutable, this method
doesn't change the value of this object. It simply computes
a new Duration object and returns it.
negate
in class Duration
Duration
object.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
normalizeWith
in class Duration
startTimeInstant
- Calendar
reference point.
Duration
of years and months of this Duration
as days.
NullPointerException
- If the startTimeInstant parameter is null.
UnsupportedOperationException
- Always thrown by this implementation.public int compare(Duration rhs)
Partial order relation comparison with this Duration
instance.
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:
DatatypeConstants.LESSER
if this Duration
is shorter than duration
parameterDatatypeConstants.EQUAL
if this Duration
is equal to duration
parameterDatatypeConstants.GREATER
if this Duration
is longer than duration
parameterDatatypeConstants.INDETERMINATE
if a conclusive partial order relation cannot be determined
compare
in class Duration
rhs
- duration to compare
this
Duration
and duration
parameter as
DatatypeConstants.LESSER
,
DatatypeConstants.EQUAL
,
DatatypeConstants.GREATER
or DatatypeConstants.INDETERMINATE
.
UnsupportedOperationException
- If the underlying implementation
cannot reasonably process the request, e.g. W3C XML Schema allows for
arbitrarily large/small/precise values, the request may be beyond the
implementations capability.
NullPointerException
- if duration
is null
.
IllegalArgumentException
- if the operands are not dayTimeDuration or yearMonthDuration values.Duration.isShorterThan(javax.xml.datatype.Duration)
,
Duration.isLongerThan(javax.xml.datatype.Duration)
public int hashCode()
hashCode
in class Duration
Object.hashCode()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |