|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.molae.pipe.basic.ObjectProxy<B> net.sf.molae.pipe.basic.MapProxy<B,K,V> net.sf.molae.pipe.sorted.MapAsSortedMap<B,K,V>
public class MapAsSortedMap<B extends Map<K,V>,K,V>
If it can be guaranteed that the iterator of a map
returns elements in sorted key order,
this wrapper can be used to create a SortedMap
implementation.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface java.util.Map |
---|
Map.Entry<K,V> |
Constructor Summary | |
---|---|
|
MapAsSortedMap(B base,
Comparator<? super K> comparator)
Constructs a MapAsSortedMap object. |
protected |
MapAsSortedMap(B base,
Comparator<? super K> comparator,
Comparator<Bound<K>> boundComparator,
Bound<K> fromKey,
Bound<K> toKey)
Creates a new MapAsSortedMap with the specified
properties. |
Method Summary | ||
---|---|---|
Comparator<? super K> |
comparator()
Returns the comparator associated with this sorted map, or null if it uses its elements' natural ordering. |
|
protected int |
compare(Bound<K> o1,
Bound<K> o2)
Compares its two arguments for order using a comparator with infinities. |
|
K |
firstKey()
Returns the first (lowest) key currently in this sorted map. |
|
protected Comparator<Bound<K>> |
getBoundComparator()
Returns the comparator of this set taking infinity into account. |
|
protected Bound<K> |
getFromKey()
Returns the lower bound of this SortedMap . |
|
protected SortedMap<K,V> |
getSubMap(Bound<K> fromKey,
Bound<K> toKey)
Common method to create head, tail and sub maps. |
|
protected Bound<K> |
getToKey()
Returns the upper bound of this SortedMap . |
|
SortedMap<K,V> |
headMap(K toKey)
Returns a view of the portion of this sorted map whose keys are strictly less than toKey . |
|
K |
lastKey()
Returns the last (highest) key currently in this sorted map. |
|
static
|
newInstance(Map<K,V> base,
Comparator<? super K> comparator)
Constructs a MapAsSortedMap object. |
|
SortedMap<K,V> |
subMap(K fromKey,
K toKey)
Returns a view of the portion of this Map whose keys range from fromKey, inclusive, to toKey, exclusive. |
|
SortedMap<K,V> |
tailMap(K fromKey)
Returns a view of the portion of this sorted map whose keys are greater than or equal to fromKey . |
Methods inherited from class net.sf.molae.pipe.basic.MapProxy |
---|
clear, containsKey, containsValue, entrySet, equals, get, isEmpty, keySet, put, putAll, remove, size, values |
Methods inherited from class net.sf.molae.pipe.basic.ObjectProxy |
---|
assertNotNull, getBase, hashCode, toString, toVerboseString |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.SortedMap |
---|
entrySet, keySet, values |
Methods inherited from interface java.util.Map |
---|
clear, containsKey, containsValue, equals, get, hashCode, isEmpty, put, putAll, remove, size |
Constructor Detail |
---|
protected MapAsSortedMap(B base, Comparator<? super K> comparator, Comparator<Bound<K>> boundComparator, Bound<K> fromKey, Bound<K> toKey)
MapAsSortedMap
with the specified
properties.
This constructor is intended for classes that implement both
the SortedMap and its submaps.
base
- the underlying base mapcomparator
- the comparator that will be used to sort this map
A null
value indicates that the keys' natural
ordering should be used.boundComparator
- the comparator that will be used to compare
bounds - used for submapsfromKey
- low endpoint (inclusive) of the subMap.toKey
- high endpoint (exclusive) of the subMap.
ClassCastException
- if FromKey and
toKey cannot be compared to one another using
this Map's comparator (or, if the Map has no comparator,
using natural ordering).
IllegalArgumentException
- if fromKey is greater than
toKey.
NullPointerException
- if fromKey or
toKey is null and this Map uses natural
order, or its comparator does not tolerate null Keys
or if the base map is null
.public MapAsSortedMap(B base, Comparator<? super K> comparator)
base
- the underlying base mapcomparator
- the comparator that will be used to sort this map
A null
value indicates that the keys' natural
ordering should be used.Method Detail |
---|
public final Comparator<? super K> comparator()
null
if it uses its elements' natural ordering.
comparator
in interface SortedMap<K,V>
null
if it uses its elements' natural orderingprotected Comparator<Bound<K>> getBoundComparator()
protected final Bound<K> getFromKey()
SortedMap
.
Returns negative infinity
if no such bound was specified.
SortedMap
.protected final Bound<K> getToKey()
SortedMap
.
Returns positive infinity
if no such bound was specified.
SortedMap
public static <K,V> SortedMap<K,V> newInstance(Map<K,V> base, Comparator<? super K> comparator)
base
- the underlying base mapcomparator
- the comparator that will be used to sort this map
A null
value indicates that the keys' natural
ordering should be used.protected final int compare(Bound<K> o1, Bound<K> o2)
o1
- first key to compareo2
- second key to compare
protected SortedMap<K,V> getSubMap(Bound<K> fromKey, Bound<K> toKey)
fromKey
- low endpoint (inclusive) of the subMap.toKey
- high endpoint (exclusive) of the subMap.
public SortedMap<K,V> subMap(K fromKey, K toKey)
getSubMap
.
subMap
in interface SortedMap<K,V>
fromKey
- low endpoint (inclusive) of the subMap.toKey
- high endpoint (exclusive) of the subMap.
ClassCastException
- if FromKey and
toKey cannot be compared to one another using
this Map's comparator (or, if the Map has no comparator,
using natural ordering).
IllegalArgumentException
- if fromKey is greater than
toKey.
NullPointerException
- if fromKey or
toKey is null and this Map uses natural
order, or its comparator does not tolerate null Keys.public SortedMap<K,V> headMap(K toKey)
toKey
.
This implementation calls getSubMap()
with the
the fromKey
of this SortedMap
and
the specified toKey
.
headMap
in interface SortedMap<K,V>
toKey
- high endpoint (exclusive) of the headMap.
ClassCastException
- if toKey is not compatible
with this map's comparator (or, if the map has no comparator,
if toKey does not implement Comparable).
IllegalArgumentException
- if this map is itself a subMap,
headMap, or tailMap, and toKey is not within the
specified range of the subMap, headMap, or tailMap.
NullPointerException
- if toKey is null and
this sorted map does not tolerate null keys.public SortedMap<K,V> tailMap(K fromKey)
fromKey
.
This implementation calls getSubMap()
with
the specified fromKey
and
the toKey
of this SortedMap
.
tailMap
in interface SortedMap<K,V>
fromKey
- low endpoint (inclusive) of the tailMap.
ClassCastException
- if fromKey is not compatible
with this map's comparator (or, if the map has no comparator,
if fromKey does not implement Comparable).
IllegalArgumentException
- if this map is itself a subMap,
headMap, or tailMap, and fromKey is not within the
specified range of the subMap, headMap, or tailMap.
NullPointerException
- if fromKey is null and
this sorted map does not tolerate null keys.public K firstKey()
keySet
iterator.
firstKey
in interface SortedMap<K,V>
NoSuchElementException
- if this map is empty.public K lastKey()
keySet
iterator.
lastKey
in interface SortedMap<K,V>
NoSuchElementException
- if this map is empty.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |