net.agmodel.physical
Class Duration

java.lang.Object
  extended bynet.agmodel.physical.AbstractQuantity
      extended bynet.agmodel.physical.Duration
All Implemented Interfaces:
Cloneable, Comparable, Serializable

public class Duration
extends AbstractQuantity
implements Comparable

This class represents a period of existence or persistence. It is a modified version of classes from World Builders. (Originals available at http://www.magi.com/~wb/quantity.html)

Author:
Jean-Marie Dautelle, Matthew Laurenson
See Also:
Serialized Form

Field Summary
static Duration HALF_HOUR
           
static Duration ONE_DAY
           
static Duration ONE_HOUR
           
static Duration ONE_MILLISECOND
           
static Duration ONE_MINUTE
           
static Duration ONE_MONTH
           
static Duration ONE_SECOND
           
static Duration ONE_YEAR
           
static Duration QUARTER_HOUR
           
static Duration TEN_MINUTES
           
static Duration TWELVE_MINUTES
           
 
Fields inherited from class net.agmodel.physical.AbstractQuantity
COMPLETE, DEVOID, SPATIALLYINTERPOLATED, TEMPORALLYINTERPOLATED, UNINTERPOLATED
 
Constructor Summary
Duration()
          Creates a default Duration of length 0
Duration(Composite c)
          Duration constructor from Composite quantity.
Duration(Date a, Date b)
          Creates a Duration consisting of the absolute time between two Dates
Duration(double value, DurationUnit unit)
          Duration constructor.
 
Method Summary
 Duration add(Duration x)
          Returns a Duration whose value is (this + x).
 Date addToDate(Date input)
          Add this duration onto the input date, and return a new date as the result
 int compareTo(Duration x)
          Compares this Duration with the specified Duration.
 int compareTo(Object o)
          Compares this Duration with the specified Object.
 Duration divide(double coefficient)
          Returns a Duration whose value is (this / coefficient).
 double dividedBy(Duration another)
          Returns the ratio this/another
 double getValue(DurationUnit unit)
          Gets the duration in the specified unit.
 Frequency inverse()
          Returns the Frequency corresponding to this duration period.
static Duration lookup(String name)
           
 Speed multiply(Acceleration a)
          Returns a Speed whose value is (this * a).
 Duration multiply(double coefficient)
          Returns a Duration whose value is (this * coefficient).
 Length multiply(Speed s)
          Returns a Length whose value is (this * s).
static Date oneWithSameTimeAsTwo(Date date1, Date date2)
          Returns the nearest Date <= date1 with the same "time" as date2 eg if date 1 is 0000 on 1/1/99 and date 2 time is 0900 (date doesn't matter) then returns 0900 on 31/12/98
 void setValue(Date a, Date b)
          Sets this Duration to the absolute time between two Dates
 void setValue(double value, DurationUnit unit)
          Sets this Duration using the specified unit.
 Duration subtract(Duration x)
          Returns a Duration whose value is (this - x).
 Date subtractFromDate(Date input)
          Subtract this duration from the input date, and return a new date as the result
 String toString()
          Presents the duration as a string
 
Methods inherited from class net.agmodel.physical.AbstractQuantity
clone, divide, isSpatiallyInterpolated, isTemporallyInterpolated, multiply, toComposite
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ONE_MILLISECOND

public static final Duration ONE_MILLISECOND

ONE_SECOND

public static final Duration ONE_SECOND

ONE_MINUTE

public static final Duration ONE_MINUTE

TEN_MINUTES

public static final Duration TEN_MINUTES

TWELVE_MINUTES

public static final Duration TWELVE_MINUTES

QUARTER_HOUR

public static final Duration QUARTER_HOUR

HALF_HOUR

public static final Duration HALF_HOUR

ONE_HOUR

public static final Duration ONE_HOUR

ONE_DAY

public static final Duration ONE_DAY

ONE_MONTH

public static final Duration ONE_MONTH

ONE_YEAR

public static final Duration ONE_YEAR
Constructor Detail

Duration

public Duration(double value,
                DurationUnit unit)
Duration constructor.

Parameters:
value - the duration in the specified unit (>=0).
unit - the measurement unit being used.
Throws:
IllegalArgumentException - if value > 0

Duration

public Duration(Composite c)
Duration constructor from Composite quantity.

Parameters:
c - the quantity to convert.
Throws:
UnitDimensionException - composite is not a duration.
See Also:
Composite

Duration

public Duration(Date a,
                Date b)
Creates a Duration consisting of the absolute time between two Dates

Parameters:
a - a Date.
b - another Date.

Duration

public Duration()
Creates a default Duration of length 0

Method Detail

oneWithSameTimeAsTwo

public static final Date oneWithSameTimeAsTwo(Date date1,
                                              Date date2)
Returns the nearest Date <= date1 with the same "time" as date2 eg if date 1 is 0000 on 1/1/99 and date 2 time is 0900 (date doesn't matter) then returns 0900 on 31/12/98


getValue

public double getValue(DurationUnit unit)
Gets the duration in the specified unit.

Parameters:
unit - the measurement unit being used.
Returns:
duration in the specified measurement unit.
Throws:
ArrayIndexOutOfBoundsException - unknown measurement unit

setValue

public void setValue(double value,
                     DurationUnit unit)
Sets this Duration using the specified unit.

Parameters:
value - the new duration in the specified unit.
unit - the measurement unit being used.
Throws:
ArrayIndexOutOfBoundsException - unknown measurement unit

setValue

public void setValue(Date a,
                     Date b)
Sets this Duration to the absolute time between two Dates

Parameters:
a - a Date.
b - another Date.

add

public Duration add(Duration x)
Returns a Duration whose value is (this + x).

Parameters:
x - the Duration to be added.
Returns:
(this + x)

subtract

public Duration subtract(Duration x)
Returns a Duration whose value is (this - x).

Parameters:
x - the Duration to be subtracted.
Returns:
(this - x)

multiply

public Duration multiply(double coefficient)
Returns a Duration whose value is (this * coefficient).

Parameters:
coefficient - the dimensionless multiplier.
Returns:
(this * coefficient)

divide

public Duration divide(double coefficient)
Returns a Duration whose value is (this / coefficient).

Parameters:
coefficient - the dimensionless divisor.
Returns:
(this / coefficient)
Throws:
ArithmeticException - coefficient == 0.0

multiply

public Length multiply(Speed s)
Returns a Length whose value is (this * s).

Parameters:
s - the speed multiplier.
Returns:
(this * s)

multiply

public Speed multiply(Acceleration a)
Returns a Speed whose value is (this * a).

Parameters:
a - the acceleration multiplier.
Returns:
(this * a)

inverse

public Frequency inverse()
Returns the Frequency corresponding to this duration period.

Returns:
(1 / this)
Throws:
ArithmeticException - this == 0.0 Second

compareTo

public int compareTo(Duration x)
Compares this Duration with the specified Duration. This method is provided in preference to individual methods for each of the six boolean comparison operators (<, ==, >, >=, !=, <=). The suggested idiom for performing these comparisons is: (x.compareTo(y) <op> 0), where <op> is one of the six comparison operators.

Parameters:
x - Duration to which this Duration is to be compared.
Returns:
-1, 0 or 1 as this Duration is numerically less than, equal to, or greater than x.

compareTo

public int compareTo(Object o)
Compares this Duration with the specified Object. If the Object is a Duration, this method behaves like compareTo(Duration). Otherwise, it throws a ClassCastException (as Durations are comparable only to other Durations).

Specified by:
compareTo in interface Comparable
Parameters:
o - Object to which this Duration is to be compared.
Returns:
a negative number, zero, or a positive number as this Duration is numerically less than, equal to, or greater than o, which must be a Duration.
Throws:
ClassCastException - o is not a Duration.
See Also:
compareTo(Duration), Comparable

subtractFromDate

public Date subtractFromDate(Date input)
Subtract this duration from the input date, and return a new date as the result

Returns:
a new Date which is earlier than the input by the duration.

addToDate

public Date addToDate(Date input)
Add this duration onto the input date, and return a new date as the result

Returns:
a new Date which is later than the input by the duration.

dividedBy

public double dividedBy(Duration another)
Returns the ratio this/another

Returns:
the ratio (dimensionless)

toString

public String toString()
Presents the duration as a string

Overrides:
toString in class AbstractQuantity
Returns:
decimal String representation of this quantity in SI units followed by its SI symbol.

lookup

public static Duration lookup(String name)


Copyright (C) NARC 2001 All Rights Reserved.