sos.dated.util
Class TreeDates

java.lang.Object
  |
  +--sos.dated.util.AbstractDates
        |
        +--sos.dated.util.TreeDates
All Implemented Interfaces:
java.lang.Cloneable, Dates, java.io.Serializable

public class TreeDates
extends AbstractDates
implements Dates, java.io.Serializable, java.lang.Cloneable

An implementation of Dates that uses a Red-Black tree to achieve logarithmic insertions and deletions.

This implementation is serializable and cloneable; however, it is not synchronized. To use it safely in a multi-threaded situation, wrap an instance of the dated set with a call to DatedCollections.synchronizedDates.

Since:
1.0
See Also:
Dates, DatedCollections.synchronizedDates(Dates)

Constructor Summary
TreeDates()
           
TreeDates(Dates dates)
          Creates an instance of TreeDates initialized with the ranges of dates.
 
Method Summary
 Dates addAll(Dates series)
          Adds all date ranges given by dates to this series of dates.
 Dates addRange(java.util.Date from, java.util.Date to)
          Adds a date range to this series of dates.
 void clear()
          Removes all date ranges from this series of dates.
 java.lang.Object clone()
          Creates and returns a copy of this object.
 void complement()
          Modifies this Dates object so that it contains only the ranges not currently in this Dates object.
 DateIterator dateIterator(java.util.Date date)
          Returns an iterator over the date ranges, beginning with from, inclusive, and ending with to, exclusive.
 boolean includes(java.util.Date date)
          Indicates if a date range in this series contains the specified date.
 boolean isEmpty()
          Indicates if this series of dates is empty.
 Dates removeAll(Dates series)
          Removes all dates ranges given by dates from this series of dates.
 Dates removeRange(java.util.Date from, java.util.Date to)
          Removes the specified range from this series of dates.
 Dates retainAll(Dates series)
          Removes all but the date ranges given by dates from this series of dates.
 
Methods inherited from class sos.dated.util.AbstractDates
dateIterator, equals, excludesAll, excludesRange, hashCode, includesAll, includesRange, size, toDateArray, toDateArray, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface sos.dated.util.Dates
dateIterator, equals, excludesAll, excludesRange, hashCode, includesAll, includesRange, size, toDateArray, toDateArray
 

Constructor Detail

TreeDates

public TreeDates()

TreeDates

public TreeDates(Dates dates)
Creates an instance of TreeDates initialized with the ranges of dates.

Parameters:
dates - date ranges for which to initialize this new TreeDates
Throws:
java.lang.NullPointerException - if dates is null
Method Detail

addAll

public Dates addAll(Dates series)
Description copied from interface: Dates
Adds all date ranges given by dates to this series of dates.

The returned value indicates when this series of date ranges changed as a result of the call and is applicable only for the specified date range. It may be read-only, and it is not tied to this Dates object.

Specified by:
addAll in interface Dates
Overrides:
addAll in class AbstractDates
Parameters:
series - series of dates to be added
Returns:
a series of dates indicating the date ranges that were added as a result of the call

addRange

public Dates addRange(java.util.Date from,
                      java.util.Date to)
Description copied from interface: Dates
Adds a date range to this series of dates.

The returned value indicates when this series of date ranges changed as a result of the call and is applicable only for the specified date range. It may be read-only, and it is not tied to this Dates object.

Specified by:
addRange in interface Dates
Overrides:
addRange in class AbstractDates
Parameters:
from - start of the date range, inclusive
to - end of the date range, exclusive
Returns:
a series of dates indicating the date ranges that were added as a result of the call

clear

public void clear()
Description copied from interface: Dates
Removes all date ranges from this series of dates.

Specified by:
clear in interface Dates
Overrides:
clear in class AbstractDates

clone

public java.lang.Object clone()
Creates and returns a copy of this object.

Overrides:
clone in class java.lang.Object
Returns:
a clone of this instance

complement

public void complement()
Description copied from interface: Dates
Modifies this Dates object so that it contains only the ranges not currently in this Dates object.

Specified by:
complement in interface Dates
Overrides:
complement in class AbstractDates

dateIterator

public DateIterator dateIterator(java.util.Date date)
Description copied from interface: Dates
Returns an iterator over the date ranges, beginning with from, inclusive, and ending with to, exclusive.

Specified by:
dateIterator in interface Dates
Specified by:
dateIterator in class AbstractDates
Returns:
an iterator over the date ranges, constrained to the specified range

includes

public boolean includes(java.util.Date date)
Description copied from interface: Dates
Indicates if a date range in this series contains the specified date.

Specified by:
includes in interface Dates
Overrides:
includes in class AbstractDates
Parameters:
date - date to test for inclusion
Returns:
true if this series of dates contains the specified date

isEmpty

public boolean isEmpty()
Description copied from interface: Dates
Indicates if this series of dates is empty.

Specified by:
isEmpty in interface Dates
Overrides:
isEmpty in class AbstractDates
Returns:
true if no date ranges exist in this series

removeAll

public Dates removeAll(Dates series)
Description copied from interface: Dates
Removes all dates ranges given by dates from this series of dates.

The returned value indicates when this series of date ranges changed as a result of the call and is applicable only for the specified date range. It may be read-only, and it is not tied to this Dates object.

Specified by:
removeAll in interface Dates
Overrides:
removeAll in class AbstractDates
Parameters:
series - date ranges to be removed
Returns:
a series of dates indicating the date ranges that were removed as a result of the call

removeRange

public Dates removeRange(java.util.Date from,
                         java.util.Date to)
Description copied from interface: Dates
Removes the specified range from this series of dates.

The returned value indicates when this series of date ranges changed as a result of the call and is applicable only for the specified date range. It may be read-only, and it is not tied to this Dates object.

Specified by:
removeRange in interface Dates
Overrides:
removeRange in class AbstractDates
Parameters:
from - start of date range to remove (inclusive)
to - end of date range to remove (exclusive)
Returns:
a series of dates indicating the date ranges that were removed as a result of the call

retainAll

public Dates retainAll(Dates series)
Description copied from interface: Dates
Removes all but the date ranges given by dates from this series of dates.

The returned value indicates when this series of date ranges changed as a result of the call and is applicable only for the specified date range. It may be read-only, and it is not tied to this Dates object.

Specified by:
retainAll in interface Dates
Overrides:
retainAll in class AbstractDates
Parameters:
series - date ranges to retain
Returns:
a series of dates indicating the date ranges that were removed as a result of the call


Copyright 2003 Side of Software (SOS). All rights reserved.