Class PersistentTreeMap<K,​V>

    • Field Detail

      • EMPTY

        public static final 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"). An attempt to use it with other items will blow up at runtime. Either a withComparator() method will be added, or this will be removed.
    • Method Detail

      • of

        public static <K extends java.lang.Comparable<K>,​V> PersistentTreeMap<K,​V> of​(java.lang.Iterable<java.util.Map.Entry<K,​V>> es)
        Returns a new PersistentTreeMap of the given comparable keys and their paired values, skipping any null Entries.
      • ofComp

        public static <K,​V> PersistentTreeMap<K,​V> ofComp​(java.util.Comparator<? super K> comp,
                                                                      java.lang.Iterable<java.util.Map.Entry<K,​V>> kvPairs)
        Returns a new PersistentTreeMap of the specified comparator and the given key/value pairs.
        Parameters:
        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.
        Returns:
        a new PersistentTreeMap of the specified comparator and the given key/value pairs
      • empty

        public static <K extends java.lang.Comparable<K>,​V> PersistentTreeMap<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"). An attempt to use it with other items will blow up at runtime. Either a withComparator() method will be added, or this will be removed.
      • empty

        public static <K,​V> PersistentTreeMap<K,​V> empty​(java.util.Comparator<? super K> c)
        Returns a new empty PersistentTreeMap that will use the specified comparator.
      • entrySet

        public ImSortedSet<java.util.Map.Entry<K,​V>> entrySet()
        Returns a view of the mappings contained in this map. The set should actually contain UnmodMap.UnEntry items, but that return signature is illegal in Java, so you'll just have to remember.
        Specified by:
        entrySet in interface BaseMap<K,​V>
        Specified by:
        entrySet in interface ImSortedMap<K,​V>
        Specified by:
        entrySet in interface java.util.Map<K,​V>
        Specified by:
        entrySet in interface java.util.SortedMap<K,​V>
        Specified by:
        entrySet in interface UnmodMap<K,​V>
        Specified by:
        entrySet in interface UnmodSortedMap<K,​V>
      • subMap

        public ImSortedMap<K,​V> subMap​(K fromKey,
                                             K toKey)
        Return the elements in this map from the start element (inclusive) to the end element (exclusive)
        Specified by:
        subMap in interface ImSortedMap<K,​V>
        Specified by:
        subMap in interface java.util.SortedMap<K,​V>
        Specified by:
        subMap in interface UnmodSortedMap<K,​V>
      • tailMap

        public ImSortedMap<K,​V> tailMap​(K fromKey)
        Return the elements in this from the given element to the end
        Specified by:
        tailMap in interface ImSortedMap<K,​V>
        Specified by:
        tailMap in interface java.util.SortedMap<K,​V>
        Specified by:
        tailMap in interface UnmodSortedMap<K,​V>
      • comparator

        public java.util.Comparator<? super K> comparator()
        Returns the comparator used to order the keys in this map, or null if it uses Fn2.DEFAULT_COMPARATOR (for compatibility with java.util.SortedMap).
        Specified by:
        comparator in interface java.util.SortedMap<K,​V>
      • assoc

        public PersistentTreeMap<K,​V> assoc​(K key,
                                                  V val)
        Returns a new map with the given key/value added. If the key exists in this map, the new value overwrites the old one. If the key exists with the same value (based on the address of that value in memory, not an equals test), the old map is returned unchanged.
        Specified by:
        assoc in interface BaseMap<K,​V>
        Specified by:
        assoc in interface ImSortedMap<K,​V>
        Parameters:
        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.
        Returns:
        a new PersistentTreeMap of the specified comparator and the given key/value pairs
      • iterator

        public <R> UnmodSortedIterator<R> iterator​(Fn1<org.organicdesign.fp.collections.PersistentTreeMap.Node<K,​V>,​R> aFn)
      • firstKey

        public K firstKey()
        Returns the first key in this map or throws a NoSuchElementException if the map is empty.
        Specified by:
        firstKey in interface java.util.SortedMap<K,​V>
      • lastKey

        public K lastKey()
        Returns the last key in this map or throws a NoSuchElementException if the map is empty.
        Specified by:
        lastKey in interface java.util.SortedMap<K,​V>
      • last

        public UnmodMap.UnEntry<K,​V> last()
        Returns the last key/value pair in this map, or null if the map is empty.
      • size

        public int size()
        Returns the number of key/value mappings in this map.
        Specified by:
        size in interface java.util.Map<K,​V>
        Specified by:
        size in interface Sized