Side of Software
Dated Collections Library 2.0

sos.dated.util
Class Adapters

java.lang.Object
  extended by 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
<E,D> java.util.Collection<E>
asCollection(DatedCollection<E,D> datedCollection, D at)
          Returns an unmodifiable non-dated version of the specified dated collection at the specified date.
static
<E,D> java.util.Collection<E>
asCollection(DatedCollection<E,D> datedCollection, D from, D to)
          Returns a modifiable non-dated version of the specified dated collection for the specified date range.
static
<E,D> DatedCollection<E,D>
asDatedCollection(java.util.Collection<E> collection, D from, D to)
          Treats a non-dated collection as a dated collection between the specified dates.
static
<E,D> DatedList<E,D>
asDatedList(java.util.List<E> list, D from, D to)
          Returns an unmodifiable dated view of a list.
static
<K,V,D> DatedMap<K,V,D>
asDatedMap(java.util.Map<K,V> map, D from, D to)
          Treats a non-dated map as a dated map between the specified dates.
static
<E,D> DatedSet<E,D>
asDatedSet(java.util.Set<E> set, D from, D to)
          Treats a non-dated set as a dated set between the specified dates.
static
<K,V,D> DatedSortedMap<K,V,D>
asDatedSortedMap(java.util.SortedMap<K,V> map, D from, D to)
          Treats a non-dated sorted map as a dated sorted map between the specified dates.
static
<E,D> DatedSortedSet<E,D>
asDatedSortedSet(java.util.SortedSet<E> set, D from, D to)
          Treats a non-dated sorted set as a dated sorted set between the specified dates.
static
<E,D> DatedValue<E,D>
asDatedValue(E value, D from, D to)
          Treats a non-dated value as a dated value between the specified dates.
static
<E,D> java.util.List<E>
asList(DatedList<E,D> datedList, D at)
          Returns an unmodifiable non-dated version of the specified dated list at the specified date.
static
<E,D> java.util.List<E>
asList(DatedList<E,D> datedList, D from, D to)
          Returns a modifiable non-dated version of the specified dated list for the specified date range.
static
<K,V,D> java.util.Map<K,V>
asMap(DatedMap<K,V,D> datedMap, D at)
          Returns an unmodifiable non-dated version of the specified dated map at the specified date.
static
<K,V,D> java.util.Map<K,V>
asMap(DatedMap<K,V,D> datedMap, D from, D to)
          Returns a modifiable non-dated version of the specified dated map for the specified date range.
static
<E,D> java.util.Set<E>
asSet(DatedSet<E,D> datedSet, D at)
          Returns an unmodifiable non-dated version of the specified dated set at the specified date.
static
<E,D> java.util.Set<E>
asSet(DatedSet<E,D> datedSet, D from, D to)
          Returns a modifiable non-dated version of the specified dated set for the specified date range.
static
<K,V,D> java.util.SortedMap<K,V>
asSortedMap(DatedSortedMap<K,V,D> datedSortedMap, D at)
          Returns an unmodifiable non-dated version of the specified dated sorted map at the specified date.
static
<K,V,D> java.util.SortedMap<K,V>
asSortedMap(DatedSortedMap<K,V,D> datedSortedMap, D from, D to)
          Returns a modifiable non-dated version of the specified dated sorted map for the specified date range.
static
<E,D> java.util.SortedSet<E>
asSortedSet(DatedSortedSet<E,D> datedSet, D at)
          Returns an unmodifiable non-dated version of the specified dated sorted set at the specified date.
static
<E,D> java.util.SortedSet<E>
asSortedSet(DatedSortedSet<E,D> datedSortedSet, D from, D 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 <E,D> java.util.Collection<E> asCollection(DatedCollection<E,D> datedCollection,
                                                         D at)
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
at - date slice of datedCollection to treat as a Collection
Returns:
an unmodifiable non-dated Collection of datedCollection at the specified date
Throws:
java.lang.NullPointerException - if any argument is null

asList

public static <E,D> java.util.List<E> asList(DatedList<E,D> datedList,
                                             D at)
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 java.util.RandomAccess only if the dated list implements java.util.RandomAccess.

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

asSet

public static <E,D> java.util.Set<E> asSet(DatedSet<E,D> datedSet,
                                           D at)
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
at - date slice of datedSet to treat as a Set
Returns:
an unmodifiable non-dated Set of datedSet at the specified date
Throws:
java.lang.NullPointerException - if any argument is null

asSortedMap

public static <K,V,D> java.util.SortedMap<K,V> asSortedMap(DatedSortedMap<K,V,D> datedSortedMap,
                                                           D at)
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:
datedSortedMap - dated sorted map to treat as non-dated
at - date slice of datedSortedMap to treat as a SortedMap
Returns:
an unmodifiable non-dated SortedMap of datedSortedMap at the specified date
Throws:
java.lang.NullPointerException - if any argument is null

asSortedSet

public static <E,D> java.util.SortedSet<E> asSortedSet(DatedSortedSet<E,D> datedSet,
                                                       D at)
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
at - date slice of datedSortedSet to treat as a SortedSet
Returns:
an unmodifiable non-dated sortedSet of datedSortedSet at the specified date
Throws:
java.lang.NullPointerException - if any argument is null

asMap

public static <K,V,D> java.util.Map<K,V> asMap(DatedMap<K,V,D> datedMap,
                                               D at)
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:
datedMap - dated map to treat as non-dated
at - date slice of datedMap to treat as a Map
Returns:
an unmodifiable non-dated Map of datedMap at the specified date
Throws:
java.lang.NullPointerException - if any argument is null

asCollection

public static <E,D> java.util.Collection<E> asCollection(DatedCollection<E,D> datedCollection,
                                                         D from,
                                                         D 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:
DateOutOfRangeException - if datedCollection changes between from and to
java.lang.IllegalArgumentException - if from does not precede to
java.lang.NullPointerException - if any argument is null

asList

public static <E,D> java.util.List<E> asList(DatedList<E,D> datedList,
                                             D from,
                                             D 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 java.util.RandomAccess only if the dated list implements java.util.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:
DateOutOfRangeException - if datedList changes between from and to
java.lang.IllegalArgumentException - if from does not precede to
java.lang.NullPointerException - if any argument is null

asMap

public static <K,V,D> java.util.Map<K,V> asMap(DatedMap<K,V,D> datedMap,
                                               D from,
                                               D 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:
DateOutOfRangeException - if datedMap changes between from and to
java.lang.IllegalArgumentException - if from does not precede to
java.lang.NullPointerException - if any argument is null

asSet

public static <E,D> java.util.Set<E> asSet(DatedSet<E,D> datedSet,
                                           D from,
                                           D 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:
DateOutOfRangeException - if datedSet changes between from and to
java.lang.IllegalArgumentException - if from does not precede to
java.lang.NullPointerException - if any argument is null

asSortedMap

public static <K,V,D> java.util.SortedMap<K,V> asSortedMap(DatedSortedMap<K,V,D> datedSortedMap,
                                                           D from,
                                                           D 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:
DateOutOfRangeException - if datedSortedMap changes between from and to
java.lang.IllegalArgumentException - if from does not precede to
java.lang.NullPointerException - if any argument is null

asSortedSet

public static <E,D> java.util.SortedSet<E> asSortedSet(DatedSortedSet<E,D> datedSortedSet,
                                                       D from,
                                                       D 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:
DateOutOfRangeException - if datedSortedSet changes between from and to
java.lang.IllegalArgumentException - if from does not precede to
java.lang.NullPointerException - if any argument is null

asDatedCollection

public static <E,D> DatedCollection<E,D> asDatedCollection(java.util.Collection<E> collection,
                                                           D from,
                                                           D 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.IllegalArgumentException - if from does not precede to
java.lang.NullPointerException - if any argument is null

asDatedList

public static <E,D> DatedList<E,D> asDatedList(java.util.List<E> list,
                                               D from,
                                               D 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
Throws:
java.lang.IllegalArgumentException - if from does not precede to
java.lang.NullPointerException - if any argument is null

asDatedMap

public static <K,V,D> DatedMap<K,V,D> asDatedMap(java.util.Map<K,V> map,
                                                 D from,
                                                 D to)
Treats a non-dated map as a dated map between the specified dates. For all other dates, the returned dated map has no mappings.

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
Throws:
java.lang.IllegalArgumentException - if from does not precede to
java.lang.NullPointerException - if any argument is null

asDatedSet

public static <E,D> DatedSet<E,D> asDatedSet(java.util.Set<E> set,
                                             D from,
                                             D to)
Treats a non-dated set as a dated set between the specified dates. For all other dates, the returned dated set has no elements.

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
Throws:
java.lang.IllegalArgumentException - if from does not precede to
java.lang.NullPointerException - if any argument is null

asDatedSortedMap

public static <K,V,D> DatedSortedMap<K,V,D> asDatedSortedMap(java.util.SortedMap<K,V> map,
                                                             D from,
                                                             D to)
Treats a non-dated sorted map as a dated sorted map between the specified dates. For all other dates, the returned dated map has no mappings.

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
Throws:
java.lang.IllegalArgumentException - if from does not precede to
java.lang.NullPointerException - if any argument is null

asDatedSortedSet

public static <E,D> DatedSortedSet<E,D> asDatedSortedSet(java.util.SortedSet<E> set,
                                                         D from,
                                                         D to)
Treats a non-dated sorted set as a dated sorted set between the specified dates. For all other dates, the returned dated set has no elements.

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
Throws:
java.lang.IllegalArgumentException - if from does not precede to
java.lang.NullPointerException - if any argument is null

asDatedValue

public static <E,D> DatedValue<E,D> asDatedValue(E value,
                                                 D from,
                                                 D to)
Treats a non-dated value as a dated value between the specified dates. For all other dates, the returned dated value is null.

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
Throws:
java.lang.IllegalArgumentException - if from does not precede to
java.lang.NullPointerException - if from or to is null

Side of Software
Dated Collections Library 2.0

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