QJCC homepage

biz.chitec.quarterback.util
Class EDateMultiRange

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

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

Multiple date ranges in one storage. The EDateMultiRange knows about automatically splitting and unifying a time range. It implements true versions of unite(), intersect() and remainder(). The multirange has a correct understanding of an empty range (being an empty list of ranges). Internally, this class manages a list of ranges. for the sake of efficiency, this class can perform its work somewhen between the call to a changing method and the query of the result, including the query method itself.

Version:
$Id: ae91b3e0a57b6bc3b6cfa9b173be21a10effb2e5 $
Author:
cantamen/Dirk Hillbrecht 2006 Distributed under the terms of the GNU LGPL.
See Also:
Serialized Form

Field Summary
private  boolean normalized
           
private  java.util.List subranges
           
 
Constructor Summary
EDateMultiRange()
          Creates an empty multirange.
EDateMultiRange(EDateMultiRange o)
          Creates a new and completely independant copy of the given multirange.
EDateMultiRange(EDateRange r)
          Creates a multi range containing only the given range.
 
Method Summary
 int compareTo(java.lang.Object o)
          Compares this object with the specified object for order.
 boolean equals(java.lang.Object o)
          true iff o is a EDateMultiRange and starts and ends at the same times as this.
 int getChunkCount()
          Returns the count of non-linear chunks.
 java.util.List getChunks()
          Return the chunks of multirange.
 EDateRange getEnvelope()
          Return the minimum envelope of the multirange, i.e. the time range from the first subrange's beginning to the end of the last range.
 void intersect(EDateMultiRange other)
          Intersect the multirange with another timerange.
 boolean isEmpty()
          Returns whether the multirange is empty, i.e. there are no subranges left.
 boolean isSingular()
          Returns whether the multirange is sigular, i.e. there is exactly one subrange.
private  void normalize()
          Normlizes the multirange internally.
 void remainder(EDateMultiRange other)
          Calculates the remainder of this against all chunks of other.
 void remainder(EDateRange other)
          Calculates remainder of this multi range with the other date range.
 java.lang.String toString()
          returns String representation of this.
 void unite(EDateMultiRange other)
          Unite the multirange with all contents of the other multirange
 void unite(EDateRange other)
          Unite the multirange with yet another range.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

subranges

private java.util.List subranges

normalized

private boolean normalized
Constructor Detail

EDateMultiRange

public EDateMultiRange()
Creates an empty multirange.


EDateMultiRange

public EDateMultiRange(EDateMultiRange o)
Creates a new and completely independant copy of the given multirange.


EDateMultiRange

public EDateMultiRange(EDateRange r)
Creates a multi range containing only the given range. The given EDateRange is not copied.

Parameters:
r - A date range to initialize the multirange with.
Method Detail

normalize

private void normalize()
Normlizes the multirange internally. This method must be called before every result computation. During unification and all the other operations, the internal storage is only partly cleaned. Only after normalization, results will be correct.


remainder

public void remainder(EDateRange other)
Calculates remainder of this multi range with the other date range. After the operation, the multirange contains only those time ranges which are not in the given date range.


remainder

public void remainder(EDateMultiRange other)
Calculates the remainder of this against all chunks of other. Only those parts of this remain which are not in any chunk of other. Note that this operation will normalize other while nothing like this happens to this.

Parameters:
other - other list of changes.

unite

public void unite(EDateRange other)
Unite the multirange with yet another range.


unite

public void unite(EDateMultiRange other)
Unite the multirange with all contents of the other multirange


intersect

public void intersect(EDateMultiRange other)
Intersect the multirange with another timerange. After the operation, the multirange contains only those time ranges which are also in the given date range.


getChunkCount

public int getChunkCount()
Returns the count of non-linear chunks.


isEmpty

public boolean isEmpty()
Returns whether the multirange is empty, i.e. there are no subranges left.


isSingular

public boolean isSingular()
Returns whether the multirange is sigular, i.e. there is exactly one subrange.


getChunks

public java.util.List getChunks()
Return the chunks of multirange.


getEnvelope

public EDateRange getEnvelope()
Return the minimum envelope of the multirange, i.e. the time range from the first subrange's beginning to the end of the last range. If there are no subranges, null is returned.

Returns:
Surrounding minimum envelope timerange.

equals

public boolean equals(java.lang.Object o)
true iff o is a EDateMultiRange 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