Package org.apache.xmlbeans
Class GDuration
- java.lang.Object
-
- org.apache.xmlbeans.GDuration
-
- All Implemented Interfaces:
java.io.Serializable,GDurationSpecification
public final class GDuration extends java.lang.Object implements GDurationSpecification, java.io.Serializable
Represents an XML Schema-compatible duration.A duration is made up of a number of years, months, days, hours, minutes, seconds, and fractions of seconds. See the XML Schema specification section on xs:duration for details on the rules for comparing durations and adding durations to dates.
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description GDuration()Constructs an empty GDuration representing zero seconds.GDuration(int sign, int year, int month, int day, int hour, int minute, int second, java.math.BigDecimal fraction)Constructs a GDuration with the specified sign, year, month, day, hours, minutes, seconds, and optional fractional seconds.GDuration(java.lang.CharSequence str)Constructs a GDuration from a lexical representation.GDuration(GDurationSpecification gDuration)Constructs a GDuration from another GDurationSpecification.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description GDurationadd(GDurationSpecification duration)Returns a new GDuration which is the sum of this one and the supplied duration.java.lang.Objectclone()Builds another GDate with the same value as this one.intcompareToGDuration(GDurationSpecification duration)Comparison to another GDuration.booleanequals(java.lang.Object obj)Two GDurations are equal if all their fields are equal.intgetDay()Gets the day-of-month component.java.math.BigDecimalgetFraction()Gets the fraction-of-second.intgetHour()Gets the hour-of-day component.intgetMinute()Gets the minute-of-hour component.intgetMonth()Gets the month-of-year component.intgetSecond()Gets the second-of-minute component.intgetSign()Returns the sign of the duration: +1 is forwards and -1 is backwards in time.intgetYear()Gets the year component.inthashCode()booleanisImmutable()All GDuration instances return true.booleanisValid()Returns true if all of the individual components of the duration are nonnegative.GDurationsubtract(GDurationSpecification duration)Returns a new GDuration which is the result of subtracting the supplied duration from this one.java.lang.StringtoString()The natural string representation of the duration.
-
-
-
Constructor Detail
-
GDuration
public GDuration()
Constructs an empty GDuration representing zero seconds.
-
GDuration
public GDuration(java.lang.CharSequence str)
Constructs a GDuration from a lexical representation. The lexical space contains the union of the lexical spaces of all the schema date/time types (except for duration).
-
GDuration
public GDuration(int sign, int year, int month, int day, int hour, int minute, int second, java.math.BigDecimal fraction)Constructs a GDuration with the specified sign, year, month, day, hours, minutes, seconds, and optional fractional seconds.- Parameters:
sign- +1 for a positive duration, -1 for a negative duration- Throws:
java.lang.IllegalArgumentException- if the sign is not 1 or -1
-
GDuration
public GDuration(GDurationSpecification gDuration)
Constructs a GDuration from another GDurationSpecification.
-
-
Method Detail
-
clone
public java.lang.Object clone()
Builds another GDate with the same value as this one.
-
isImmutable
public final boolean isImmutable()
All GDuration instances return true.- Specified by:
isImmutablein interfaceGDurationSpecification
-
getSign
public final int getSign()
Returns the sign of the duration: +1 is forwards and -1 is backwards in time.- Specified by:
getSignin interfaceGDurationSpecification
-
getYear
public final int getYear()
Gets the year component.- Specified by:
getYearin interfaceGDurationSpecification
-
getMonth
public final int getMonth()
Gets the month-of-year component.- Specified by:
getMonthin interfaceGDurationSpecification
-
getDay
public final int getDay()
Gets the day-of-month component.- Specified by:
getDayin interfaceGDurationSpecification
-
getHour
public final int getHour()
Gets the hour-of-day component.- Specified by:
getHourin interfaceGDurationSpecification
-
getMinute
public final int getMinute()
Gets the minute-of-hour component.- Specified by:
getMinutein interfaceGDurationSpecification
-
getSecond
public final int getSecond()
Gets the second-of-minute component.- Specified by:
getSecondin interfaceGDurationSpecification
-
getFraction
public java.math.BigDecimal getFraction()
Gets the fraction-of-second. Range from 0 (inclusive) to 1 (exclusive).- Specified by:
getFractionin interfaceGDurationSpecification
-
isValid
public boolean isValid()
Returns true if all of the individual components of the duration are nonnegative.- Specified by:
isValidin interfaceGDurationSpecification
-
compareToGDuration
public final int compareToGDuration(GDurationSpecification duration)
Comparison to another GDuration.- Returns -1 if this < duration. (less-than)
- Returns 0 if this == duration. (equal)
- Returns 1 if this > duration. (greater-than)
- Returns 2 if this <> duration. (incomparable)
- Specified by:
compareToGDurationin interfaceGDurationSpecification
-
toString
public java.lang.String toString()
The natural string representation of the duration.Any components that are zero are omitted. Note that if the duration is invalid, i.e., it has negative components, those negative components are serialized out here. To check for validity, use the isValid() method; and to normalize most durations to a valid form use the normalize() method.
- Overrides:
toStringin classjava.lang.Object
-
add
public GDuration add(GDurationSpecification duration)
Returns a new GDuration which is the sum of this one and the supplied duration. Does a fieldwise addition, with no normalization.
-
subtract
public GDuration subtract(GDurationSpecification duration)
Returns a new GDuration which is the result of subtracting the supplied duration from this one. Does a fieldwise subtraction, with no normalization.
-
equals
public boolean equals(java.lang.Object obj)
Two GDurations are equal if all their fields are equal. The equals function does not apply normalizatin.- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-