QJCC homepage

biz.chitec.quarterback.util
Class EDateRange

java.lang.Object
  extended bybiz.chitec.quarterback.util.EDateRange
All Implemented Interfaces:
java.lang.Comparable, java.io.Serializable

public class EDateRange
extends java.lang.Object
implements java.lang.Comparable, java.io.Serializable

Java representation of a date range with EDate start and end point. A date range consists simply of a start (inclusive), an end (exclusive). An empty date range can be expressed by start=end. Note however that EDateRange by itself does not enforce any consistency checks on start and end time setting. However, the mathematical operations assume silently that the date range is consistent (end equals or later than start).

Version:
$Id: 357bb5cfaa92b87541876d93d60efbcb71ffeb6f $
Author:
Dirk Hillbrecht 1997-2000, chitec/Dirk Hillbrecht 2000-2003, cantamen/Dirk Hillbrecht 2003-2006. Distributed under the terms of the GNU LGPL .
See Also:
EDateMultiRange, Serialized Form

Field Summary
 EDate end
           
 EDate start
           
 
Constructor Summary
protected EDateRange()
          Empty constructor, only needed for derived classes.
  EDateRange(EDate s, EDate e)
          Constructor with start and end.
  EDateRange(EDateRange b)
          Copy constructor.
 
Method Summary
 int compareTo(java.lang.Object o)
          Compares this object with the specified object for order.
 boolean contains(EDate d)
          Returns whether the given date is in the range, which is interpreted as half-open with the start belonging to it but not the end.
 boolean contains(EDateRange other)
          true iff this contains other completely.
 void cumulate(EDateRange other)
          cumulates this date range with the other.
 EDate duration()
          return duration of the date range
 boolean endsEqual(EDateRange other)
          true iff this and other end at the same time
 boolean endsLaterThan(EDateRange other)
          true iff this ends later than other
 boolean equals(java.lang.Object o)
          true iff o is a EDateRange and starts and ends at the same times as this.
 EDate getEnd()
          return end date
 EDate getStart()
          return stadt date
 void intersect(EDateRange other)
          Intersect myself with another booking.
 boolean isCorrect()
          returns whether the date range ends later than it starts
 boolean isEmpty()
          Returns whether the date range is empty, i.e. start and end are equal
 boolean overlaps(EDateRange other)
          true iff this and other overlap anyhow.
 EDateRange remainder(EDateRange other)
          calculates remainder of this date range with the other date range.
 void setEnd(EDate d)
          Set the end time of the interval.
 void setStart(EDate d)
          Set the start time of the interval.
 boolean startsEqual(EDateRange other)
          true iff this and other start at the same time
 boolean startsLaterThan(EDateRange other)
          true iff this starts later than other.
 java.lang.String toString()
          returns String representation of this.
 void unite(EDateRange other)
          unifies this date range with the other.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

start

public EDate start

end

public EDate end
Constructor Detail

EDateRange

protected EDateRange()
Empty constructor, only needed for derived classes.


EDateRange

public EDateRange(EDate s,
                  EDate e)
Constructor with start and end. Note the both dates are not copied by the constructor.

Parameters:
s - Start date of the date range
e - End date of the date range

EDateRange

public EDateRange(EDateRange b)
Copy constructor. Note that this constructor actually does copy start and end date. Both range objects are completely independent from each other (as the contract for a copy constructor says).

Parameters:
b - Copy source
Method Detail

setStart

public void setStart(EDate d)
Set the start time of the interval. Note that this method does not copy the given date and does not do any consistency checks.

Parameters:
d - New start date

setEnd

public void setEnd(EDate d)
Set the end time of the interval. Note that this method does not copy the given date and does not do any consistency checks.

Parameters:
d - New end date

getStart

public EDate getStart()
return stadt date


getEnd

public EDate getEnd()
return end date


isCorrect

public boolean isCorrect()
returns whether the date range ends later than it starts


isEmpty

public boolean isEmpty()
Returns whether the date range is empty, i.e. start and end are equal


startsLaterThan

public boolean startsLaterThan(EDateRange other)
true iff this starts later than other.


startsEqual

public boolean startsEqual(EDateRange other)
true iff this and other start at the same time


endsLaterThan

public boolean endsLaterThan(EDateRange other)
true iff this ends later than other


endsEqual

public boolean endsEqual(EDateRange other)
true iff this and other end at the same time


duration

public EDate duration()
return duration of the date range


overlaps

public boolean overlaps(EDateRange other)
true iff this and other overlap anyhow. As end dates are exclusive, this method returns false if the one's start is the other's end.


contains

public boolean contains(EDate d)
Returns whether the given date is in the range, which is interpreted as half-open with the start belonging to it but not the end.

Parameters:
d - Date in question
Returns:
true whether the interval contains d where equality to start is included, equality to end not.

contains

public boolean contains(EDateRange other)
true iff this contains other completely. This method returns true on equality.


remainder

public EDateRange remainder(EDateRange other)
calculates remainder of this date range with the other date range. If this date range is split into two halfs, the later half is returned, otherwise null is returned. If remainder is zero, end of this is set to start of this.


unite

public void unite(EDateRange other)
unifies this date range with the other. If they do not overlap, an ArithmeticException is thrown


intersect

public void intersect(EDateRange other)
Intersect myself with another booking. This is shortened in a way that only the part in common with other is kept. If this and other have no time in common, this gets the same start and end time (which can be anything).

Parameters:
other - Another time range to intersect this with

cumulate

public void cumulate(EDateRange other)
cumulates this date range with the other. The duration of the other date range is added to the end of this date range.


equals

public boolean equals(java.lang.Object o)
true iff o is a EDateRange and starts and ends at the same times as this.


compareTo

public int compareTo(java.lang.Object o)
Compares this object with the specified object for order.

Specified by:
compareTo in interface java.lang.Comparable

toString

public java.lang.String toString()
returns String representation of this.


QJCC homepage