org.jdesktop.swingx.calendar
Class DateSpan

java.lang.Object
  extended by org.jdesktop.swingx.calendar.DateSpan

public class DateSpan
extends Object

An immutable representation of a time range. The time range is internally represented as two longs. The methods that take and return Dates create the Dates as needed, so that if you modify returned Dates you will not effect the DateSpan. The end points are inclusive.


Constructor Summary
DateSpan(Date start, Date end)
          Creates a DateSpan between the two end points.
DateSpan(long start, long end)
          Creates a DateSpan between the two end points.
 
Method Summary
 DateSpan add(DateSpan span)
          Returns a new DateSpan that is the union of this DateSpan and span.
 DateSpan add(long start, long end)
          Returns a new DateSpan that is the union of this DateSpan and the passed in span.
 boolean contains(DateSpan span)
          Returns true if this DateSpan contains the specified DateSpan.
 boolean contains(long time)
          Returns whether or not this DateSpan contains the specified time.
 boolean contains(long start, long end)
          Returns whether or not this DateSpan contains the specified date span.
 boolean equals(Object o)
          Indicates whether some other object is "equal to" this one.
 long getEnd()
          Returns the end of the date span.
 Date getEndAsDate()
          Returns the end of the date span as a Date.
 long getStart()
          Returns the start of the date span.
 Date getStartAsDate()
          Returns the start of the date span as a Date.
 int hashCode()
          Returns a hash code value for the object.
 boolean intersects(DateSpan span)
          Returns true if the this DateSpan intersects with the specified DateSpan.
 boolean intersects(long start, long end)
          Returns true if the this DateSpan intersects with the specified time.
 String toString()
          Returns a string representation of the object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DateSpan

public DateSpan(long start,
                long end)
Creates a DateSpan between the two end points.

Parameters:
start - Beginning date
end - Ending date
Throws:
IllegalArgumentException - if start is after end

DateSpan

public DateSpan(Date start,
                Date end)
Creates a DateSpan between the two end points. This is a conveniance constructor that is equivalent to new Date(start.getTime(), end.getTime());.

Parameters:
start - Beginning date
end - Ending date
Method Detail

getStart

public long getStart()
Returns the start of the date span.

Returns:
start of the span.

getEnd

public long getEnd()
Returns the end of the date span.

Returns:
end of the span.

getStartAsDate

public Date getStartAsDate()
Returns the start of the date span as a Date.

Returns:
start of the span.

getEndAsDate

public Date getEndAsDate()
Returns the end of the date span as a Date.

Returns:
end of the span.

contains

public boolean contains(DateSpan span)
Returns true if this DateSpan contains the specified DateSpan.

Parameters:
span - Date to check
Returns:
true if this DateSpan contains span.

contains

public boolean contains(long time)
Returns whether or not this DateSpan contains the specified time.

Parameters:
time - time check
Returns:
true if this DateSpan contains time.

contains

public boolean contains(long start,
                        long end)
Returns whether or not this DateSpan contains the specified date span.

Parameters:
start - Start of time span
end - End of time
Returns:
true if this DateSpan contains the specified date span.

intersects

public boolean intersects(long start,
                          long end)
Returns true if the this DateSpan intersects with the specified time.

Parameters:
start - Start time
end - End time
Returns:
true if this DateSpan intersects with the specified time.

intersects

public boolean intersects(DateSpan span)
Returns true if the this DateSpan intersects with the specified DateSpan.

Parameters:
span - DateSpan to compare to
Returns:
true if this DateSpan intersects with the specified time.

add

public DateSpan add(DateSpan span)
Returns a new DateSpan that is the union of this DateSpan and span.

Parameters:
span - DateSpan to add
Returns:
union of this DateSpan and span

add

public DateSpan add(long start,
                    long end)
Returns a new DateSpan that is the union of this DateSpan and the passed in span.

Parameters:
start - Start of region to add
end - End of region to end
Returns:
union of this DateSpan and start, end

equals

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

The equals method implements an equivalence relation on non-null object references:

The equals method for class Object implements the most discriminating possible equivalence relation on objects; that is, for any non-null reference values x and y, this method returns true if and only if x and y refer to the same object (x == y has the value true).

Note that it is generally necessary to override the hashCode method whenever this method is overridden, so as to maintain the general contract for the hashCode method, which states that equal objects must have equal hash codes.

Overrides:
equals in class Object
Parameters:
o - the reference object with which to compare.
Returns:
true if this object is the same as the obj argument; false otherwise.
See Also:
Object.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.

The general contract of hashCode is:

As much as is reasonably practical, the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically implemented by converting the internal address of the object into an integer, but this implementation technique is not required by the JavaTM programming language.)

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

toString

public String toString()
Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 

Overrides:
toString in class Object
Returns:
a string representation of the object.