com.flexive.shared.value
Class DateRange

java.lang.Object
  extended by com.flexive.shared.value.DateRange
All Implemented Interfaces:
java.io.Serializable

public class DateRange
extends java.lang.Object
implements java.io.Serializable

A class to describe an immutable date range

parts of the code are taken from JFreeChart (http://www.jfree.org/jfreechart/index.html) which is released under an LGPL license. Code is taken from org.jfree.data.Range (http://www.koders.com/java/fidBBD43A5DBC05830ABCF1267D7B17BF90BD2B6521.aspx)

Author:
Markus Plesser (markus.plesser@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
See Also:
Serialized Form

Constructor Summary
DateRange(java.util.Date lower, java.util.Date upper)
           
DateRange(java.lang.String dateRange)
           
 
Method Summary
static DateRange combine(DateRange range1, DateRange range2)
          Creates a new range by combining two existing ranges.
 java.util.Date constrain(java.util.Date value)
          Returns the value within the range that is closest to the specified value.
 boolean contains(java.util.Date value)
          Returns true if the range contains the specified value and false otherwise.
 DateRange copy()
          Returns a copy of this DateRange instance.
 boolean equals(java.lang.Object obj)
          Indicates whether some other object is "equal to" this one.
static DateRange expand(DateRange range, double lowerMargin, double upperMargin)
          Creates a new range by adding margins to an existing range.
 java.util.Date getCentralValue()
          Returns the central value for the range.
 long getDuration()
           
 java.util.Date getLower()
           
 java.util.Date getUpper()
           
 int hashCode()
          Returns a hash code value for the object.
 boolean intersects(DateRange range)
          Does range intersect with this DateRange?
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DateRange

public DateRange(java.util.Date lower,
                 java.util.Date upper)

DateRange

public DateRange(java.lang.String dateRange)
Method Detail

copy

public DateRange copy()
Returns a copy of this DateRange instance.

Returns:
a copy of this DateRange instance.

getLower

public java.util.Date getLower()

getUpper

public java.util.Date getUpper()

getDuration

public long getDuration()

intersects

public boolean intersects(DateRange range)
Does range intersect with this DateRange?

Parameters:
range - the DateRange to test for intersection
Returns:
if the ranges intersect

getCentralValue

public java.util.Date getCentralValue()
Returns the central value for the range.

Returns:
The central value.

contains

public boolean contains(java.util.Date value)
Returns true if the range contains the specified value and false otherwise.

Parameters:
value - the value to check
Returns:
true if the range contains the specified value.

constrain

public java.util.Date constrain(java.util.Date value)
Returns the value within the range that is closest to the specified value.

Parameters:
value - the value.
Returns:
The constrained value.

combine

public static DateRange combine(DateRange range1,
                                DateRange range2)
Creates a new range by combining two existing ranges.

Note that:

Parameters:
range1 - the first range (null permitted).
range2 - the second range (null permitted).
Returns:
A new range (possibly null).

expand

public static DateRange expand(DateRange range,
                               double lowerMargin,
                               double upperMargin)
Creates a new range by adding margins to an existing range.

Parameters:
range - the range (null not permitted).
lowerMargin - the lower margin (expressed as a percentage of the range length).
upperMargin - the upper margin (expressed as a percentage of the range length).
Returns:
The expanded range.

equals

public boolean equals(java.lang.Object obj)
Indicates whether some other object is "equal to" this one.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the reference object with which to compare.
Returns:
true if this object is the same as the obj argument; false otherwise.
See Also:
hashCode(), Hashtable

hashCode

public int hashCode()
Returns a hash code value for the object. This method is supported for the benefit of hashtables such as those provided by java.util.Hashtable.

Overrides:
hashCode in class java.lang.Object
Returns:
a hash code value for this object.
See Also:
Object.equals(Object), Hashtable

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object