Class ImmutableSortedMap<K,V>

    • Method Detail

      • of

        public static <K extends Comparable<? super K>,V> ImmutableSortedMap<K,V> of(K k1,
                                                                                     V v1)
        Returns an immutable map containing a single entry.
      • of

        public static <K extends Comparable<? super K>,V> ImmutableSortedMap<K,V> of(K k1,
                                                                                     V v1,
                                                                                     K k2,
                                                                                     V v2)
        Returns an immutable sorted map containing the given entries, sorted by the natural ordering of their keys.
        Throws:
        IllegalArgumentException - if the two keys are equal according to their natural ordering
      • of

        public static <K extends Comparable<? super K>,V> ImmutableSortedMap<K,V> of(K k1,
                                                                                     V v1,
                                                                                     K k2,
                                                                                     V v2,
                                                                                     K k3,
                                                                                     V v3)
        Returns an immutable sorted map containing the given entries, sorted by the natural ordering of their keys.
        Throws:
        IllegalArgumentException - if any two keys are equal according to their natural ordering
      • of

        public static <K extends Comparable<? super K>,V> ImmutableSortedMap<K,V> of(K k1,
                                                                                     V v1,
                                                                                     K k2,
                                                                                     V v2,
                                                                                     K k3,
                                                                                     V v3,
                                                                                     K k4,
                                                                                     V v4)
        Returns an immutable sorted map containing the given entries, sorted by the natural ordering of their keys.
        Throws:
        IllegalArgumentException - if any two keys are equal according to their natural ordering
      • of

        public static <K extends Comparable<? super K>,V> ImmutableSortedMap<K,V> of(K k1,
                                                                                     V v1,
                                                                                     K k2,
                                                                                     V v2,
                                                                                     K k3,
                                                                                     V v3,
                                                                                     K k4,
                                                                                     V v4,
                                                                                     K k5,
                                                                                     V v5)
        Returns an immutable sorted map containing the given entries, sorted by the natural ordering of their keys.
        Throws:
        IllegalArgumentException - if any two keys are equal according to their natural ordering
      • copyOf

        public static <K,V> ImmutableSortedMap<K,V> copyOf(Map<? extends K,? extends V> map)
        Returns an immutable map containing the same entries as map, sorted by the natural ordering of the keys.

        Despite the method name, this method attempts to avoid actually copying the data when it is safe to do so. The exact circumstances under which a copy will or will not be performed are undocumented and subject to change.

        This method is not type-safe, as it may be called on a map with keys that are not mutually comparable.

        Throws:
        ClassCastException - if the keys in map are not mutually comparable
        NullPointerException - if any key or value in map is null
        IllegalArgumentException - if any two keys are equal according to their natural ordering
      • copyOf

        public static <K,V> ImmutableSortedMap<K,V> copyOf(Map<? extends K,? extends V> map,
                                                           Comparator<? super K> comparator)
        Returns an immutable map containing the same entries as map, with keys sorted by the provided comparator.

        Despite the method name, this method attempts to avoid actually copying the data when it is safe to do so. The exact circumstances under which a copy will or will not be performed are undocumented and subject to change.

        Throws:
        NullPointerException - if any key or value in map is null
        IllegalArgumentException - if any two keys are equal according to the comparator
      • copyOfSorted

        public static <K,V> ImmutableSortedMap<K,V> copyOfSorted(SortedMap<K,? extends V> map)
        Returns an immutable map containing the same entries as the provided sorted map, with the same ordering.

        Despite the method name, this method attempts to avoid actually copying the data when it is safe to do so. The exact circumstances under which a copy will or will not be performed are undocumented and subject to change.

        Throws:
        NullPointerException - if any key or value in map is null
      • orderedBy

        public static <K,V> ImmutableSortedMap.Builder<K,V> orderedBy(Comparator<K> comparator)
        Returns a builder that creates immutable sorted maps with an explicit comparator. If the comparator has a more general type than the map's keys, such as creating a SortedMap<Integer, String> with a Comparator<Number>, use the ImmutableSortedMap.Builder constructor instead.
        Throws:
        NullPointerException - if comparator is null
      • reverseOrder

        public static <K extends Comparable<?>,V> ImmutableSortedMap.Builder<K,V> reverseOrder()
        Returns a builder that creates immutable sorted maps whose keys are ordered by the reverse of their natural ordering.
      • size

        public int size()
      • containsValue

        public boolean containsValue(Object value)
      • entrySet

        public ImmutableSet<Map.Entry<K,V>> entrySet()
        Returns an immutable set of the mappings in this map, sorted by the key ordering.
      • keySet

        public abstract ImmutableSortedSet<K> keySet()
        Returns an immutable sorted set of the keys in this map.
      • values

        public abstract ImmutableCollection<V> values()
        Returns an immutable collection of the values in this map, sorted by the ordering of the corresponding keys.
      • comparator

        public Comparator<? super K> comparator()
        Returns the comparator that orders the keys, which is Ordering.natural() when the natural ordering of the keys is used. Note that its behavior is not consistent with TreeMap.comparator(), which returns null to indicate natural ordering.
      • firstKey

        public K firstKey()
      • lastKey

        public K lastKey()
      • headMap

        public ImmutableSortedMap<K,V> headMap(K toKey)
        This method returns a ImmutableSortedMap, consisting of the entries whose keys are less than toKey.

        The SortedMap.headMap(K) documentation states that a submap of a submap throws an IllegalArgumentException if passed a toKey greater than an earlier toKey. However, this method doesn't throw an exception in that situation, but instead keeps the original toKey.

      • headMap

        public abstract ImmutableSortedMap<K,V> headMap(K toKey,
                                                        boolean inclusive)
        This method returns a ImmutableSortedMap, consisting of the entries whose keys are less than (or equal to, if inclusive) toKey.

        The SortedMap.headMap(K) documentation states that a submap of a submap throws an IllegalArgumentException if passed a toKey greater than an earlier toKey. However, this method doesn't throw an exception in that situation, but instead keeps the original toKey.

        Specified by:
        headMap in interface  NavigableMap<K,V>
        Since:
        12.0
      • subMap

        public ImmutableSortedMap<K,V> subMap(K fromKey,
                                              K toKey)
        This method returns a ImmutableSortedMap, consisting of the entries whose keys ranges from fromKey, inclusive, to toKey, exclusive.

        The SortedMap.subMap(K, K) documentation states that a submap of a submap throws an IllegalArgumentException if passed a fromKey less than an earlier fromKey. However, this method doesn't throw an exception in that situation, but instead keeps the original fromKey. Similarly, this method keeps the original toKey, instead of throwing an exception, if passed a toKey greater than an earlier toKey.

      • subMap

        public ImmutableSortedMap<K,V> subMap(K fromKey,
                                              boolean fromInclusive,
                                              K toKey,
                                              boolean toInclusive)
        This method returns a ImmutableSortedMap, consisting of the entries whose keys ranges from fromKey to toKey, inclusive or exclusive as indicated by the boolean flags.

        The SortedMap.subMap(K, K) documentation states that a submap of a submap throws an IllegalArgumentException if passed a fromKey less than an earlier fromKey. However, this method doesn't throw an exception in that situation, but instead keeps the original fromKey. Similarly, this method keeps the original toKey, instead of throwing an exception, if passed a toKey greater than an earlier toKey.

        Specified by:
        subMap in interface  NavigableMap<K,V>
        Since:
        12.0
      • tailMap

        public ImmutableSortedMap<K,V> tailMap(K fromKey)
        This method returns a ImmutableSortedMap, consisting of the entries whose keys are greater than or equals to fromKey.

        The SortedMap.tailMap(K) documentation states that a submap of a submap throws an IllegalArgumentException if passed a fromKey less than an earlier fromKey. However, this method doesn't throw an exception in that situation, but instead keeps the original fromKey.

      • tailMap

        public abstract ImmutableSortedMap<K,V> tailMap(K fromKey,
                                                        boolean inclusive)
        This method returns a ImmutableSortedMap, consisting of the entries whose keys are greater than (or equal to, if inclusive) fromKey.

        The SortedMap.tailMap(K) documentation states that a submap of a submap throws an IllegalArgumentException if passed a fromKey less than an earlier fromKey. However, this method doesn't throw an exception in that situation, but instead keeps the original fromKey.

        Specified by:
        tailMap in interface  NavigableMap<K,V>
        Since:
        12.0
      • lowerKey

        public K lowerKey(K key)
      • floorKey

        public K floorKey(K key)
      • ceilingKey

        public K ceilingKey(K key)
      • higherKey

        public K higherKey(K key)