sos.dated.util
Class Adapters

java.lang.Object
  |
  +--sos.dated.util.Adapters

public class Adapters
extends java.lang.Object

A bridge between dated and non-dated collections. This class provides two ways to disguise a dated collection as a non-dated collection. The first returns a snapshot at the collection at a given date. Since the returned non-dated collections reflect an instant in time, they are unmodifiable. For this approach, use the following methods. Note that there is no need for a DatedValue view because all dated values provide a get method.

The second way requires a date range for which the dated collection does not change. The returned views are modifiable and the changes are applied for the specified date range. These methods are This class also provides methods to disguise a non-dated collection as a dated collection. Each method requires a date range for which the elements in a non-dated collection should appear in the returned dated collection. The returned dated collection is unmodifiable. These methods are: All of these returned views "wrap" an underlying collection. All views are serializable. All views are undefined if the underlying collection changes during the lifetime of the view.

Since:
1.0
See Also:
DatedCollection, DatedSet, DatedList, DatedMap, DatedCollections

Method Summary
static java.util.Collection asCollection(DatedCollection datedCollection, java.util.Date date)
          Returns an unmodifiable non-dated version of the specified dated collection at the specified date.
static java.util.Collection asCollection(DatedCollection datedCollection, java.util.Date from, java.util.Date to)
          Returns a modifiable non-dated version of the specified dated collection for the specified date range.
static DatedCollection asDatedCollection(java.util.Collection collection, java.util.Date from, java.util.Date to)
          Treats a non-dated collection as a dated collection between the specified dates.
static DatedList asDatedList(java.util.List list, java.util.Date from, java.util.Date to)
          Returns an unmodifiable dated view of a list.
static DatedMap asDatedMap(java.util.Map map, java.util.Date from, java.util.Date to)
          Turns a map into a dated sorted map.
static DatedSet asDatedSet(java.util.Set set, java.util.Date from, java.util.Date to)
          Turns a set into a dated set.
static DatedSortedMap asDatedSortedMap(java.util.SortedMap map, java.util.Date from, java.util.Date to)
          Turns a sorted map into a dated sorted map.
static DatedSortedSet asDatedSortedSet(java.util.SortedSet set, java.util.Date from, java.util.Date to)
          Turns a sorted set into a dated sorted set.
static DatedValue asDatedValue(java.lang.Object value, java.util.Date from, java.util.Date to)
          Turns a value into a dated value.
static java.util.List asList(DatedList datedList, java.util.Date date)
          Returns an unmodifiable non-dated version of the specified dated list at the specified date.
static java.util.List asList(DatedList datedList, java.util.Date from, java.util.Date to)
          Returns a modifiable non-dated version of the specified dated list for the specified date range.
static java.util.Map asMap(DatedMap datedMap, java.util.Date date)
          Returns an unmodifiable non-dated version of the specified dated map at the specified date.
static java.util.Map asMap(DatedMap datedMap, java.util.Date from, java.util.Date to)
          Returns a modifiable non-dated version of the specified dated map for the specified date range.
static java.util.Set asSet(DatedSet datedSet, java.util.Date date)
          Returns an unmodifiable non-dated version of the specified dated set at the specified date.
static java.util.Set asSet(DatedSet datedSet, java.util.Date from, java.util.Date to)
          Returns a modifiable non-dated version of the specified dated set for the specified date range.
static java.util.SortedMap asSortedMap(DatedSortedMap datedMap, java.util.Date date)
          Returns an unmodifiable non-dated version of the specified dated sorted map at the specified date.
static java.util.SortedMap asSortedMap(DatedSortedMap datedSortedMap, java.util.Date from, java.util.Date to)
          Returns a modifiable non-dated version of the specified dated sorted map for the specified date range.
static java.util.SortedSet asSortedSet(DatedSortedSet datedSet, java.util.Date date)
          Returns an unmodifiable non-dated version of the specified dated sorted set at the specified date.
static java.util.SortedSet asSortedSet(DatedSortedSet datedSortedSet, java.util.Date from, java.util.Date to)
          Returns a modifiable non-dated version of the specified dated sorted set for the specified date range.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

asCollection

public static java.util.Collection asCollection(DatedCollection datedCollection,
                                                java.util.Date date)
Returns an unmodifiable non-dated version of the specified dated collection at the specified date. Any attempt to update the returned collection will result in an UnsupportedOperationException. The returned collection "wraps" the dated collection. Therefore, it is essential that the client does not modify the dated collection while using the returned collection. The returned collection is serializable only if the dated collection is serializable.

Parameters:
datedCollection - dated collection to treat as non-dated
date - date slice of datedCollection to treat as a Collection
Returns:
an unmodifiable non-dated Collection of datedCollection at date
Throws:
java.lang.NullPointerException - if any argument is null

asList

public static java.util.List asList(DatedList datedList,
                                    java.util.Date date)
Returns an unmodifiable non-dated version of the specified dated list at the specified date. Any attempt to update the returned list will result in an UnsupportedOperationException. The returned collection "wraps" the dated list. Therefore, it is essential that the client does not modify the dated list while using the returned list. The returned list is serializable only if the dated collection is serializable. Also, the returned list implements RandomAccess only if the dated list implements RandomAccess.

Parameters:
datedList - dated list to treat as non-dated
date - date slice of datedList to treat as a List
Returns:
an unmodifiable non-dated List of datedList at date
Throws:
java.lang.NullPointerException - if any argument is null

asSet

public static java.util.Set asSet(DatedSet datedSet,
                                  java.util.Date date)
Returns an unmodifiable non-dated version of the specified dated set at the specified date. Any attempt to update the returned set will result in an UnsupportedOperationException. The returned set "wraps" the dated set. Therefore, it is essential that the client does not modify the dated set while using the returned set. The returned set is serializable only if the dated set is serializable.

Parameters:
datedSet - dated set to treat as non-dated
date - date slice of datedSet to treat as a Set
Returns:
an unmodifiable non-dated Set of datedSet at date
Throws:
java.lang.NullPointerException - if any argument is null

asSortedMap

public static java.util.SortedMap asSortedMap(DatedSortedMap datedMap,
                                              java.util.Date date)
Returns an unmodifiable non-dated version of the specified dated sorted map at the specified date. Any attempt to update the returned map will result in an UnsupportedOperationException. The returned sorted map "wraps" the dated sorted map. Therefore, it is essential that the client does not modify the dated map while using the returned map. The returned map is serializable only if the dated map is serializable.

Parameters:
date - date slice of datedSortedMap to treat as a SortedMap
Returns:
an unmodifiable non-dated SortedMap of datedSortedMap at date
Throws:
java.lang.NullPointerException - if any argument is null

asSortedSet

public static java.util.SortedSet asSortedSet(DatedSortedSet datedSet,
                                              java.util.Date date)
Returns an unmodifiable non-dated version of the specified dated sorted set at the specified date. Any attempt to update the returned set will result in an UnsupportedOperationException. The returned set "wraps" the dated set. Therefore, it is essential that the client does not modify the dated set while using the returned set. The returned set is serializable only if the dated set is serializable.

Parameters:
datedSet - dated sorted set to treat as non-dated
date - date slice of datedSortedSet to treat as a SortedSet
Returns:
an unmodifiable non-dated sortedSet of datedSortedSet at date
Throws:
java.lang.NullPointerException - if any argument is null

asMap

public static java.util.Map asMap(DatedMap datedMap,
                                  java.util.Date date)
Returns an unmodifiable non-dated version of the specified dated map at the specified date. Any attempt to update the returned set will result in an UnsupportedOperationException. The returned map "wraps" the dated map. Therefore, it is essential that the client does not modify the dated map while using the returned map. The returned map is serializable only if the dated map is serializable.

Parameters:
date - date slice of datedMap to treat as a Map
Returns:
an unmodifiable non-dated Map of datedMap at date
Throws:
java.lang.NullPointerException - if any argument is null

asCollection

public static java.util.Collection asCollection(DatedCollection datedCollection,
                                                java.util.Date from,
                                                java.util.Date to)
Returns a modifiable non-dated version of the specified dated collection for the specified date range. The dated collection must be static within this range. Changes made to the returned collection are reflected in the dated collection for the entire date range. The returned collection "wraps" the dated collection. Therefore, it is essential that the client does not modify the dated collection while using the returned collection. The returned collection is serializable only if the dated collection is serializable.

Parameters:
datedCollection - dated collection to treat as non-dated
from - start date (inclusive) of static range of datedCollection to treat as non-dated
to - end date (exclusive) of static range of datedCollection to treat as non-dated
Returns:
a modifiable non-dated Collection of datedCollection reflecting the static range given by from and to
Throws:
java.lang.NullPointerException - if any argument is null
java.lang.IllegalArgumentException - if from does not precede to
DateOutOfRangeException - if datedCollection changes between from and to

asList

public static java.util.List asList(DatedList datedList,
                                    java.util.Date from,
                                    java.util.Date to)
Returns a modifiable non-dated version of the specified dated list for the specified date range. The dated list must be static within this range. Changes made to the returned list are reflected in the dated list for the entire date range. The returned list "wraps" the dated list. Therefore, it is essential that the client does not modify the dated list while using the returned list. The returned list is serializable only if the dated list is serializable. Also, the returned list implements RandomAccess only if the dated list implements RandomAccess.

Parameters:
datedList - dated list to treat as non-dated
from - start date (inclusive) of static range of datedList to treat as non-dated
to - end date (exclusive) of static range of datedList to treat as non-dated
Returns:
a modifiable non-dated List of datedList reflecting the static range given by from and to
Throws:
java.lang.NullPointerException - if any argument is null
java.lang.IllegalArgumentException - if from does not precede to
DateOutOfRangeException - if datedList changes between from and to

asMap

public static java.util.Map asMap(DatedMap datedMap,
                                  java.util.Date from,
                                  java.util.Date to)
Returns a modifiable non-dated version of the specified dated map for the specified date range. The dated map must be static within this range. Changes made to the returned map are reflected in the dated map for the entire date range. The returned map "wraps" the dated map. Therefore, it is essential that the client does not modify the dated map while using the returned map. The returned map is serializable only if the dated map is serializable.

Parameters:
datedMap - dated map to treat as non-dated
from - start date (inclusive) of static range of datedMap to treat as non-dated
to - end date (exclusive) of static range of datedMap to treat as non-dated
Returns:
a modifiable non-dated Map of datedMap reflecting the static range given by from and to
Throws:
java.lang.NullPointerException - if any argument is null
java.lang.IllegalArgumentException - if from does not precede to
DateOutOfRangeException - if datedMap changes between from and to

asSet

public static java.util.Set asSet(DatedSet datedSet,
                                  java.util.Date from,
                                  java.util.Date to)
Returns a modifiable non-dated version of the specified dated set for the specified date range. The dated set must be static within this range. Changes made to the returned set are reflected in the dated set for the entire date range. The returned set "wraps" the dated set. Therefore, it is essential that the client does not modify the dated set while using the returned set. The returned set is serializable only if the dated set is serializable.

Parameters:
datedSet - dated set to treat as non-dated
from - start date (inclusive) of static range of datedSet to treat as non-dated
to - end date (exclusive) of static range of datedSet to treat as non-dated
Returns:
a modifiable non-dated Set of datedSet reflecting the static range given by from and to
Throws:
java.lang.NullPointerException - if any argument is null
java.lang.IllegalArgumentException - if from does not precede to
DateOutOfRangeException - if datedSet changes between from and to

asSortedMap

public static java.util.SortedMap asSortedMap(DatedSortedMap datedSortedMap,
                                              java.util.Date from,
                                              java.util.Date to)
Returns a modifiable non-dated version of the specified dated sorted map for the specified date range. The dated map must be static within this range. Changes made to the returned map are reflected in the dated map for the entire date range. The returned map "wraps" the dated map. Therefore, it is essential that the client does not modify the dated map while using the returned map. The returned map is serializable only if the dated map is serializable.

Parameters:
datedSortedMap - dated sorted map to treat as non-dated
from - start date (inclusive) of static range of datedSortedMap to treat as non-dated
to - end date (exclusive) of static range of datedSortedMap to treat as non-dated
Returns:
a modifiable non-dated SortedMap of datedCollection reflecting the static range given by from and to
Throws:
java.lang.NullPointerException - if any argument is null
java.lang.IllegalArgumentException - if from does not precede to
DateOutOfRangeException - if datedSortedMap changes between from and to

asSortedSet

public static java.util.SortedSet asSortedSet(DatedSortedSet datedSortedSet,
                                              java.util.Date from,
                                              java.util.Date to)
Returns a modifiable non-dated version of the specified dated sorted set for the specified date range. The dated set must be static within this range. Changes made to the returned set are reflected in the dated set for the entire date range. The returned set "wraps" the dated set. Therefore, it is essential that the client does not modify the dated set while using the returned set. The returned set is serializable only if the dated set is serializable.

Parameters:
datedSortedSet - dated sorted set to treat as non-dated
from - start date (inclusive) of static range of datedSortedSet to treat as non-dated
to - end date (exclusive) of static range of datedSortedSet to treat as non-dated
Returns:
a modifiable non-dated SortedSet of datedSortedSet reflecting the static range given by from and to
Throws:
java.lang.NullPointerException - if any argument is null
java.lang.IllegalArgumentException - if from does not precede to
DateOutOfRangeException - if datedSortedSet changes between from and to

asDatedCollection

public static DatedCollection asDatedCollection(java.util.Collection collection,
                                                java.util.Date from,
                                                java.util.Date to)
Treats a non-dated collection as a dated collection between the specified dates. For all other dates, the returned dated collection has no elements. The returned dated collection is serializable only if the non-dated collection is serializable.

Parameters:
collection - collection to treat as dated
from - start date (inclusive) of range for which the returned dated collection should contain the elements of collection
to - end date (exclusive) of range for which the returned dated collection should contain the elements of collection
Returns:
an unmodifiable dated collection containing the elements of collection between from and to
Throws:
java.lang.NullPointerException - if any argument is null
java.lang.IllegalArgumentException - if from does not precede to

asDatedList

public static DatedList asDatedList(java.util.List list,
                                    java.util.Date from,
                                    java.util.Date to)
Returns an unmodifiable dated view of a list. The resulting dated list has the elements of the backing list for the date range [from, to). For all other dates, the dated list has no elements.

Parameters:
list - list to be viewed as dated
from - starting date (inclusive)
to - ending date (exclusive)
Returns:
an unmodifiable dated list backed by the specified list

asDatedMap

public static DatedMap asDatedMap(java.util.Map map,
                                  java.util.Date from,
                                  java.util.Date to)
Turns a map into a dated sorted map.

Parameters:
map - map to be treated as dated
from - start of date range (inclusive) for which the returned dated map has the entries of the specified map
to - end of date range (exclusive) for which the returned dated map has the entries of the specified map
Returns:
an unmodifiable dated map backed by the specified map during the specified date range

asDatedSet

public static DatedSet asDatedSet(java.util.Set set,
                                  java.util.Date from,
                                  java.util.Date to)
Turns a set into a dated set.

Parameters:
set - set to be treated as dated
from - start of date range (inclusive) for which the returned dated set has the elements of the specified set
to - end of date range (exclusive) for which the returned dated set has the elements of the specified set
Returns:
an unmodifiable dated set backed by the specified set during the specified date range

asDatedSortedMap

public static DatedSortedMap asDatedSortedMap(java.util.SortedMap map,
                                              java.util.Date from,
                                              java.util.Date to)
Turns a sorted map into a dated sorted map.

Parameters:
map - sorted map to be treated as dated
from - start of date range (inclusive) for which the returned dated map has the entries of the specified map
to - end of date range (exclusive) for which the returned dated map has the entries of the specified map
Returns:
an unmodifiable dated sorted map backed by the specified map during the specified date range

asDatedSortedSet

public static DatedSortedSet asDatedSortedSet(java.util.SortedSet set,
                                              java.util.Date from,
                                              java.util.Date to)
Turns a sorted set into a dated sorted set.

Parameters:
set - sorted set to be treated as dated
from - start of date range (inclusive) for which the returned dated set has the elements of the specified set
to - end of date range (exclusive) for which the returned dated set has the elements of the specified set
Returns:
an unmodifiable dated sorted set backed by the specified set during the specified date range

asDatedValue

public static DatedValue asDatedValue(java.lang.Object value,
                                      java.util.Date from,
                                      java.util.Date to)
Turns a value into a dated value.

Parameters:
value - value to be treated as dated
from - start of date range (inclusive) for which the returned dated value has the specified value
to - end of date range (exclusive) for which the returned dated value has the specified value
Returns:
an unmodifiable dated value backed by the specified value during the specified date range


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