public class PersistentTreeMap<K,V> extends UnmodMap.AbstractUnmodMap<K,V> implements ImSortedMap<K,V>, Serializable
UnmodMap.AbstractUnmodMap<K,V>, UnmodMap.UnEntry<K,V>
UnmodIterable.AbstractUnmodIterable<T>
Modifier and Type | Field and Description |
---|---|
static PersistentTreeMap |
EMPTY
Be extremely careful with this because it uses the default comparator, which only works for
items that implement Comparable (have a "natural ordering").
|
Modifier and Type | Method and Description |
---|---|
PersistentTreeMap<K,V> |
assoc(K key,
V val)
Returns a new map with the given key/value added.
|
Comparator<? super K> |
comparator()
Returns the comparator used to order the keys in this map, or null if it uses
Function2.DEFAULT_COMPARATOR (for compatibility with java.util.SortedMap).
|
static <K extends Comparable<K>,V> |
empty()
Be extremely careful with this because it uses the default comparator, which only works for
items that implement Comparable (have a "natural ordering").
|
static <K,V> PersistentTreeMap<K,V> |
empty(Comparator<? super K> c)
Returns a new empty PersistentTreeMap that will use the specified comparator.
|
Option<UnmodMap.UnEntry<K,V>> |
entry(K key)
Returns an Option of the key/value pair matching the given key, or Option.none() if the key is
not found.
|
ImSortedSet<Map.Entry<K,V>> |
entrySet()
Returns a view of the mappings contained in this map.
|
boolean |
equals(Object other)
When comparing against a SortedMap, this is correct and O(n) fast, but BEWARE! It is also
compatible with java.util.Map which unfortunately means equality as defined by this method
(and java.util.AbstractMap) is not commutative when comparing ordered and unordered maps (it is
also O(n log n) slow).
|
K |
firstKey()
Returns the first key in this map or throws a NoSuchElementException if the map is empty.
|
Option<UnmodMap.UnEntry<K,V>> |
head()
The first item in this sequence.
|
UnmodSortedIterator<UnmodMap.UnEntry<K,V>> |
iterator()
Returns an iterator over the UnEntries of this map in order.
|
UnmodMap.UnEntry<K,V> |
last()
Returns the last key/value pair in this map, or null if the map is empty.
|
K |
lastKey()
Returns the last key in this map or throws a NoSuchElementException if the map is empty.
|
static <K extends Comparable<K>,V> |
of(Iterable<Map.Entry<K,V>> es)
Returns a new PersistentTreeMap of the given comparable keys and their paired values, skipping
any null Entries.
|
static <K,V> PersistentTreeMap<K,V> |
ofComp(Comparator<? super K> comp,
Iterable<Map.Entry<K,V>> kvPairs)
Returns a new PersistentTreeMap of the specified comparator and the given key/value pairs.
|
int |
size()
Returns the number of key/value mappings in this map.
|
ImSortedMap<K,V> |
subMap(K fromKey,
K toKey)
Return the elements in this map from the start element (inclusive) to the end element
(exclusive)
|
ImSortedMap<K,V> |
tailMap(K fromKey)
Return the elements in this from the given element to the end
|
PersistentTreeMap<K,V> |
without(K key)
Returns a new map with the given key/value removed
|
hashCode, toString
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
assoc, containsKey, get, getOrElse, headMap, keySet
values
clear, compute, computeIfAbsent, computeIfPresent, containsValue, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll
forEach, getOrDefault, hashCode
castFromList, castFromSortedMap, castFromSortedSet, equal, equals
concat, drop, filter, flatMap, foldLeft, foldLeft, hash, hashCode, map, precat, take, takeWhile, toString
forEach, spliterator
toImList, toImMap, toImSet, toImSortedMap, toImSortedSet, toMutableList, toMutableMap, toMutableSet, toMutableSortedMap, toMutableSortedSet
public static final PersistentTreeMap EMPTY
public static <K extends Comparable<K>,V> PersistentTreeMap<K,V> of(Iterable<Map.Entry<K,V>> es)
public static <K,V> PersistentTreeMap<K,V> ofComp(Comparator<? super K> comp, Iterable<Map.Entry<K,V>> kvPairs)
comp
- A comparator (on the keys) that defines the sort order inside the new map. This
becomes a permanent part of the map and all sub-maps or appended maps derived from it. If you
want to use a null key, make sure the comparator treats nulls correctly in all circumstances!kvPairs
- Key/value pairs (to go into the map). In the case of a duplicate key, later
values in the input list overwrite the earlier ones. The resulting map can contain zero or
one null key (if your comparator knows how to sort nulls) and any number of null values. Null
k/v pairs will be silently ignored.public static <K extends Comparable<K>,V> PersistentTreeMap<K,V> empty()
public static <K,V> PersistentTreeMap<K,V> empty(Comparator<? super K> c)
public ImSortedSet<Map.Entry<K,V>> entrySet()
public boolean equals(Object other)
public ImSortedMap<K,V> subMap(K fromKey, K toKey)
public Option<UnmodMap.UnEntry<K,V>> head()
head
in interface UnmodIterable<UnmodMap.UnEntry<K,V>>
public ImSortedMap<K,V> tailMap(K fromKey)
public Comparator<? super K> comparator()
comparator
in interface SortedMap<K,V>
public PersistentTreeMap<K,V> assoc(K key, V val)
assoc
in interface ImSortedMap<K,V>
key
- the key used to look up the value. In the case of a duplicate key, later values
overwrite the earlier ones. The resulting map can contain zero or one null key (if your
comparator knows how to sort nulls) and any number of null values.val
- the value to store in this key.public PersistentTreeMap<K,V> without(K key)
without
in interface ImSortedMap<K,V>
public UnmodSortedIterator<UnmodMap.UnEntry<K,V>> iterator()
iterator
in interface Iterable<UnmodMap.UnEntry<K,V>>
iterator
in interface ImSortedMap<K,V>
iterator
in interface UnmodIterable<UnmodMap.UnEntry<K,V>>
iterator
in interface UnmodSortedIterable<UnmodMap.UnEntry<K,V>>
public K firstKey()
public K lastKey()
public UnmodMap.UnEntry<K,V> last()
public int size()
public Option<UnmodMap.UnEntry<K,V>> entry(K key)
entry
in interface ImSortedMap<K,V>
Copyright © 2017. All rights reserved.