biweekly.util
Class Duration

java.lang.Object
  extended by biweekly.util.Duration

public class Duration
extends Object

Represents a period of time (for example, "2 hours and 30 minutes").

This class is immutable. Use the Duration.Builder class to construct a new instance, or the parse(java.lang.String) method to parse a duration string.

Examples:

 Duration duration = new Duration.Builder().hours(2).minutes(30).build();
 Duration duration = Duration.parse("PT2H30M");
 

Author:
Michael Angstadt

Nested Class Summary
static class Duration.Builder
          Builds Duration objects.
 
Method Summary
 boolean equals(Object obj)
           
 Integer getDays()
          Gets the number of days.
 Integer getHours()
          Gets the number of hours.
 Integer getMinutes()
          Gets the number of minutes.
 Integer getSeconds()
          Gets the number of seconds.
 Integer getWeeks()
          Gets the number of weeks.
 int hashCode()
           
 boolean hasTime()
          Determines if any time components are present.
 boolean isPrior()
          Gets whether the duration is negative.
static Duration parse(String value)
          Parses a duration string.
 String toString()
          Converts the duration to its string representation.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

parse

public static Duration parse(String value)
Parses a duration string.

Parameters:
value - the duration string (e.g. "P30DT10H")
Returns:
the parsed duration
Throws:
IllegalArgumentException - if the duration string is invalid

isPrior

public boolean isPrior()
Gets whether the duration is negative.

Returns:
true if it's negative, false if not

getWeeks

public Integer getWeeks()
Gets the number of weeks.

Returns:
the number of weeks or null if not set

getDays

public Integer getDays()
Gets the number of days.

Returns:
the number of days or null if not set

getHours

public Integer getHours()
Gets the number of hours.

Returns:
the number of hours or null if not set

getMinutes

public Integer getMinutes()
Gets the number of minutes.

Returns:
the number of minutes or null if not set

getSeconds

public Integer getSeconds()
Gets the number of seconds.

Returns:
the number of seconds or null if not set

hasTime

public boolean hasTime()
Determines if any time components are present.

Returns:
true if the duration has at least one time component, false if not

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

toString

public String toString()
Converts the duration to its string representation.

Overrides:
toString in class Object
Returns:
the string representation (e.g. "P4DT1H" for "4 days and 1 hour")


Copyright © 2013 Michael Angstadt. All Rights Reserved.