com.liquidatom.derbyscore.domain
Class Duration

java.lang.Object
  extended by com.liquidatom.derbyscore.domain.Duration
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<Duration>

@Immutable
@ThreadSafe
public class Duration
extends java.lang.Object
implements java.io.Serializable, java.lang.Comparable<Duration>

A basic immutable data structure which holds a scalar and a unit for measuring the duration of time.

Author:
Russell Francis (russ@metro-six.com)
See Also:
Serialized Form

Constructor Summary
Duration(long time, java.util.concurrent.TimeUnit unit)
          Construct a new Duration instance with the provided length and unit.
 
Method Summary
 int compareTo(Duration o)
          
 boolean equals(java.lang.Object o)
          
 long getTime()
          Get the length represented by this duration.
 long getTimeInMilliseconds()
          Get the length of time represented in milliseconds.
 java.util.concurrent.TimeUnit getUnit()
          Get the unit that the length of this duration is represented in.
 int hashCode()
          
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Duration

public Duration(long time,
                java.util.concurrent.TimeUnit unit)
Construct a new Duration instance with the provided length and unit.

Parameters:
time - The number of units of duration this instance will represent.
unit - The unit of time this duration will represent.
Method Detail

getTime

public long getTime()
Get the length represented by this duration. This number will be in the units identified by getUnit().

Returns:
The length of this duration.

getUnit

public java.util.concurrent.TimeUnit getUnit()
Get the unit that the length of this duration is represented in.

Returns:
The unit that the length of this duration is represented in.

getTimeInMilliseconds

public long getTimeInMilliseconds()
Get the length of time represented in milliseconds.

Returns:
The length of time represented in milliseconds.

compareTo

public int compareTo(Duration o)

Specified by:
compareTo in interface java.lang.Comparable<Duration>

equals

public boolean equals(java.lang.Object o)

Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()

Overrides:
hashCode in class java.lang.Object