Class GDurationBuilder
- All Implemented Interfaces:
Serializable,GDurationSpecification
public class GDurationBuilder extends Object implements GDurationSpecification, Serializable
GDurations.- See Also:
- Serialized Form
-
Constructor Summary
Constructors Constructor Description GDurationBuilder()Constructs an empty GDurationBuilder representing zero seconds.GDurationBuilder(int sign, int year, int month, int day, int hour, int minute, int second, BigDecimal fraction)Constructs a GDurationBuilder with the specified sign, year, month, day, hours, minutes, seconds, and optional fractional seconds.GDurationBuilder(String s)Constructs a GDuration from a lexical representation.GDurationBuilder(GDurationSpecification gDuration)Constructs a GDurationBuilder from another GDurationBuilderSpecification. -
Method Summary
Modifier and Type Method Description voidaddGDuration(GDurationSpecification duration)Adds to this duration.Objectclone()Builds another GDurationBuilder with the same value as this one.intcompareToGDuration(GDurationSpecification duration)Comparison to another GDuration.intgetDay()Gets the day-of-month component.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.booleanisImmutable()All GDuration instances return true.booleanisValid()Returns true if all of the individual components of the duration are nonnegative.voidnormalize()Normalize a duration value.voidsetDay(int day)Sets the day component.voidsetFraction(BigDecimal fraction)Sets the fraction-of-second component.voidsetHour(int hour)Sets the hour component.voidsetMinute(int minute)Sets the minute component.voidsetMonth(int month)Sets the month component.voidsetSecond(int second)Sets the second component.voidsetSign(int sign)Sets the sign.voidsetYear(int year)Sets the year component.static StringstripTrailingZeros(String s)voidsubtractGDuration(GDurationSpecification duration)Subtracts from this duration.GDurationtoGDuration()Builds a GDuration from this GDurationBuilder.static StringtoPlainString(BigDecimal bd)StringtoString()The natural string representation of the duration.
-
Constructor Details
-
GDurationBuilder
public GDurationBuilder()Constructs an empty GDurationBuilder representing zero seconds. -
GDurationBuilder
Constructs a GDuration from a lexical representation. -
GDurationBuilder
public GDurationBuilder(int sign, int year, int month, int day, int hour, int minute, int second, BigDecimal fraction)Constructs a GDurationBuilder 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:
IllegalArgumentException- if the sign is not 1 or -1
-
GDurationBuilder
Constructs a GDurationBuilder from another GDurationBuilderSpecification.
-
-
Method Details
-
clone
Builds another GDurationBuilder with the same value as this one. -
toGDuration
Builds a GDuration from this GDurationBuilder. -
addGDuration
Adds to this duration. Does a fieldwise add, with no normalization. -
subtractGDuration
Subtracts from this duration. Does a fieldwise subtraction, with no normalization. -
setSign
public final void setSign(int sign)Sets the sign. -
setYear
public void setYear(int year)Sets the year component. -
setMonth
public void setMonth(int month)Sets the month component. -
setDay
public void setDay(int day)Sets the day component. -
setHour
public void setHour(int hour)Sets the hour component. -
setMinute
public void setMinute(int minute)Sets the minute component. -
setSecond
public void setSecond(int second)Sets the second component. -
setFraction
Sets the fraction-of-second component. -
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. This value does not necessarily reflect the true direction of the duration if the duration is not normalized or not normalizable.- 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
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
-
normalize
public void normalize()Normalize a duration value. This ensures that months, hours, minutes, seconds, and fractions are positive and within the ranges 0..11, 0..23, 0..59, etc. Negative durations are indicated by a negative sign rather than negative components.Most duration specifications can be normalized to valid durations with all positive components, but not all of them can.
The only situations which cannot be normalized are where the year/month and the day/hour/minute/second offsets are of opposite sign. Days cannot be carried into months since the length of a Gregorian month is variable depending on when the duration is applied. In these cases, this method normalizes the components so that "day" is the only negative component.
-
compareToGDuration
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
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.
-
toPlainString
-
stripTrailingZeros
-