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 Comparable<K>,​V> PersistentTreeMap<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.
      • ofComp

        public 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.
        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 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​(Comparator<? super K> c)
        Returns a new empty PersistentTreeMap that will use the specified comparator.
      • comparator

        public 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 SortedMap<K,​V>
      • assoc

        @NotNull
        public @NotNull 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 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 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 Map<K,​V>
        Specified by:
        size in interface Sized
      • entry

        @NotNull
        public @NotNull 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.
        Specified by:
        entry in interface BaseMap<K,​V>
        Specified by:
        entry in interface ImSortedMap<K,​V>