|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object anon.util.XMLDuration
public class XMLDuration
Immutable representation of a time span as defined in the W3C XML Schema 1.0 specification.
A Duration object represents a period of Gregorian time, which consists of six fields (years, months, days, hours, minutes, and seconds) plus a sign (+/-) field.
The first five fields have non-negative (>=0) integers or null (which represents that the field is not set), and the seconds field has a non-negative decimal or null. A negative sign indicates a negative duration.
This class provides a number of methods that make it easy to use for the duration datatype of XML Schema 1.0 with the errata.
Duration objects only have partial order, where two values A and B maybe either:
For example, 30 days cannot be meaningfully compared to one month.
The #compare(Duration duration)
method implements this
relationship.
See the #isLongerThan(Duration)
method for details about
the order relationship among Duration
objects.
Field Summary | |
---|---|
private static int |
DAYS
|
static int |
DURATION
|
static int |
DURATION_DAYTIME
|
static int |
DURATION_YEARMONTH
|
static int |
EQUAL
|
static int |
GREATER
|
private static int |
HOURS
|
static int |
INDETERMINATE
|
static int |
LESSER
|
private boolean |
m_bNegativeSign
|
private long |
m_calcDays
|
private long |
m_calcHours
|
private long |
m_calcMinutes
|
private long |
m_calcMonths
|
private double |
m_calcSeconds
|
private long |
m_calcYears
|
private long |
m_days
|
private int |
m_hashCode
|
private long |
m_hours
|
private long |
m_minutes
|
private long |
m_months
|
private double |
m_seconds
|
private java.util.Vector |
m_setFields
|
private java.lang.String |
m_theDuration
|
private long |
m_years
|
private static int |
MINUTES
|
private static int |
MONTHS
|
private static java.lang.String[] |
NAMES
|
private static int |
SECONDS
|
private static int |
YEARS
|
Constructor Summary | |
---|---|
XMLDuration()
|
|
XMLDuration(java.lang.String a_duration)
|
|
XMLDuration(XMLDuration a_duration)
|
Method Summary | |
---|---|
int |
compare(XMLDuration a_duration)
Partial order relation comparison with this Duration instance. |
boolean |
equals(java.lang.Object a_duration)
|
long |
getDays()
|
java.lang.Number |
getField(int a_field)
Gets the value of a field. |
java.lang.Number |
getField(java.lang.Object a_field)
|
static java.lang.String |
getFieldName(int a_field)
|
static java.lang.String |
getFieldName(java.lang.Object a_field)
|
java.util.Enumeration |
getFields()
|
long |
getHours()
|
int |
getLastFieldSet()
|
long |
getMinutes()
|
long |
getMonths()
|
double |
getSeconds()
|
int |
getSign()
Returns the sign of this duration in -1,0, or 1. |
java.lang.String |
getXMLSchema()
|
int |
getXMLSchemaType()
Return the name of the XML Schema date/time type that this instance maps to. |
long |
getYears()
|
int |
hashCode()
|
private void |
init()
|
boolean |
isLongerThan(XMLDuration a_duration)
Checks if this duration object is strictly longer than another Duration object. |
boolean |
isSet(int a_field)
Checks if a field is set. |
boolean |
isShorterThan(XMLDuration a_duration)
Checks if this duration object is strictly shorter than another Duration object. |
XMLDuration |
negate()
Returns a new Duration object whose
value is -this . |
private java.lang.String |
parseXMLSchemaPart(int a_field,
java.lang.String a_strXMLDurationPart)
|
private void |
setField(int a_field,
java.lang.Number a_value)
|
java.lang.String |
toString()
Returns a String representation of this Duration Object . |
private java.lang.String |
toString(java.math.BigDecimal bd)
|
private java.lang.String |
toStringJDK5(java.math.BigDecimal bd)
Turns BigDecimal to a string representation. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final int DURATION
public static final int DURATION_DAYTIME
public static final int DURATION_YEARMONTH
public static final int LESSER
public static final int EQUAL
public static final int GREATER
public static final int INDETERMINATE
private static final int YEARS
private static final int MONTHS
private static final int DAYS
private static final int HOURS
private static final int MINUTES
private static final int SECONDS
private static final java.lang.String[] NAMES
private long m_years
private long m_months
private long m_days
private long m_hours
private long m_minutes
private double m_seconds
private boolean m_bNegativeSign
private java.lang.String m_theDuration
private java.util.Vector m_setFields
private long m_calcYears
private long m_calcMonths
private long m_calcDays
private long m_calcHours
private long m_calcMinutes
private double m_calcSeconds
private int m_hashCode
Constructor Detail |
---|
public XMLDuration()
public XMLDuration(XMLDuration a_duration)
public XMLDuration(java.lang.String a_duration) throws XMLParseException
XMLParseException
Method Detail |
---|
private void setField(int a_field, java.lang.Number a_value)
private java.lang.String parseXMLSchemaPart(int a_field, java.lang.String a_strXMLDurationPart) throws XMLParseException
XMLParseException
public java.lang.String getXMLSchema()
public int getXMLSchemaType() throws java.lang.IllegalStateException
Return the name of the XML Schema date/time type that this instance
maps to. Type is computed based on fields that are set,
i.e. isSet(int a_field)
== true
.
Required fields for XML Schema 1.0 Date/Time Datatypes. (timezone is optional for all date/time datatypes) |
||||||
---|---|---|---|---|---|---|
Datatype | year | month | day | hour | minute | second |
DURATION | X | X | X | X | X | X |
DURATION_DAYTIME | X | X | X | X | ||
URATION_YEARMONTH | X | X |
java.lang.IllegalStateException
- If the combination of set fields does not match one of the XML Schema date/time datatypes.public int getSign()
public long getYears()
public long getMonths()
public long getDays()
public long getHours()
public long getMinutes()
public double getSeconds()
public static java.lang.String getFieldName(java.lang.Object a_field)
public static java.lang.String getFieldName(int a_field)
public java.util.Enumeration getFields()
public java.lang.Number getField(java.lang.Object a_field)
public java.lang.Number getField(int a_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.
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
.
java.lang.NullPointerException
- If the field
is null
.public boolean isSet(int a_field)
field
- one of the six Field constants (YEARS,MONTHS,DAYS,HOURS,
MINUTES, or SECONDS.)
public XMLDuration 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.
Duration
object.public int compare(XMLDuration a_duration)
Partial order relation comparison with this Duration
instance.
Comparison result must be in accordance with W3C XML Schema 1.0 Part 2, Section 3.2.7.6.2, Order relation on duration.
Return:
Duration
is shorter than duration
parameterDuration
is equal to duration
parameterDuration
is longer than duration
parameter
duration
- to compare
this
Duration
and duration
parameter as
LESSER, EQUAL,GREATER or INDETERMINATE.
java.lang.NullPointerException
- if duration
is null
.#isShorterThan(Duration)
,
#isLongerThan(Duration)
public boolean equals(java.lang.Object a_duration)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public boolean isLongerThan(XMLDuration a_duration)
Checks if this duration object is strictly longer than
another Duration
object.
Duration X is "longer" than Y if and only if X>Y as defined in the section 3.2.6.2 of the XML Schema 1.0 specification.
For example, "P1D" (one day) > "PT12H" (12 hours) and "P2Y" (two years) > "P23M" (23 months).
duration
- Duration
to test this Duration
against.
java.lang.NullPointerException
- If duration
is null.#isShorterThan(Duration)
,
#compare(Duration duration)
public boolean isShorterThan(XMLDuration a_duration)
Checks if this duration object is strictly shorter than
another Duration
object.
duration
- Duration
to test this Duration
against.
true
if duration
parameter is shorter than this Duration
,
else false
.
java.lang.NullPointerException
- if duration
is null.#isLongerThan(Duration duration)
,
#compare(Duration duration)
public int getLastFieldSet()
public java.lang.String toString()
Returns a String
representation of this Duration
Object
.
The result is formatted according to the XML Schema 1.0 spec and can be always parsed back later into the
equivalent Duration
Object
.
Formally, the following holds for any Duration
Object
x:
new Duration(x.toString()).equals(x)
toString
in class java.lang.Object
null
valid String
representation of this Duration
.private java.lang.String toString(java.math.BigDecimal bd)
private java.lang.String toStringJDK5(java.math.BigDecimal bd)
Turns BigDecimal
to a string representation.
Due to a behavior change in the BigDecimal.toString()
method in JDK 5, this had to be implemented here.
bd
- BigDecimal
to format as a String
String
representation of BigDecimal
private void init()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |