Class AbstractMapIterable<K,​V>

java.lang.Object
org.eclipse.collections.impl.AbstractRichIterable<V>
org.eclipse.collections.impl.map.AbstractMapIterable<K,​V>
All Implemented Interfaces:
Iterable<V>, InternalIterable<V>, MapIterable<K,​V>, RichIterable<V>
Direct Known Subclasses:
AbstractImmutableMap, AbstractImmutableSortedMap, AbstractMutableMapIterable, OrderedMapAdapter

public abstract class AbstractMapIterable<K,​V>
extends AbstractRichIterable<V>
implements MapIterable<K,​V>
  • Constructor Details

  • Method Details

    • 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>
    • getOrDefault

      public V getOrDefault​(Object key, V defaultValue)
      Specified by:
      getOrDefault in interface MapIterable<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>
    • getIfAbsentValue

      public V getIfAbsentValue​(K key, V value)
      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 value.
      Specified by:
      getIfAbsentValue in interface MapIterable<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>
    • anySatisfy

      public boolean anySatisfy​(Predicate<? super V> predicate)
      Description copied from interface: RichIterable
      Returns true if the predicate evaluates to true for any element of the iterable. Returns false if the iterable is empty, or if no element returned true when evaluating the predicate.
      Specified by:
      anySatisfy in interface RichIterable<K>
      Overrides:
      anySatisfy in class AbstractRichIterable<V>
    • anySatisfyWith

      public <P> boolean anySatisfyWith​(Predicate2<? super V,​? super P> predicate, P parameter)
      Description copied from interface: RichIterable
      Returns true if the predicate evaluates to true for any element of the collection, or return false. Returns false if the collection is empty.
      Specified by:
      anySatisfyWith in interface RichIterable<K>
      Overrides:
      anySatisfyWith in class AbstractRichIterable<V>
    • allSatisfy

      public boolean allSatisfy​(Predicate<? super V> predicate)
      Description copied from interface: RichIterable
      Returns true if the predicate evaluates to true for every element of the iterable or if the iterable is empty. Otherwise, returns false.
      Specified by:
      allSatisfy in interface RichIterable<K>
      Overrides:
      allSatisfy in class AbstractRichIterable<V>
    • allSatisfyWith

      public <P> boolean allSatisfyWith​(Predicate2<? super V,​? super P> predicate, P parameter)
      Description copied from interface: RichIterable
      Returns true if the predicate evaluates to true for every element of the collection, or returns false.
      Specified by:
      allSatisfyWith in interface RichIterable<K>
      Overrides:
      allSatisfyWith in class AbstractRichIterable<V>
    • noneSatisfy

      public boolean noneSatisfy​(Predicate<? super V> predicate)
      Description copied from interface: RichIterable
      Returns true if the predicate evaluates to false for every element of the iterable or if the iterable is empty. Otherwise, returns false.
      Specified by:
      noneSatisfy in interface RichIterable<K>
      Overrides:
      noneSatisfy in class AbstractRichIterable<V>
    • noneSatisfyWith

      public <P> boolean noneSatisfyWith​(Predicate2<? super V,​? super P> predicate, P parameter)
      Description copied from interface: RichIterable
      Returns true if the predicate evaluates to false for every element of the collection, or return false. Returns true if the collection is empty.
      Specified by:
      noneSatisfyWith in interface RichIterable<K>
      Overrides:
      noneSatisfyWith in class AbstractRichIterable<V>
    • asLazy

      public LazyIterable<V> asLazy()
      Description copied from interface: RichIterable
      Returns a lazy (deferred) iterable, most likely implemented by calling LazyIterate.adapt(this).
      Specified by:
      asLazy in interface RichIterable<K>
      Overrides:
      asLazy in class AbstractRichIterable<V>
    • chunk

      public RichIterable<RichIterable<V>> chunk​(int size)
      Description copied from interface: RichIterable
      Partitions elements in fixed size chunks.
      Specified by:
      chunk in interface RichIterable<K>
      Parameters:
      size - the number of elements per chunk
      Returns:
      A RichIterable containing RichIterables of size size, except the last will be truncated if the elements don't divide evenly.
    • each

      public void each​(Procedure<? super V> procedure)
      Description copied from interface: RichIterable
      The procedure is executed for each element in the iterable.

      Example using a Java 8 lambda expression:

       people.each(person -> LOGGER.info(person.getName()));
       

      Example using an anonymous inner class:

       people.each(new Procedure<Person>()
       {
           public void value(Person person)
           {
               LOGGER.info(person.getName());
           }
       });
       
      This method is a variant of InternalIterable.forEach(Procedure) that has a signature conflict with Iterable.forEach(java.util.function.Consumer).
      Specified by:
      each in interface RichIterable<K>
      See Also:
      InternalIterable.forEach(Procedure), Iterable.forEach(java.util.function.Consumer)
    • forEachWith

      public <P> void forEachWith​(Procedure2<? super V,​? super P> procedure2, 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 AbstractRichIterable<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 AbstractRichIterable<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>
    • 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>
    • contains

      public boolean contains​(Object object)
      Description copied from interface: RichIterable
      Returns true if the iterable has an element which responds true to element.equals(object).
      Specified by:
      contains in interface RichIterable<K>
      Overrides:
      contains in class AbstractRichIterable<V>
    • detect

      public V detect​(Predicate<? super V> predicate)
      Description copied from interface: RichIterable
      Returns the first element of the iterable for which the predicate evaluates to true or null in the case where no element returns true. This method is commonly called find.

      Example using a Java 8 lambda expression:

       Person person =
           people.detect(person -> person.getFirstName().equals("John") && person.getLastName().equals("Smith"));
       

      Example using an anonymous inner class:

       Person person =
           people.detect(new Predicate<Person>()
           {
               public boolean accept(Person person)
               {
                   return person.getFirstName().equals("John") && person.getLastName().equals("Smith");
               }
           });
       
      Specified by:
      detect in interface RichIterable<K>
      Overrides:
      detect in class AbstractRichIterable<V>
    • detectWith

      public <P> V detectWith​(Predicate2<? super V,​? super P> predicate, P parameter)
      Description copied from interface: RichIterable
      Returns the first element that evaluates to true for the specified predicate2 and parameter, or null if none evaluate to true.

      Example using a Java 8 lambda expression:

       Person person =
           people.detectWith((person, fullName) -> person.getFullName().equals(fullName), "John Smith");
       

      Example using an anonymous inner class:

       Person person =
           people.detectWith(new Predicate2<Person, String>()
           {
               public boolean accept(Person person, String fullName)
               {
                   return person.getFullName().equals(fullName);
               }
           }, "John Smith");
       
      Specified by:
      detectWith in interface RichIterable<K>
      Overrides:
      detectWith in class AbstractRichIterable<V>
    • detectOptional

      public Optional<V> detectOptional​(Predicate<? super V> predicate)
      Description copied from interface: RichIterable
      Returns the first element of the iterable for which the predicate evaluates to true as an Optional. This method is commonly called find.

      Example using a Java 8 lambda expression:

       Person person =
           people.detectOptional(person -> person.getFirstName().equals("John") && person.getLastName().equals("Smith"));
       

      Specified by:
      detectOptional in interface RichIterable<K>
      Overrides:
      detectOptional in class AbstractRichIterable<V>
    • detectWithOptional

      public <P> Optional<V> detectWithOptional​(Predicate2<? super V,​? super P> predicate, P parameter)
      Description copied from interface: RichIterable
      Returns the first element that evaluates to true for the specified predicate2 and parameter as an Optional.

      Example using a Java 8 lambda expression:

       Optional<Person> person =
           people.detectWithOptional((person, fullName) -> person.getFullName().equals(fullName), "John Smith");
       

      Specified by:
      detectWithOptional in interface RichIterable<K>
      Overrides:
      detectWithOptional in class AbstractRichIterable<V>
    • detectIfNone

      public V detectIfNone​(Predicate<? super V> predicate, Function0<? extends V> function)
      Description copied from interface: RichIterable
      Returns the first element of the iterable for which the predicate evaluates to true. If no element matches the predicate, then returns the value of applying the specified function.
      Specified by:
      detectIfNone in interface RichIterable<K>
    • detectWithIfNone

      public <P> V detectWithIfNone​(Predicate2<? super V,​? super P> predicate, P parameter, Function0<? extends V> function)
      Description copied from interface: RichIterable
      Returns the first element of the iterable that evaluates to true for the specified predicate2 and parameter, or returns the value of evaluating the specified function.
      Specified by:
      detectWithIfNone in interface RichIterable<K>
      Overrides:
      detectWithIfNone in class AbstractRichIterable<V>
    • getFirst

      public V getFirst()
      Description copied from interface: RichIterable
      Returns the first element of an iterable. In the case of a List it is the element at the first index. In the case of any other Collection, it is the first element that would be returned during an iteration. If the iterable is empty, null is returned. If null is a valid element of the container, then a developer would need to check to see if the iterable is empty to validate that a null result was not due to the container being empty.

      The order of Sets are not guaranteed (except for TreeSets and other Ordered Set implementations), so if you use this method, the first element could be any element from the Set.

      Specified by:
      getFirst in interface RichIterable<K>
    • getLast

      public V getLast()
      Description copied from interface: RichIterable
      Returns the last element of an iterable. In the case of a List it is the element at the last index. In the case of any other Collection, it is the last element that would be returned during an iteration. If the iterable is empty, null is returned. If null is a valid element of the container, then a developer would need to check to see if the iterable is empty to validate that a null result was not due to the container being empty.

      The order of Sets are not guaranteed (except for TreeSets and other Ordered Set implementations), so if you use this method, the last element could be any element from the Set.

      Specified by:
      getLast in interface RichIterable<K>
    • getOnly

      public V getOnly()
      Description copied from interface: RichIterable
      Returns the element if the iterable has exactly one element. Otherwise, throw IllegalStateException.
      Specified by:
      getOnly in interface RichIterable<K>
      Returns:
      an element of an iterable.
    • toArray

      public Object[] toArray()
      Description copied from interface: RichIterable
      Converts this iterable to an array.
      Specified by:
      toArray in interface RichIterable<K>
      Overrides:
      toArray in class AbstractRichIterable<V>
      See Also:
      Collection.toArray()
    • toArray

      public <T> T[] toArray​(T[] a)
      Description copied from interface: RichIterable
      Converts this iterable to an array using the specified target array, assuming the target array is as long or longer than the iterable.
      Specified by:
      toArray in interface RichIterable<K>
      Overrides:
      toArray in class AbstractRichIterable<V>
      See Also:
      Collection.toArray(Object[])