gov.sandia.cognition.time
Class DefaultDuration

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.time.DefaultDuration
All Implemented Interfaces:
Duration, CloneableSerializable, Serializable, Cloneable, Comparable<Duration>

public class DefaultDuration
extends AbstractCloneableSerializable
implements Duration

A default implementation of the Duration interface. It is implemented storing milliseconds as a double value.

Since:
3.0
Author:
Justin Basilico
See Also:
Serialized Form

Field Summary
static DefaultDuration DAY
          A day in duration.
static DefaultDuration HOUR
          An hour in duration.
static int HOURS_PER_DAY
          There are 24 hours per day.
static DefaultDuration MAX_VALUE
          The maximum value of a duration.
static DefaultDuration MILLISECOND
          A millisecond in duration.
static int MILLISECONDS_PER_DAY
          There are 86400000 milliseoncds per day.
static int MILLISECONDS_PER_HOUR
          There are 3600000 milliseconds per hour.
static int MILLISECONDS_PER_MINUTE
          There are 60000 milliseconds per minute.
static int MILLISECONDS_PER_SECOND
          There are 1000 milliseconds per second.
static DefaultDuration MIN_VALUE
          The minimum value of a duration.
static DefaultDuration MINUTE
          A minute in duration.
static int MINUTES_PER_HOUR
          There are 60 minutes per hour.
static DefaultDuration SECOND
          A second in duration.
static int SECONDS_PER_MINUTE
          There are 60 seconds per minute.
static DecimalFormat THREE_DIGIT_FORMAT
          Formatting used for the toString method that creates numbers of three digits.
static DefaultDuration ZERO
          A zero duration.
 
Constructor Summary
protected DefaultDuration(double milliseconds)
          Creates a new DefaultDuration representing the given number of milliseconds.
 
Method Summary
 Duration absoluteValue()
          Returns the absolute value of this duration.
 int compareTo(Duration other)
           
 Duration divide(double scalar)
          Divides this duration by the given scalar value and returns the result.
 double divide(Duration other)
          Divides this duration by the given duration and returns the ratio.
 boolean equals(Duration other)
          Determines if this duration is equivalent to the given duration.
 boolean equals(Object other)
           
static DefaultDuration fromDays(double days)
          Creates a new DefaultDuration from the given number of days.
static DefaultDuration fromHours(double hours)
          Creates a new DefaultDuration from the given number of hours.
static DefaultDuration fromMilliseconds(double milliseconds)
          Creates a new DefaultDuration from the given number of milliseconds.
static DefaultDuration fromMinutes(double minutes)
          Creates a new DefaultDuration from the given number of minutes.
static DefaultDuration fromSeconds(double seconds)
          Creates a new DefaultDuration from the given number of seconds.
 long getDaysPart()
          Gets the standard minutes part of the time.
 int getHoursPart()
          Gets the standard hours part of the time.
 int getMillisecondsPart()
          Gets the standard milliseconds part of the time.
 int getMinutesPart()
          Gets the standard minutes part of the time.
 int getSecondsPart()
          Gets the standard seconds part of the time.
 double getTotalDays()
          Gets the total number of standard days of this duration.
 double getTotalHours()
          Gets the total number of standard hours of this duration.
 double getTotalMilliseconds()
          Gets the total number of standard milliseconds of this duration.
 double getTotalMinutes()
          Gets the total number of standard minutes of this duration.
 double getTotalSeconds()
          Gets the total number of standard seconds of this duration.
 int hashCode()
           
 Duration minus(Duration other)
          Subtracts the given duration from this duration and returns the difference.
 Duration negative()
          Returns the negative of this duration.
 Duration plus(Duration other)
          Adds this duration to the given duration and returns the sum.
 Duration times(double scalar)
          Multiplies this duration by the given scalar value and returns the product.
 String toString()
           
 
Methods inherited from class gov.sandia.cognition.util.AbstractCloneableSerializable
clone
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MILLISECONDS_PER_SECOND

public static final int MILLISECONDS_PER_SECOND
There are 1000 milliseconds per second.

See Also:
Constant Field Values

SECONDS_PER_MINUTE

public static final int SECONDS_PER_MINUTE
There are 60 seconds per minute.

See Also:
Constant Field Values

MINUTES_PER_HOUR

public static final int MINUTES_PER_HOUR
There are 60 minutes per hour.

See Also:
Constant Field Values

HOURS_PER_DAY

public static final int HOURS_PER_DAY
There are 24 hours per day.

See Also:
Constant Field Values

MILLISECONDS_PER_MINUTE

public static final int MILLISECONDS_PER_MINUTE
There are 60000 milliseconds per minute.

See Also:
Constant Field Values

MILLISECONDS_PER_HOUR

public static final int MILLISECONDS_PER_HOUR
There are 3600000 milliseconds per hour.

See Also:
Constant Field Values

MILLISECONDS_PER_DAY

public static final int MILLISECONDS_PER_DAY
There are 86400000 milliseoncds per day.

See Also:
Constant Field Values

ZERO

public static final DefaultDuration ZERO
A zero duration.


MILLISECOND

public static final DefaultDuration MILLISECOND
A millisecond in duration.


SECOND

public static final DefaultDuration SECOND
A second in duration.


MINUTE

public static final DefaultDuration MINUTE
A minute in duration.


HOUR

public static final DefaultDuration HOUR
An hour in duration.


DAY

public static final DefaultDuration DAY
A day in duration.


MIN_VALUE

public static final DefaultDuration MIN_VALUE
The minimum value of a duration.


MAX_VALUE

public static final DefaultDuration MAX_VALUE
The maximum value of a duration.


THREE_DIGIT_FORMAT

public static final DecimalFormat THREE_DIGIT_FORMAT
Formatting used for the toString method that creates numbers of three digits.

Constructor Detail

DefaultDuration

protected DefaultDuration(double milliseconds)
Creates a new DefaultDuration representing the given number of milliseconds. To create instances of this class, the factory methods (from*) should be used instead of this constructor, to avoid confusion with the types of units used to construct the class.

Parameters:
milliseconds - The duration in milliseconds.
Method Detail

fromMilliseconds

public static DefaultDuration fromMilliseconds(double milliseconds)
Creates a new DefaultDuration from the given number of milliseconds.

Parameters:
milliseconds - The number of milliseconds.
Returns:
The duration representing that number of milliseconds, rounded down to the nearest millisecond.

fromSeconds

public static DefaultDuration fromSeconds(double seconds)
Creates a new DefaultDuration from the given number of seconds.

Parameters:
seconds - The number of seconds.
Returns:
The duration representing that number of seconds, rounded down to the nearest millisecond.

fromMinutes

public static DefaultDuration fromMinutes(double minutes)
Creates a new DefaultDuration from the given number of minutes.

Parameters:
minutes - The number of minutes.
Returns:
The duration representing that number of minutes, rounded down to the nearest millisecond.

fromHours

public static DefaultDuration fromHours(double hours)
Creates a new DefaultDuration from the given number of hours.

Parameters:
hours - The number of hours.
Returns:
The duration representing that number of hours, rounded down to the nearest millisecond.

fromDays

public static DefaultDuration fromDays(double days)
Creates a new DefaultDuration from the given number of days.

Parameters:
days - The number of days.
Returns:
The duration representing that number of days, rounded down to the nearest millisecond.

equals

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

equals

public boolean equals(Duration other)
Description copied from interface: Duration
Determines if this duration is equivalent to the given duration.

Specified by:
equals in interface Duration
Parameters:
other - The other duration.
Returns:
True if this duration is equal to the given duration.

hashCode

public int hashCode()
Overrides:
hashCode in class Object

compareTo

public int compareTo(Duration other)
Specified by:
compareTo in interface Comparable<Duration>

negative

public Duration negative()
Description copied from interface: Duration
Returns the negative of this duration.

Specified by:
negative in interface Duration
Returns:
The negative of this duration.

absoluteValue

public Duration absoluteValue()
Description copied from interface: Duration
Returns the absolute value of this duration.

Specified by:
absoluteValue in interface Duration
Returns:
The absolute value of this duration.

plus

public Duration plus(Duration other)
Description copied from interface: Duration
Adds this duration to the given duration and returns the sum.

Specified by:
plus in interface Duration
Parameters:
other - The other duration.
Returns:
The sum of this duration and the other duration.

minus

public Duration minus(Duration other)
Description copied from interface: Duration
Subtracts the given duration from this duration and returns the difference.

Specified by:
minus in interface Duration
Parameters:
other - The other duration.
Returns:
The difference of this duration and the other duration.

times

public Duration times(double scalar)
Description copied from interface: Duration
Multiplies this duration by the given scalar value and returns the product.

Specified by:
times in interface Duration
Parameters:
scalar - The scalar value.
Returns:
The product of this duration and the scalar value.

divide

public double divide(Duration other)
Description copied from interface: Duration
Divides this duration by the given duration and returns the ratio.

Specified by:
divide in interface Duration
Parameters:
other - The other duration.
Returns:
The result of dividing this duration by the given duration.

divide

public Duration divide(double scalar)
Description copied from interface: Duration
Divides this duration by the given scalar value and returns the result.

Specified by:
divide in interface Duration
Parameters:
scalar - The scalar value.
Returns:
The result of dividing this duration by the given scalar value.

getTotalMilliseconds

public double getTotalMilliseconds()
Description copied from interface: Duration
Gets the total number of standard milliseconds of this duration.

Specified by:
getTotalMilliseconds in interface Duration
Returns:
The total number of standard milliseconds.

getTotalSeconds

public double getTotalSeconds()
Description copied from interface: Duration
Gets the total number of standard seconds of this duration.

Specified by:
getTotalSeconds in interface Duration
Returns:
The total number of standard seconds.

getTotalMinutes

public double getTotalMinutes()
Description copied from interface: Duration
Gets the total number of standard minutes of this duration.

Specified by:
getTotalMinutes in interface Duration
Returns:
The total number of standard minutes.

getTotalHours

public double getTotalHours()
Description copied from interface: Duration
Gets the total number of standard hours of this duration.

Specified by:
getTotalHours in interface Duration
Returns:
The total number of standard hours.

getTotalDays

public double getTotalDays()
Description copied from interface: Duration
Gets the total number of standard days of this duration.

Specified by:
getTotalDays in interface Duration
Returns:
The total number of standard days.

getMillisecondsPart

public int getMillisecondsPart()
Description copied from interface: Duration
Gets the standard milliseconds part of the time. It is in the range of -999 to 999, inclusive.

Specified by:
getMillisecondsPart in interface Duration
Returns:
The standard milliseconds part of the time.

getSecondsPart

public int getSecondsPart()
Description copied from interface: Duration
Gets the standard seconds part of the time. It is in the range of -59 to 59, inclusive.

Specified by:
getSecondsPart in interface Duration
Returns:
The standard seconds part of the time.

getMinutesPart

public int getMinutesPart()
Description copied from interface: Duration
Gets the standard minutes part of the time. It is in the range of -59 to 59, inclusive.

Specified by:
getMinutesPart in interface Duration
Returns:
The standard minutes part of the time.

getHoursPart

public int getHoursPart()
Description copied from interface: Duration
Gets the standard hours part of the time. It is in the range of -23 to 23, inclusive.

Specified by:
getHoursPart in interface Duration
Returns:
The standard hours part of the time.

getDaysPart

public long getDaysPart()
Description copied from interface: Duration
Gets the standard minutes part of the time.

Specified by:
getDaysPart in interface Duration
Returns:
The standard minutes part of the time.

toString

public String toString()
Overrides:
toString in class Object