net.agmodel.physical
Class Interval

java.lang.Object
  |
  +--net.agmodel.physical.Period
        |
        +--net.agmodel.physical.Interval
All Implemented Interfaces:
Cloneable, Comparable, Serializable
Direct Known Subclasses:
MutableInterval

public class Interval
extends Period
implements Cloneable

An interval is a finite period that has a starting and ending time. In contrast, Periods can be open-ended. Intervals are immutable.

See Also:
Serialized Form

Constructor Summary
Interval()
          Creates an Interval with start and end set to the beginning and end of time respecitively;
Interval(Date start, Date end)
          Creates an interval from a starting and ending time.
Interval(Date start, Duration duration)
          Creates an interval from a starting time and duration.
Interval(Duration duration, Date end)
          Creates an interval from a duration and ending time.
 
Method Summary
 Object clone()
           
 double containsTimeQuantities(Duration small)
          Gets the number of Durations in the Interval eg the interval midnight Jan 1, 1999 to midnight Jan 1, 2000 contains 365 subintervals of duration 1 day.
 Duration getDuration()
          Gets the period duration
static Duration getDuration(Date a, Date b)
          Gets the duration between two dates, regardless of their order
 double overlap(Period another)
          Returns the degree of overlap between this |-----| and another |=======| as a ratio: duration of overlap ------------------- duration of this examples |======| |---| returns 1
|=================| |------| returns 0.5
|-----| |======| returns 0
 
Methods inherited from class net.agmodel.physical.Period
coincidesWith, coincidesWith, coincidesWith, compareTo, encompasses, getBeginningOfTime, getEarlierOf, getEnd, getEndOfTime, getLaterOf, getStart, hasBeginning, hasEnd, set, set, set, setEnd, setStart, toString, unionWith
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Interval

public Interval()
Creates an Interval with start and end set to the beginning and end of time respecitively;


Interval

public Interval(Date start,
                Date end)
Creates an interval from a starting and ending time.

Throws:
IllegalArgumentException - if start or end are null.

Interval

public Interval(Duration duration,
                Date end)
Creates an interval from a duration and ending time.

Parameters:
duration - the duration of the interval
end - the ending time of the interval
Throws:
IllegalArgumentException - if end is null

Interval

public Interval(Date start,
                Duration duration)
Creates an interval from a starting time and duration.

Parameters:
start - the starting time of the interval
duration - the duration of the interval
Throws:
IllegalArgumentException - if start is null
Method Detail

overlap

public double overlap(Period another)
Returns the degree of overlap between this
|-----|
and another
|=======|
as a ratio:
 duration of overlap
 -------------------
 duration of this
 
examples
 |======|
  |---|
returns 1
    |=================|
 |------|
returns 0.5
 |-----|
       |======|
returns 0

Parameters:
another - Period which may or may not overlap
Returns:
0 if there is no overlap,
1 if this Period is completely overlapped by another

getDuration

public static Duration getDuration(Date a,
                                   Date b)
Gets the duration between two dates, regardless of their order

Parameters:
a - one date
b - another date
Returns:
the duration as a Duration object

getDuration

public Duration getDuration()
Gets the period duration

Returns:
the duration of the period as a Duration object

containsTimeQuantities

public double containsTimeQuantities(Duration small)
Gets the number of Durations in the Interval eg the interval midnight Jan 1, 1999 to midnight Jan 1, 2000 contains 365 subintervals of duration 1 day.

Returns:
the number of Durations in the Interval

clone

public Object clone()
Overrides:
clone in class Period