SortedMap to create objects in the map on demand.
When the get(Object) method is called with a key that does not
exist in the map, the factory is used to create the object. The created
object will be added to the map using the requested key.
For instance:
Factory<Date> factory = new Factory<Date>() {
public Date create() {
return new Date();
}
}
SortedMap<String, Date> lazy =
LazySortedMap.lazySortedMap(new HashMap<String, Date>(), factory);
Date date = lazy.get("NOW");
After the above code is executed, date will refer to
a new Date instance. Furthermore, that Date
instance is mapped to the "NOW" key in the map.
Note that LazySortedMap is not synchronized and is not thread-safe.
If you wish to use this map from multiple threads concurrently, you must use
appropriate synchronization. The simplest approach is to wrap this map
using java.. This class may throw
exceptions when accessed by concurrent threads without synchronization.
This class is Serializable from Commons Collections 3.1.
| Modifier and Type | Field and Description |
|---|---|
| private static final long | serialVersionUID
Hides org. |
| Access | Constructor and Description |
|---|---|
| protected | LazySortedMap(final SortedMap<K, V>
the map to decorate, must not be null map, final Factory<? extends V> the factory to use, must not be null factory)Constructor that wraps (not copies). |
| protected | LazySortedMap(final SortedMap<K, V>
the map to decorate, must not be null map, final Transformer<? super K, ? extends V> the factory to use, must not be null factory)Constructor that wraps (not copies). |
| Modifier and Type | Method and Description |
|---|---|
| public Comparator | comparator()
Implements java. null if this map uses the natural ordering of its keys.
|
| public K | firstKey()
Implements java. |
| protected SortedMap | |
| public SortedMap | headMap(final K
high endpoint (exclusive) of the keys in the returned map toKey)Implements java. toKey.
|
| public K | lastKey()
Implements java. |
| public static < the key type K, the value type V> LazySortedMap | Returns: a new lazy sorted mapthe map to decorate, must not be null map, final Factory<? extends V> the factory to use, must not be null factory)Factory method to create a lazily instantiated sorted map. |
| public static < the key type K, the value type V> LazySortedMap | Returns: a new lazy sorted mapthe map to decorate, must not be null map, final Transformer<? super K, ? extends V> the factory to use, must not be null factory)Factory method to create a lazily instantiated sorted map. |
| public SortedMap | subMap(final K
low endpoint (inclusive) of the keys in the returned map fromKey, final K high endpoint (exclusive) of the keys in the returned map toKey)Implements java. fromKey, inclusive, to toKey, exclusive.
|
| public SortedMap | tailMap(final K
low endpoint (inclusive) of the keys in the returned map fromKey)Implements java. fromKey.
|
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Hides org. Serialization version | |
| LazySortedMap | back to summary |
|---|---|
| protected LazySortedMap(final SortedMap<K, V> map, final Factory<? extends V> factory) Constructor that wraps (not copies).
| |
| LazySortedMap | back to summary |
|---|---|
| protected LazySortedMap(final SortedMap<K, V> map, final Transformer<? super K, ? extends V> factory) Constructor that wraps (not copies).
| |
| comparator | back to summary |
|---|---|
| public Comparator Implements java. Doc from java. Returns the comparator used to order the keys in this map, or
| |
| firstKey | back to summary |
|---|---|
| public K firstKey() Implements java. Doc from java. Returns the first (lowest) key currently in this map.
| |
| getSortedMap | back to summary |
|---|---|
| protected SortedMap Gets the map being decorated.
| |
| headMap | back to summary |
|---|---|
| public SortedMap Implements java. Doc from java. Returns a view of the portion of this map whose keys are
strictly less than The returned map will throw an | |
| lastKey | back to summary |
|---|---|
| public K lastKey() Implements java. Doc from java. Returns the last (highest) key currently in this map.
| |
| lazySortedMap | back to summary |
|---|---|
| public static <K, V> LazySortedMap Factory method to create a lazily instantiated sorted map.
| |
| lazySortedMap | back to summary |
|---|---|
| public static <K, V> LazySortedMap Factory method to create a lazily instantiated sorted map.
| |
| subMap | back to summary |
|---|---|
| public SortedMap Implements java. Doc from java. Returns a view of the portion of this map whose keys range from
The returned map will throw an | |
| tailMap | back to summary |
|---|---|
| public SortedMap Implements java. Doc from java. Returns a view of the portion of this map whose keys are
greater than or equal to The returned map will throw an | |