it.amattioli.encapsulate.dates
Class PhysicalDuration

Show UML class diagram
java.lang.Object
  extended by it.amattioli.encapsulate.dates.PhysicalDuration
All Implemented Interfaces:
Duration, Comparable<PhysicalDuration>

public class PhysicalDuration
extends Object
implements Duration, Comparable<PhysicalDuration>


Field Summary
static PhysicalDuration ONE_DAY
           
static PhysicalDuration ONE_HOUR
           
static PhysicalDuration ONE_MINUTE
           
static PhysicalDuration ONE_SECOND
           
static PhysicalDuration ONE_WEEK
           
 
Constructor Summary
PhysicalDuration(Date begin, Date end)
          Constructs a duration given two time points
PhysicalDuration(Day begin, Day end)
          Constructs a duration given two days.
 
Method Summary
 Date after(Date begin)
          Returns the time point obtained summing this duration to the given time point
 Date before(Date begin)
          Returns the time point obtained subtracting this duration to the given time point
 int compareTo(PhysicalDuration interval)
           
 boolean equals(Object o)
           
static PhysicalDuration fromDays(long days)
          Constructs a duration given the number of days.
static PhysicalDuration fromHours(long hours)
          Constructs a duration given the hours
static PhysicalDuration fromMilliseconds(long milliseconds)
          Constructs a duration given the milliseconds
static PhysicalDuration fromMinutes(long minutes)
          Constructs a duration given the minutes
static PhysicalDuration fromSeconds(long seconds)
          Constructs a duration given the seconds
 long getRemainingHours()
           
 long getRemainingMilliseconds()
           
 long getRemainingMinutes()
           
 long getRemainingSeconds()
           
 int hashCode()
           
 long inDays()
          Returns this duration in days
 long inHours()
          Returns this duration in hours
 long inMilliseconds()
          Returns this duration in milliseconds
 long inMinutes()
          Returns this duration in minutes
 long inSeconds()
          Returns this duration in seconds
 Duration plus(Duration d)
          Add this duration to another to obtain another duration.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ONE_SECOND

public static final PhysicalDuration ONE_SECOND

ONE_MINUTE

public static final PhysicalDuration ONE_MINUTE

ONE_HOUR

public static final PhysicalDuration ONE_HOUR

ONE_DAY

public static final PhysicalDuration ONE_DAY

ONE_WEEK

public static final PhysicalDuration ONE_WEEK
Constructor Detail

PhysicalDuration

public PhysicalDuration(Date begin,
                        Date end)
Constructs a duration given two time points

Parameters:
begin - the start time point
end - the end time point
Throws:
NullPointerException - if at least one of the two parameters is null

PhysicalDuration

public PhysicalDuration(Day begin,
                        Day end)
Constructs a duration given two days.

Parameters:
begin - the start day
end - the end day
Throws:
NullPointerException - if at least one of the two parameters is null
Method Detail

fromMilliseconds

public static PhysicalDuration fromMilliseconds(long milliseconds)
Constructs a duration given the milliseconds

Parameters:
milliseconds -
Returns:

fromSeconds

public static PhysicalDuration fromSeconds(long seconds)
Constructs a duration given the seconds

Parameters:
seconds -
Returns:

fromMinutes

public static PhysicalDuration fromMinutes(long minutes)
Constructs a duration given the minutes

Parameters:
minutes -
Returns:

fromHours

public static PhysicalDuration fromHours(long hours)
Constructs a duration given the hours

Parameters:
hours -
Returns:

fromDays

public static PhysicalDuration fromDays(long days)
Constructs a duration given the number of days. Each day is treated as 24 hours. Daylight saving time is ignored

Parameters:
days -
Returns:

inMilliseconds

public long inMilliseconds()
Returns this duration in milliseconds

Returns:

inSeconds

public long inSeconds()
Returns this duration in seconds

Returns:

inMinutes

public long inMinutes()
Returns this duration in minutes

Returns:

inHours

public long inHours()
Returns this duration in hours

Returns:

inDays

public long inDays()
Returns this duration in days

Returns:

getRemainingMilliseconds

public long getRemainingMilliseconds()

getRemainingSeconds

public long getRemainingSeconds()

getRemainingMinutes

public long getRemainingMinutes()

getRemainingHours

public long getRemainingHours()

after

public Date after(Date begin)
Description copied from interface: Duration
Returns the time point obtained summing this duration to the given time point

Specified by:
after in interface Duration
Returns:

before

public Date before(Date begin)
Description copied from interface: Duration
Returns the time point obtained subtracting this duration to the given time point

Specified by:
before in interface Duration
Returns:

plus

public Duration plus(Duration d)
Description copied from interface: Duration
Add this duration to another to obtain another duration.

Specified by:
plus in interface Duration
Returns:

equals

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

hashCode

public int hashCode()
Overrides:
hashCode in class Object

compareTo

public int compareTo(PhysicalDuration interval)
Specified by:
compareTo in interface Comparable<PhysicalDuration>

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2011. All Rights Reserved.