org.apache.axis2.databinding.types
Class Duration

java.lang.Object
  extended by org.apache.axis2.databinding.types.Duration
All Implemented Interfaces:
Serializable

public class Duration
extends Object
implements Serializable

Implementation of the XML Schema type duration. Duration supports a minimum fractional second precision of milliseconds.

See Also:
XML Schema 3.2.6, Serialized Form

Constructor Summary
Duration()
          Default no-arg constructor
Duration(boolean negative, Calendar calendar)
          Constructs Duration from a Calendar.
Duration(boolean negative, int aYears, int aMonths, int aDays, int aHours, int aMinutes, double aSeconds)
           
Duration(String duration)
          Constructs Duration from a String in an xsd:duration format - PnYnMnDTnHnMnS.
 
Method Summary
 long compare(Duration duration)
           
 boolean equals(Object object)
          The equals method compares the time represented by duration object, not its string representation.
 Calendar getAsCalendar()
          Returns duration as a calendar.
 Calendar getAsCalendar(Calendar startTime)
          Returns duration as a calendar.
 int getDays()
           
 int getHours()
           
 int getMinutes()
           
 int getMonths()
           
 double getSeconds()
           
 int getYears()
           
 int hashCode()
           
 boolean isNegative()
           
 void parseDate(String date)
          This method parses the date portion of a String that represents xsd:duration - nYnMnD.
 void parseTime(String time)
          This method parses the time portion of a String that represents xsd:duration - nHnMnS.
 void setDays(int days)
           
 void setHours(int hours)
           
 void setMinutes(int minutes)
           
 void setMonths(int months)
           
 void setNegative(boolean negative)
           
 void setSeconds(double seconds)
          Sets the seconds.
 void setSeconds(int seconds)
          Deprecated. use setSeconds(double) instead
 void setYears(int years)
           
 String toString()
          This returns the xml representation of an xsd:duration object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Duration

public Duration()
Default no-arg constructor


Duration

public Duration(boolean negative,
                int aYears,
                int aMonths,
                int aDays,
                int aHours,
                int aMinutes,
                double aSeconds)
Parameters:
negative -
aYears -
aMonths -
aDays -
aHours -
aMinutes -
aSeconds -

Duration

public Duration(String duration)
         throws IllegalArgumentException
Constructs Duration from a String in an xsd:duration format - PnYnMnDTnHnMnS.

Parameters:
duration - String
Throws:
IllegalArgumentException - if the string doesn't parse correctly.

Duration

public Duration(boolean negative,
                Calendar calendar)
         throws IllegalArgumentException
Constructs Duration from a Calendar.

Parameters:
calendar - Calendar
Throws:
IllegalArgumentException - if the calendar object does not represent any date nor time.
Method Detail

parseTime

public void parseTime(String time)
               throws IllegalArgumentException
This method parses the time portion of a String that represents xsd:duration - nHnMnS.

Parameters:
time -
Throws:
IllegalArgumentException - if time does not match pattern

parseDate

public void parseDate(String date)
               throws IllegalArgumentException
This method parses the date portion of a String that represents xsd:duration - nYnMnD.

Parameters:
date -
Throws:
IllegalArgumentException - if date does not match pattern

isNegative

public boolean isNegative()

getYears

public int getYears()

getMonths

public int getMonths()

getDays

public int getDays()

getHours

public int getHours()

getMinutes

public int getMinutes()

getSeconds

public double getSeconds()

setNegative

public void setNegative(boolean negative)
Parameters:
negative -

setYears

public void setYears(int years)
Parameters:
years -

setMonths

public void setMonths(int months)
Parameters:
months -

setDays

public void setDays(int days)
Parameters:
days -

setHours

public void setHours(int hours)
Parameters:
hours -

setMinutes

public void setMinutes(int minutes)
Parameters:
minutes -

setSeconds

public void setSeconds(int seconds)
Deprecated. use setSeconds(double) instead

Parameters:
seconds -

setSeconds

public void setSeconds(double seconds)
Sets the seconds. NOTE: The fractional value of seconds is rounded up to milliseconds.

Parameters:
seconds - double

toString

public String toString()
This returns the xml representation of an xsd:duration object.

Overrides:
toString in class Object

equals

public boolean equals(Object object)
The equals method compares the time represented by duration object, not its string representation. Hence, a duration object representing 65 minutes is considered equal to a duration object representing 1 hour and 5 minutes.

Overrides:
equals in class Object
Parameters:
object -

compare

public long compare(Duration duration)

hashCode

public int hashCode()
Overrides:
hashCode in class Object

getAsCalendar

public Calendar getAsCalendar()
Returns duration as a calendar. Due to the way a Calendar class works, the values for particular fields may not be the same as obtained through getter methods. For example, if a duration's object getMonths returns 20, a similar call on a calendar object will return 1 year and 8 months.

Returns:
Calendar

getAsCalendar

public Calendar getAsCalendar(Calendar startTime)
Returns duration as a calendar. Due to the way a Calendar class works, the values for particular fields may not be the same as obtained through getter methods. For example, if a Duration's object getMonths returns 20, a similar call on a Calendar object will return 1 year and 8 months.

Parameters:
startTime - Calendar
Returns:
Calendar


Copyright © 2004-2012 The Apache Software Foundation. All Rights Reserved.