saker.util Documentation TaskDoc JavaDoc Packages
package saker.util
public abstract class TransformingSortedMap<MK, MV, K, Vextends TransformingMap<MK, MV, K, V> implements SortedMap<K, V>
Pseudo-Map implementation that dynamically generates the entries for it based on the entries of a subject map.

This map works the same way as TransformingMap, but also implements SortedMap.

A comparator can be specified during the construction of this map, which will be reported when comparator() is called. When this map is used as the argument to a constructor of a sorted map (E.g. TreeMap.TreeMap(SortedMap<K, ? extends V>)), this will cause the constructed map to have the same ordering as this map.

Important: Implementations should ensure that the transformed keys are ordered by the comparator of this constructed map. Violating this may result in undefined behaviour in some implementations.

The use-case for this map is the same as for TransformingMap. See the documentation of that class for more information.

MKThe key type of the source map.
MVThe value type of the source map.
KThe key type of this map.
VThe value type of this map.
Fields
protected final Comparator<super K>
The comparator that this map is ordered by.
Constructors
public
TransformingSortedMap(Map<extends MK, ? extends MV> map)
Creates a new instance with the given map.
public
TransformingSortedMap(Map<extends MK, ? extends MV> map, Comparator<super K> comparator)
Creates a new instance with the given map and comparator.
Methods
public Comparator<super K>
Returns the comparator used to order the keys in this map, or null if this map uses the natural ordering of its keys.
public K
Returns the first (lowest) key currently in this map.
public SortedMap<K, V>
headMap(K toKey)
Returns a view of the portion of this map whose keys are strictly less than toKey.
public K
Returns the last (highest) key currently in this map.
public 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.
public SortedMap<K, V>
tailMap(K fromKey)
Returns a view of the portion of this map whose keys are greater than or equal to fromKey.
protected final Comparator<super K> comparator
The comparator that this map is ordered by.
public TransformingSortedMap(Map<extends MK, ? extends MV> map) throws NullPointerException
Creates a new instance with the given map.
mapThe subject map.
NullPointerExceptionIf the map is null.
public TransformingSortedMap(Map<extends MK, ? extends MV> map, Comparator<super K> comparator) throws NullPointerException
Creates a new instance with the given map and comparator.
mapThe subject map.
comparatorThe comparator.
NullPointerExceptionIf the map is null.
public Comparator<super K> comparator()
Overridden from: SortedMap
Returns the comparator used to order the keys in this map, or null if this map uses the natural ordering of its keys.
the comparator used to order the keys in this map, or null if this map uses the natural ordering of its keys
public K firstKey()
Overridden from: SortedMap
Returns the first (lowest) key currently in this map.
the first (lowest) key currently in this map
public SortedMap<K, V> headMap(K toKey)
Overridden from: SortedMap
Returns a view of the portion of this map whose keys are strictly less than toKey. The returned map is backed by this map, so changes in the returned map are reflected in this map, and vice-versa. The returned map supports all optional map operations that this map supports.

The returned map will throw an IllegalArgumentException on an attempt to insert a key outside its range.

toKeyhigh endpoint (exclusive) of the keys in the returned map
a view of the portion of this map whose keys are strictly less than toKey
public K lastKey()
Overridden from: SortedMap
Returns the last (highest) key currently in this map.
the last (highest) key currently in this map
public SortedMap<K, V> subMap(K fromKey, K toKey)
Overridden from: SortedMap
Returns a view of the portion of this map whose keys range from fromKey, inclusive, to toKey, exclusive. (If fromKey and toKey are equal, the returned map is empty.) The returned map is backed by this map, so changes in the returned map are reflected in this map, and vice-versa. The returned map supports all optional map operations that this map supports.

The returned map will throw an IllegalArgumentException on an attempt to insert a key outside its range.

fromKeylow endpoint (inclusive) of the keys in the returned map
toKeyhigh endpoint (exclusive) of the keys in the returned map
a view of the portion of this map whose keys range from fromKey, inclusive, to toKey, exclusive
public SortedMap<K, V> tailMap(K fromKey)
Overridden from: SortedMap
Returns a view of the portion of this map whose keys are greater than or equal to fromKey. The returned map is backed by this map, so changes in the returned map are reflected in this map, and vice-versa. The returned map supports all optional map operations that this map supports.

The returned map will throw an IllegalArgumentException on an attempt to insert a key outside its range.

fromKeylow endpoint (inclusive) of the keys in the returned map
a view of the portion of this map whose keys are greater than or equal to fromKey