|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--net.sf.molae.pipe.basic.ObjectProxy
|
+--net.sf.molae.pipe.basic.MapProxy
|
+--net.sf.molae.pipe.sorted.MapAsSortedMap
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.
| Inner classes inherited from class java.util.Map |
Map.Entry |
| Field Summary | |
protected static Object |
NEGATIVE_INFINITY
Defines negative infinity regardless of the type of comparison. |
protected static Object |
POSITIVE_INFINITY
Defines positive infinity regardless of the type of comparison. |
| Constructor Summary | |
|
MapAsSortedMap(Map base,
Comparator comparator)
Constructs a MapAsSortedMap object. |
protected |
MapAsSortedMap(Map base,
Comparator comparator,
Object fromKey,
Object toKey)
Creates a new MapAsSortedMap with the specified
properties. |
| Method Summary | |
Comparator |
comparator()
Returns the comparator associated with this sorted map, or null if it uses its elements' natural ordering. |
protected int |
compare(Object o1,
Object o2)
Compares its two arguments for order using a comparator with infinities. |
Object |
firstKey()
Returns the first (lowest) key currently in this sorted map. |
protected Comparator |
getBoundComparator()
Returns the comparator of this set taking infinity into account. |
protected Object |
getFromKey()
Returns the lower bound of this SortedMap. |
protected SortedMap |
getSubMap(Object fromKey,
Object toKey)
Common method to create head, tail and sub maps. |
protected Object |
getToKey()
Returns the upper bound of this SortedMap. |
SortedMap |
headMap(Object toKey)
Returns a view of the portion of this sorted map whose keys are strictly less than toKey. |
Object |
lastKey()
Returns the last (highest) key currently in this sorted map. |
SortedMap |
subMap(Object fromKey,
Object toKey)
Returns a view of the portion of this Map whose keys range from fromKey, inclusive, to toKey, exclusive. |
SortedMap |
tailMap(Object 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, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface java.util.Map |
clear, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, values |
| Field Detail |
protected static final Object NEGATIVE_INFINITY
protected static final Object POSITIVE_INFINITY
| Constructor Detail |
protected MapAsSortedMap(Map base,
Comparator comparator,
Object fromKey,
Object 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.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
or if the base map is null.
public MapAsSortedMap(Map base,
Comparator 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 comparator()
null if it uses its elements' natural ordering.comparator in interface SortedMapnull if it uses its elements' natural orderingprotected Comparator getBoundComparator()
protected final Object getFromKey()
SortedMap.
Returns NEGATIVE_INFINITY if no such bound was specified.SortedMap.protected final Object getToKey()
SortedMap.
Returns POSITIVE_INFINITY if no such bound was specified.SortedMap
protected final int compare(Object o1,
Object o2)
o1 - first key to compareo2 - second key to compare
protected SortedMap getSubMap(Object fromKey,
Object toKey)
fromKey - low endpoint (inclusive) of the subMap.toKey - high endpoint (exclusive) of the subMap.
public SortedMap subMap(Object fromKey,
Object toKey)
getSubMap.subMap in interface SortedMapfromKey - 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 headMap(Object toKey)
toKey.
This implementation calls getSubMap() with the
the fromKey of this SortedMap and
the specified toKey.headMap in interface SortedMaptoKey - 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 tailMap(Object fromKey)
fromKey.
This implementation calls getSubMap() with
the specified fromKey and
the toKey of this SortedMap.tailMap in interface SortedMapfromKey - 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 Object firstKey()
keySet iterator.firstKey in interface SortedMapNoSuchElementException - if this map is empty.public Object lastKey()
keySet iterator.lastKey in interface SortedMapNoSuchElementException - if this map is empty.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||