Package org.exolab.castor.types
Class Duration
java.lang.Object
org.exolab.castor.types.Duration
- All Implemented Interfaces:
Serializable
This class is the representation of XML Schema datatype: duration.
This representation does not support the decimal fraction for the lowest order item.
The order relation provided by this implementation does not follow the guidelines of XML Schema Specification that defines only a partial order.
For more information see X3C XML Schema Specification.
- Version:
- $Revision: 7231 $ $Date: 2006-04-25 15:08:23 -0600 (Tue, 25 Apr 2006) $
- Author:
- Arnaud Blandin, Edward Kuns
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns true if the instance of TimeDuration has the same fields of the parameterboolean
Override the java.lang.equals methodshort
getDay()
short
getHour()
long
getMilli()
short
short
getMonth()
short
short
getYear()
int
hashCode()
Overrides the java.lang.Object#hashcode method.boolean
Returns true if the present instance of TimeDuration is greater than the parameterboolean
static Object
parse a String and convert it into a java.lang.Objectstatic Duration
parseDuration
(String str) Parse the given string and return a time duration which represents this string.void
setDay
(short day) void
setHour
(short hour) void
setMilli
(long milli) void
setMinute
(short minute) void
setMonth
(short month) void
void
setSeconds
(short second) void
setValue
(short year, short month, short day, short hour, short minute, short second, long millisecond) Fill in the fields of the duration with the given valuesvoid
setYear
(short year) long
toLong()
Convert a duration into a long This long represents the duration in milliseconds.toString()
Convert a duration into a String conforming to ISO8601 and XML Schema specs
-
Constructor Details
-
Duration
public Duration()default constructor. -
Duration
Constructs a duration from a string.- Parameters:
duration
- the string representation of the duration to create- Throws:
ParseException
- thrown when the string is not a valid duration
-
Duration
public Duration(long l) This constructor fills in the duration fields according to the value of the long by calling setValue.- Parameters:
l
- the long value of the Duration- See Also:
-
-
Method Details
-
setYear
public void setYear(short year) -
setMonth
public void setMonth(short month) -
setDay
public void setDay(short day) -
setHour
public void setHour(short hour) -
setMinute
public void setMinute(short minute) -
setSeconds
public void setSeconds(short second) -
setMilli
public void setMilli(long milli) -
setNegative
public void setNegative() -
setValue
public void setValue(short year, short month, short day, short hour, short minute, short second, long millisecond) Fill in the fields of the duration with the given values- Parameters:
year
- the year valuemonth
- the month valueday
- the day valuehour
- the hour valueminute
- the minute valuesecond
- the second valuemillisecond
- the second value
-
getYear
public short getYear() -
getMonth
public short getMonth() -
getDay
public short getDay() -
getHour
public short getHour() -
getMinute
public short getMinute() -
getSeconds
public short getSeconds() -
getMilli
public long getMilli() -
isNegative
public boolean isNegative() -
toLong
public long toLong()Convert a duration into a long This long represents the duration in milliseconds.
- Returns:
- a long representing the duration
-
toString
Convert a duration into a String conforming to ISO8601 and XML Schema specs -
parse
parse a String and convert it into a java.lang.Object- Parameters:
str
- the string to parse- Returns:
- the java.lang.Object represented by the string
- Throws:
ParseException
- a parse exception is thrown if the string to parse does not follow the rigth format (see the description of this class)
-
parseDuration
Parse the given string and return a time duration which represents this string.
- Parameters:
str
- the string to parse- Returns:
- a TimeDuration instance which represent the string
- Throws:
ParseException
- thrown when the string is not valid
-
hashCode
public int hashCode()Overrides the java.lang.Object#hashcode method. -
equals
Override the java.lang.equals method -
equal
Returns true if the instance of TimeDuration has the same fields of the parameter- Parameters:
duration
- the time duration to compare- Returns:
- true if equal, false if not
-
isGreater
Returns true if the present instance of TimeDuration is greater than the parameterNote This definition does not follow the XML SCHEMA RECOMMENDATION 05022001 the following total order relation is used : givent t1,t2 timeDuration types t1>t2 iff t1.toLong()>t2.toLong()
- Parameters:
duration
- the time duration to compare with the present instance- Returns:
- true if the present instance is the greatest, false if not
-