Class AbstractMutableMapIterable<K,V>

java.lang.Object
org.eclipse.collections.impl.AbstractRichIterable<V>
org.eclipse.collections.impl.map.AbstractMapIterable<K,V>
org.eclipse.collections.impl.map.mutable.AbstractMutableMapIterable<K,V>
All Implemented Interfaces:
Iterable<V>, Map<K,V>, InternalIterable<V>, MapIterable<K,V>, MutableMapIterable<K,V>, RichIterable<V>
Direct Known Subclasses:
AbstractMutableMap, AbstractMutableSortedMap

public abstract class AbstractMutableMapIterable<K,V> extends AbstractMapIterable<K,V> implements MutableMapIterable<K,V>
  • Constructor Details

    • AbstractMutableMapIterable

      public AbstractMutableMapIterable()
  • Method Details

    • iterator

      public Iterator<V> iterator()
      Specified by:
      iterator in interface Iterable<K>
    • getIfAbsentPut

      public V getIfAbsentPut(K key, Function0<? extends V> function)
      Description copied from interface: MutableMapIterable
      Get and return the value in the Map at the specified key. Alternatively, if there is no value in the map at the key, return the result of evaluating the specified Function0, and put that value in the map at the specified key.
      Specified by:
      getIfAbsentPut in interface MutableMapIterable<K,V>
    • getIfAbsentPut

      public V getIfAbsentPut(K key, V value)
      Description copied from interface: MutableMapIterable
      Get and return the value in the Map at the specified key. Alternatively, if there is no value in the map at the key, return the specified value, and put that value in the map at the specified key.
      Specified by:
      getIfAbsentPut in interface MutableMapIterable<K,V>
    • getIfAbsentPutWithKey

      public V getIfAbsentPutWithKey(K key, Function<? super K,? extends V> function)
      Description copied from interface: MutableMapIterable
      Get and return the value in the Map at the specified key. Alternatively, if there is no value in the map for that key return the result of evaluating the specified Function using the specified key, and put that value in the map at the specified key.
      Specified by:
      getIfAbsentPutWithKey in interface MutableMapIterable<K,V>
    • getIfAbsentPutWith

      public <P> V getIfAbsentPutWith(K key, Function<? super P,? extends V> function, P parameter)
      Description copied from interface: MutableMapIterable
      Get and return the value in the Map at the specified key. Alternatively, if there is no value in the map for that key return the result of evaluating the specified Function using the specified parameter, and put that value in the map at the specified key.
      Specified by:
      getIfAbsentPutWith in interface MutableMapIterable<K,V>
    • updateValue

      public V updateValue(K key, Function0<? extends V> factory, Function<? super V,? extends V> function)
      Description copied from interface: MutableMapIterable
      Looks up the value associated with key, applies the function to it, and replaces the value. If there is no value associated with key, starts it off with a value supplied by factory.
      Specified by:
      updateValue in interface MutableMapIterable<K,V>
    • updateValueWith

      public <P> V updateValueWith(K key, Function0<? extends V> factory, Function2<? super V,? super P,? extends V> function, P parameter)
      Description copied from interface: MutableMapIterable
      Same as MutableMapIterable.updateValue(Object, Function0, Function) with a Function2 and specified parameter which is passed to the function.
      Specified by:
      updateValueWith in interface MutableMapIterable<K,V>
    • groupByUniqueKey

      public <VV> MutableMapIterable<VV,V> groupByUniqueKey(Function<? super V,? extends VV> function)
      Description copied from interface: RichIterable
      For each element of the iterable, the function is evaluated, and the results of these evaluations are collected into a new map, where the transformed value is the key. The generated keys must each be unique, or else an exception is thrown.
      Specified by:
      groupByUniqueKey in interface MutableMapIterable<K,V>
      Specified by:
      groupByUniqueKey in interface RichIterable<K>
      See Also:
    • aggregateBy

      public <K1, V1, V2> MutableMap<K1,V2> aggregateBy(Function<? super K,? extends K1> keyFunction, Function<? super V,? extends V1> valueFunction, Function0<? extends V2> zeroValueFactory, Function2<? super V2,? super V1,? extends V2> nonMutatingAggregator)
      Description copied from interface: MapIterable
      Applies an aggregate function over the map grouping results into a map based on the specific key and value groupBy functions. Aggregate results are allowed to be immutable as they will be replaced in place in the map. A second function specifies the initial "zero" aggregate value to work with.
       MapIterable<String, Interval> map = Maps.mutable.with("oneToFive", Interval.fromTo(1, 5), "sixToNine", Interval.fromTo(6, 9));
      
       MapIterable<String, Long> result = map.aggregateBy(
               eachKey -> {
                   return eachKey.equals("oneToFive")  ? "lessThanSix" : "greaterOrEqualsToSix";
               },
               each -> each.sumOfInt(Integer::intValue),
               () -> 0L,
               (argument1, argument2) -> argument1 + argument2);
      
       MapIterable<String, Long> expected =
               Maps.mutable.with("lessThanSix", Interval.fromTo(1, 5).sumOfInt(Integer::intValue),
                       "greaterOrEqualsToSix", Interval.fromTo(6, 9).sumOfInt(Integer::intValue));
       Assert.assertEquals(expected, result);
       
      Specified by:
      aggregateBy in interface MapIterable<K,V>
      Specified by:
      aggregateBy in interface MutableMapIterable<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>
    • collect

      public <K2, V2> MutableMap<K2,V2> collect(Function2<? super K,? super V,Pair<K2,V2>> function)
      Description copied from interface: MapIterable
      For each key and value of the map the function is evaluated. The results of these evaluations are returned in a new map. The map returned will use the values projected from the function rather than the original values.
       MapIterable<String, String> collected =
           peopleByCity.collect((City city, Person person) -> Pair.of(city.getCountry(), person.getAddress().getCity()));
       
      Specified by:
      collect in interface MapIterable<K,V>
      Specified by:
      collect in interface MutableMapIterable<K,V>
    • flipUniqueValues

      public MutableMap<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 MapIterable<K,V>
      Specified by:
      flipUniqueValues in interface MutableMapIterable<K,V>
    • detect

      public Pair<K,V> detect(Predicate2<? super K,? super V> predicate)
      Description copied from interface: MapIterable
      Return the first key and value of the map for which the predicate evaluates to true when they are given as arguments. The predicate will only be evaluated until such pair is found or until all the keys and values of the map have been used as arguments. That is, there may be keys and values of the map that are never used as arguments to the predicate. The result is null if predicate does not evaluate to true for any key/value combination.
       Pair<City, Person> detected =
           peopleByCity.detect((City city, Person person) -> city.getName().equals("Anytown") && person.getLastName().equals("Smith"));
       
      Specified by:
      detect in interface MapIterable<K,V>
    • detectOptional

      public Optional<Pair<K,V>> detectOptional(Predicate2<? super K,? super V> predicate)
      Description copied from interface: MapIterable
      Return the first key and value of the map as an Optional for which the predicate evaluates to true when they are given as arguments. The predicate will only be evaluated until such pair is found or until all the keys and values of the map have been used as arguments. That is, there may be keys and values of the map that are never used as arguments to the predicate.
       Optional<Pair<City, Person>> detected =
           peopleByCity.detectOptional((city, person)
                -> city.getName().equals("Anytown") && person.getLastName().equals("Smith"));
       
      Specified by:
      detectOptional in interface MapIterable<K,V>
    • sumByInt

      public <V1> MutableObjectLongMap<V1> sumByInt(Function<? super V,? extends V1> groupBy, IntFunction<? super V> function)
      Description copied from interface: RichIterable
      Groups and sums the values using the two specified functions.
      Specified by:
      sumByInt in interface MutableMapIterable<K,V>
      Specified by:
      sumByInt in interface RichIterable<K>
    • sumByFloat

      public <V1> MutableObjectDoubleMap<V1> sumByFloat(Function<? super V,? extends V1> groupBy, FloatFunction<? super V> function)
      Description copied from interface: RichIterable
      Groups and sums the values using the two specified functions.
      Specified by:
      sumByFloat in interface MutableMapIterable<K,V>
      Specified by:
      sumByFloat in interface RichIterable<K>
    • sumByLong

      public <V1> MutableObjectLongMap<V1> sumByLong(Function<? super V,? extends V1> groupBy, LongFunction<? super V> function)
      Description copied from interface: RichIterable
      Groups and sums the values using the two specified functions.
      Specified by:
      sumByLong in interface MutableMapIterable<K,V>
      Specified by:
      sumByLong in interface RichIterable<K>
    • sumByDouble

      public <V1> MutableObjectDoubleMap<V1> sumByDouble(Function<? super V,? extends V1> groupBy, DoubleFunction<? super V> function)
      Description copied from interface: RichIterable
      Groups and sums the values using the two specified functions.
      Specified by:
      sumByDouble in interface MutableMapIterable<K,V>
      Specified by:
      sumByDouble in interface RichIterable<K>
    • countBy

      public <V1> MutableBag<V1> countBy(Function<? super V,? extends V1> function)
      Description copied from interface: RichIterable
      This method will count the number of occurrences of each value calculated by applying the function to each element of the collection.
      Specified by:
      countBy in interface MutableMapIterable<K,V>
      Specified by:
      countBy in interface RichIterable<K>
      Since:
      9.0
    • countByWith

      public <V1, P> MutableBag<V1> countByWith(Function2<? super V,? super P,? extends V1> function, P parameter)
      Description copied from interface: RichIterable
      This method will count the number of occurrences of each value calculated by applying the function to each element of the collection with the specified parameter as the second argument.
      Specified by:
      countByWith in interface MutableMapIterable<K,V>
      Specified by:
      countByWith in interface RichIterable<K>
      Since:
      9.0
    • countByEach

      public <V1> MutableBag<V1> countByEach(Function<? super V,? extends Iterable<V1>> function)
      Description copied from interface: RichIterable
      This method will count the number of occurrences of each value calculated by applying the function to each element of the collection.
      Specified by:
      countByEach in interface MutableMapIterable<K,V>
      Specified by:
      countByEach in interface RichIterable<K>
      Overrides:
      countByEach in class AbstractRichIterable<V>
      Since:
      10.0.0