Class ImmutableTreeMap<K,​V>

    • Field Detail

      • keys

        private final K[] keys
      • values

        private final V[] values
      • comparator

        private final java.util.Comparator<? super K> comparator
    • Constructor Detail

      • ImmutableTreeMap

        public ImmutableTreeMap​(java.util.SortedMap<K,​V> sortedMap)
    • Method Detail

      • newMap

        public static <K,​V> ImmutableSortedMap<K,​V> newMap​(java.util.SortedMap<K,​V> sortedMap)
      • equals

        public boolean equals​(java.lang.Object object)
        Description copied from interface: MapIterable
        Follows the same general contract as Map.equals(Object).
        Specified by:
        equals in interface java.util.Map<K,​V>
        Specified by:
        equals in interface MapIterable<K,​V>
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Description copied from interface: MapIterable
        Follows the same general contract as Map.hashCode().
        Specified by:
        hashCode in interface java.util.Map<K,​V>
        Specified by:
        hashCode in interface MapIterable<K,​V>
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Description copied from class: AbstractRichIterable
        Returns a string with the elements of the iterable separated by commas with spaces and enclosed in square brackets.
         Assert.assertEquals("[]", Lists.mutable.empty().toString());
         Assert.assertEquals("[1]", Lists.mutable.with(1).toString());
         Assert.assertEquals("[1, 2, 3]", Lists.mutable.with(1, 2, 3).toString());
         
        Specified by:
        toString in interface MapIterable<K,​V>
        Specified by:
        toString in interface RichIterable<K>
        Overrides:
        toString in class AbstractRichIterable<V>
        Returns:
        a string representation of this collection.
        See Also:
        AbstractCollection.toString()
      • size

        public int size()
        Description copied from interface: RichIterable
        Returns the number of items in this iterable.
        Specified by:
        size in interface java.util.Map<K,​V>
        Specified by:
        size in interface RichIterable<K>
      • containsKey

        public boolean containsKey​(java.lang.Object key)
        Specified by:
        containsKey in interface java.util.Map<K,​V>
        Specified by:
        containsKey in interface MapIterable<K,​V>
        See Also:
        Map.containsKey(Object)
      • containsValue

        public boolean containsValue​(java.lang.Object value)
        Specified by:
        containsValue in interface java.util.Map<K,​V>
        Specified by:
        containsValue in interface MapIterable<K,​V>
        See Also:
        Map.containsValue(Object)
      • get

        public V get​(java.lang.Object key)
        Specified by:
        get in interface java.util.Map<K,​V>
        Specified by:
        get in interface MapIterable<K,​V>
        See Also:
        Map.get(Object)
      • forEachKeyValue

        public void forEachKeyValue​(Procedure2<? super K,​? super V> procedure)
        Description copied from interface: MapIterable
        Calls the procedure with each key-value pair of the map.
             final Collection<String> collection = new ArrayList<String>();
             MutableMap<Integer, String> map = this.newMapWithKeysValues(1, "One", 2, "Two", 3, "Three");
             map.forEachKeyValue((Integer key, String value) -> collection.add(String.valueOf(key) + value));
             Verify.assertContainsAll(collection, "1One", "2Two", "3Three");
         
        Specified by:
        forEachKeyValue in interface MapIterable<K,​V>
      • flipUniqueValues

        public ImmutableMap<V,​K> flipUniqueValues()
        Description copied from interface: MapIterable
        Return the MapIterable that is obtained by flipping the direction of this map and making the associations from value to key.
             MapIterable<Integer, String> map = this.newMapWithKeysValues(1, "1", 2, "2", 3, "3");
             MapIterable<String, Integer> result = map.flipUniqueValues();
             Assert.assertTrue(result.equals(UnifiedMap.newWithKeysValues("1", 1, "2", 2, "3", 3)));
         
        Specified by:
        flipUniqueValues in interface ImmutableMapIterable<K,​V>
        Specified by:
        flipUniqueValues in interface MapIterable<K,​V>
      • keysView

        public RichIterable<K> keysView()
        Description copied from interface: MapIterable
        Returns an unmodifiable lazy iterable wrapped around the keySet for the map.
        Specified by:
        keysView in interface MapIterable<K,​V>
      • valuesView

        public RichIterable<V> valuesView()
        Description copied from interface: MapIterable
        Returns an unmodifiable lazy iterable wrapped around the values for the map.
        Specified by:
        valuesView in interface MapIterable<K,​V>
      • keyValuesView

        public RichIterable<Pair<K,​V>> keyValuesView()
        Description copied from interface: MapIterable
        Returns an unmodifiable lazy iterable of key/value pairs wrapped around the entrySet for the map.
        Specified by:
        keyValuesView in interface MapIterable<K,​V>
      • comparator

        public java.util.Comparator<? super K> comparator()
        Specified by:
        comparator in interface java.util.SortedMap<K,​V>
        Specified by:
        comparator in interface SortedMapIterable<K,​V>
      • firstKey

        public K firstKey()
        Specified by:
        firstKey in interface java.util.SortedMap<K,​V>
      • lastKey

        public K lastKey()
        Specified by:
        lastKey in interface java.util.SortedMap<K,​V>
      • keySet

        public java.util.Set<K> keySet()
        Specified by:
        keySet in interface java.util.Map<K,​V>
        Specified by:
        keySet in interface java.util.SortedMap<K,​V>
      • values

        public java.util.Collection<V> values()
        Specified by:
        values in interface java.util.Map<K,​V>
        Specified by:
        values in interface java.util.SortedMap<K,​V>
      • entrySet

        public java.util.Set<java.util.Map.Entry<K,​V>> entrySet()
        Specified by:
        entrySet in interface java.util.Map<K,​V>
        Specified by:
        entrySet in interface java.util.SortedMap<K,​V>
      • writeReplace

        protected java.lang.Object writeReplace()
      • take

        public ImmutableSortedMap<K,​V> take​(int count)
        Description copied from interface: ReversibleIterable
        Returns the first count elements of the iterable or all the elements in the iterable if count is greater than the length of the iterable.
        Specified by:
        take in interface ReversibleIterable<K>
        Specified by:
        take in interface SortedMapIterable<K,​V>
        Parameters:
        count - the number of items to take.
      • drop

        public ImmutableSortedMap<K,​V> drop​(int count)
        Description copied from interface: ReversibleIterable
        Returns an iterable after skipping the first count elements or an empty iterable if the count is greater than the length of the iterable.
        Specified by:
        drop in interface ReversibleIterable<K>
        Specified by:
        drop in interface SortedMapIterable<K,​V>
        Parameters:
        count - the number of items to drop.