K - the type of keys of the mapK - the type of values of the mappublic class SortedMap<K,V>
extends java.util.TreeMap<K,V>
implements java.lang.Iterable<java.util.Map.Entry<K,V>>
| Modifier and Type | Field and Description |
|---|---|
static long |
serialVersionUID |
| Constructor and Description |
|---|
SortedMap()
Creates an empty IJDK map.
|
SortedMap(java.util.List<Pair<K,V>> elements)
Creates a map from a list of pairs.
|
SortedMap(java.util.Map<K,V> other)
Creates a IJDK map from a JDK one.
|
| Modifier and Type | Method and Description |
|---|---|
static <KeyType,ValueType> |
empty()
Creates an empty tree map.
|
java.util.Set<java.util.Map.Entry<K,V>> |
entries()
Returns the entries, the same as
entrySet. |
V |
fetch(K key)
Returns the value for the given entry.
|
V |
fetch(K key,
V defValue)
Returns the value for the given entry.
|
java.util.Iterator<java.util.Map.Entry<K,V>> |
iterator()
Returns an iterator over the entries, so this map can be used as an iterable in a for-each
block:
|
java.util.Set<K> |
keys()
Returns the keys, the same as
keySet. |
static <KeyType,ValueType> |
of()
Creates an empty tree map.
|
static <KeyType,ValueType> |
of(KeyType k1,
ValueType v1)
Creates a map with one key/value pair.
|
static <KeyType,ValueType> |
of(KeyType k1,
ValueType v1,
KeyType k2,
ValueType v2)
Creates a map with two key/value pairs.
|
static <KeyType,ValueType> |
of(KeyType k1,
ValueType v1,
KeyType k2,
ValueType v2,
KeyType k3,
ValueType v3)
Creates a map with three key/value pairs.
|
static <KeyType,ValueType> |
of(java.util.List<Pair<KeyType,ValueType>> list)
Creates a map from a list of pairs.
|
SortedMap<K,V> |
set(K key,
V value)
Adds or replaces the value for the given key, either of which can be null.
|
ceilingEntry, ceilingKey, clear, clone, comparator, containsKey, containsValue, descendingKeySet, descendingMap, entrySet, firstEntry, firstKey, floorEntry, floorKey, forEach, get, headMap, headMap, higherEntry, higherKey, keySet, lastEntry, lastKey, lowerEntry, lowerKey, navigableKeySet, pollFirstEntry, pollLastEntry, put, putAll, remove, replace, replace, replaceAll, size, subMap, subMap, tailMap, tailMap, valuespublic static final long serialVersionUID
public SortedMap(java.util.List<Pair<K,V>> elements)
elements - the keys and values for the map.public SortedMap(java.util.Map<K,V> other)
other - the JDK map from which to populate this onepublic SortedMap()
public static <KeyType,ValueType> SortedMap<KeyType,ValueType> of()
KeyType - the type of keys of the mapValueType - the type of values of the mapempty()public static <KeyType,ValueType> SortedMap<KeyType,ValueType> empty()
KeyType - the type of keys of the mapValueType - the type of values of the mappublic static <KeyType,ValueType> SortedMap<KeyType,ValueType> of(KeyType k1, ValueType v1)
KeyType - the type of keys of the mapValueType - the type of values of the mapk1 - the first parameterv1 - the first valuepublic static <KeyType,ValueType> SortedMap<KeyType,ValueType> of(KeyType k1, ValueType v1, KeyType k2, ValueType v2)
KeyType - the type of keys of the mapValueType - the type of values of the mapk1 - the first parameterv1 - the first valuek2 - the second parameterv2 - the second valuepublic static <KeyType,ValueType> SortedMap<KeyType,ValueType> of(KeyType k1, ValueType v1, KeyType k2, ValueType v2, KeyType k3, ValueType v3)
KeyType - the type of keys of the mapValueType - the type of values of the mapk1 - the first parameterv1 - the first valuek2 - the second parameterv2 - the second valuek3 - the third parameterv3 - the third valuepublic static <KeyType,ValueType> SortedMap<KeyType,ValueType> of(java.util.List<Pair<KeyType,ValueType>> list)
KeyType - the type of keys of the mapValueType - the type of values of the maplist - the list from which to populate the new mappublic SortedMap<K,V> set(K key, V value)
m.set("x", 1).set("y", 2).set("z", 3).key - the keyvalue - the valuepublic java.util.Set<K> keys()
keySet.public java.util.Set<java.util.Map.Entry<K,V>> entries()
entrySet.public java.util.Iterator<java.util.Map.Entry<K,V>> iterator()
SortedMap<String, Integer> map = SortedMap.<String, Integer>of("one", 1, "two", 2);
for (Map.Entry<String, Integer> it : map) {
// use it.getKey(), it.getValue()
}
public V fetch(K key, V defValue)
key - the keydefValue - the value to use if there is no entry for keydefValue