Class ImmutableUnifiedMap<K,​V>

    • Constructor Detail

      • ImmutableUnifiedMap

        public ImmutableUnifiedMap​(java.util.Map<K,​V> delegate)
      • ImmutableUnifiedMap

        public ImmutableUnifiedMap​(Pair<K,​V>... pairs)
    • Method Detail

      • equals

        public boolean equals​(java.lang.Object o)
        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 BatchIterable<K>
        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)
      • forEachValue

        public void forEachValue​(Procedure<? super V> procedure)
        Description copied from interface: MapIterable
        Calls the procedure with each value of the map.
             Set<String> result = UnifiedSet.newSet();
             MutableMap<Integer, String> map = this.newMapWithKeysValues(1, "One", 2, "Two", 3, "Three", 4, "Four");
             map.forEachValue(new CollectionAddProcedure<String>(result));
             Verify.assertSetsEqual(UnifiedSet.newSetWith("One", "Two", "Three", "Four"), result);
         
        Specified by:
        forEachValue in interface MapIterable<K,​V>
        Overrides:
        forEachValue in class AbstractMapIterable<K,​V>
      • forEachKey

        public void forEachKey​(Procedure<? super K> procedure)
        Description copied from interface: MapIterable
        Calls the procedure with each key of the map.
             final Collection<Integer> result = new ArrayList<Integer>();
             MutableMap<Integer, String> map = this.newMapWithKeysValues(1, "1", 2, "2", 3, "3");
             map.forEachKey(new CollectionAddProcedure<Integer>(result));
             Verify.assertContainsAll(result, 1, 2, 3);
         
        Specified by:
        forEachKey in interface MapIterable<K,​V>
        Overrides:
        forEachKey in class AbstractMapIterable<K,​V>
      • 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>
      • keySet

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

        public java.util.Collection<V> values()
        Specified by:
        values in interface java.util.Map<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>
      • forEachWithIndex

        public void forEachWithIndex​(ObjectIntProcedure<? super V> objectIntProcedure)
        Description copied from interface: InternalIterable
        Iterates over the iterable passing each element and the current relative int index to the specified instance of ObjectIntProcedure.

        Example using a Java 8 lambda:

         people.forEachWithIndex((Person person, int index) -> LOGGER.info("Index: " + index + " person: " + person.getName()));
         

        Example using an anonymous inner class:

         people.forEachWithIndex(new ObjectIntProcedure<Person>()
         {
             public void value(Person person, int index)
             {
                 LOGGER.info("Index: " + index + " person: " + person.getName());
             }
         });
         
        Specified by:
        forEachWithIndex in interface InternalIterable<K>
        Overrides:
        forEachWithIndex in class AbstractMapIterable<K,​V>
      • forEachWith

        public <P> void forEachWith​(Procedure2<? super V,​? super P> procedure,
                                    P parameter)
        Description copied from interface: InternalIterable
        The procedure2 is evaluated for each element in the iterable with the specified parameter provided as the second argument.

        Example using a Java 8 lambda:

         people.forEachWith((Person person, Person other) ->
             {
                 if (person.isRelatedTo(other))
                 {
                      LOGGER.info(person.getName());
                 }
             }, fred);
         

        Example using an anonymous inner class:

         people.forEachWith(new Procedure2<Person, Person>()
         {
             public void value(Person person, Person other)
             {
                 if (person.isRelatedTo(other))
                 {
                      LOGGER.info(person.getName());
                 }
             }
         }, fred);
         
        Specified by:
        forEachWith in interface InternalIterable<K>
        Overrides:
        forEachWith in class AbstractMapIterable<K,​V>
      • writeReplace

        protected java.lang.Object writeReplace()
      • ifPresentApply

        public <A> A ifPresentApply​(K key,
                                    Function<? super V,​? extends A> function)
        Description copied from interface: MapIterable
        If there is a value in the Map that corresponds to the specified key return the result of applying the specified Function on the value, otherwise return null.
        Specified by:
        ifPresentApply in interface MapIterable<K,​V>
        Overrides:
        ifPresentApply in class AbstractMapIterable<K,​V>
      • getIfAbsent

        public V getIfAbsent​(K key,
                             Function0<? extends V> function)
        Description copied from interface: MapIterable
        Return the value in the Map that corresponds to the specified key, or if there is no value at the key, return the result of evaluating the specified Function0.
        Specified by:
        getIfAbsent in interface MapIterable<K,​V>
        Overrides:
        getIfAbsent in class AbstractMapIterable<K,​V>
      • getIfAbsentWith

        public <P> V getIfAbsentWith​(K key,
                                     Function<? super P,​? extends V> function,
                                     P parameter)
        Description copied from interface: MapIterable
        Return the value in the Map that corresponds to the specified key, or if there is no value at the key, return the result of evaluating the specified function and parameter.
        Specified by:
        getIfAbsentWith in interface MapIterable<K,​V>
        Overrides:
        getIfAbsentWith in class AbstractMapIterable<K,​V>