Interface MapStream<K,V>

Type Parameters:
K - The type of the map keys.
V - The type of the map values.
All Superinterfaces:
AutoCloseable, BaseStream<Map.Entry<K,V>,Stream<Map.Entry<K,V>>>, Stream<Map.Entry<K,V>>
All Known Implementing Classes:
DefaultMapStream

@ClassVersion(sourceVersion="$Id: MapStream.java 1060 2023-09-24 19:21:40Z tquadrat $") @API(status=STABLE, since="0.0.7") public interface MapStream<K,V> extends Stream<Map.Entry<K,V>>
A stream of Map.Entry<K,V>.
Author:
Alexis Cartier (alexcrt), Dominic Fox
Modified by:
Thomas Thrien (thomas.thrien@tquadrat.org)
Version:
$Id: MapStream.java 1060 2023-09-24 19:21:40Z tquadrat $
Since:
0.0.7
UML Diagram
UML Diagram for "org.tquadrat.foundation.stream.MapStream"

UML Diagram for "org.tquadrat.foundation.stream.MapStream"

UML Diagram for "org.tquadrat.foundation.stream.MapStream"
  • Method Details

    • collect

      default Map<K,V> collect()
      Returns a Map from the stream. If there are identical keys in the stream, mergeKeys() should be called before. Alternatively, collect(BinaryOperator) could be used.
      Returns:
      A map from the values of the stream.
    • collect

      default Map<K,V> collect(BinaryOperator<V> mergeFunction)
      Returns a Map from the stream. If there are similar keys in the stream, the merge function will be applied to merge the values of those keys.
      Parameters:
      mergeFunction - The function that is used to merge the values with identical keys.
      Returns:
      A map from the values of the stream.
    • distinct

      Specified by:
      distinct in interface Stream<K>
    • dropKeys

      default Stream<V> dropKeys()
      Returns a stream consisting only of the values of underlying map for this MapStream.

      This is an intermediate operation.
      Returns:
      The new stream.
    • dropValues

      default Stream<K> dropValues()
      Returns a stream consisting only of the keys of underlying map for this MapStream.

      This is an intermediate operation.
      Returns:
      The new stream.
    • filter

      MapStream<K,V> filter(Predicate<? super Map.Entry<K,V>> predicate)
      Specified by:
      filter in interface Stream<K>
    • filter

      default MapStream<K,V> filter(BiPredicate<? super K,? super V> predicate)
      Returns a stream consisting of the elements of this stream that match the given predicate.

      This is an intermediate operation.
      Parameters:
      predicate - A non-interfering, stateless predicate to apply to each element to determine if it should be included.
      Returns:
      The new stream.
      See Also:
    • forEach

      default void forEach(BiConsumer<K,V> action)
      Performs an action for each entry of the Map that was used to construct this stream.

      This is a terminal operation.

      The behaviour of this operation is explicitly nondeterministic. For parallel stream pipelines, this operation does not guarantee to respect the encounter order of the stream, as doing so would sacrifice the benefit of parallelism. For any given element, the action may be performed at whatever time and in whatever thread the library chooses. If the action accesses shared state, it is responsible for providing the required synchronisation.
      Parameters:
      action - A non-interfering action to perform on the entries.
    • inverseMapping

      Returns a MapStream from which the key and values are reversed.
      Returns:
      A new map stream.
    • limit

      MapStream<K,V> limit(long limit)
      Specified by:
      limit in interface Stream<K>
    • map

      default <R> Stream<R> map(BiFunction<K,V,? extends R> mapper)
      Returns a stream consisting of the results of applying the given function to the elements of this stream.

      This is an intermediate operation.
      Type Parameters:
      R - The element type of the new stream.
      Parameters:
      mapper - A non-interfering, stateless function to apply to each element.
      Returns:
      The new stream.
    • mapEntries

      default <K1, V1> MapStream<K1,V1> mapEntries(Function<? super K,? extends K1> keyMapper, Function<? super V,? extends V1> valueMapper)

      Applies the mapping for each key and value in the map.

      If the mapping function is not bijective for the keys, mergeKeys() or mergeKeys(BinaryOperator) needs to be called before, or a merge function has to be provided when calling collect().

      Type Parameters:
      K1 - The type of the map keys.
      V1 - The type of the map values.
      Parameters:
      keyMapper - The key mapping to be applied.
      valueMapper - The value mapping to be applied.
      Returns:
      A new map stream.
    • mapKeys

      default <K1> MapStream<K1,V> mapKeys(Function<? super K,? extends K1> mapper)
      Applies the mapping for each key in the map. If the mapping function is not bijective, mergeKeys() or mergeKeys(BinaryOperator) needs to be called before, or a merge function has to be provided when calling collect().
      Type Parameters:
      K1 - The type of the map keys.
      Parameters:
      mapper - The key mapping to be applied.
      Returns:
      A new map stream.
    • mapValues

      default <V1> MapStream<K,V1> mapValues(Function<? super V,? extends V1> mapper)
      Applies the mapping for each value in the map.
      Type Parameters:
      V1 - The type of the map values.
      Parameters:
      mapper - The value mapping to be applied.
      Returns:
      A new map stream.
    • mergeKeys

      default MapStream<K,List<V>> mergeKeys()
      Merges the keys of the stream into a new stream.
      Returns:
      A new map stream.
    • mergeKeys

      default MapStream<K,V> mergeKeys(BinaryOperator<V> mergeFunction)
      Merges keys of the stream into a new stream with the provided merge function.
      Parameters:
      mergeFunction - The merge function.
      Returns:
      A new map stream.
    • of

      @API(status=STABLE, since="0.0.4") static <K, V> MapStream<K,V> of(K key, V value)
      Factory for a MapStream<K,V>; constructs a stream from a single key-value pair.
      Type Parameters:
      K - The type of the map keys.
      V - The type of the map values.
      Parameters:
      key - The key.
      value - The value.
      Returns:
      A new MapStream<K,V>.
    • of

      @API(status=STABLE, since="0.0.4") static <K, V> MapStream<K,V> of(K key1, V value1, K key2, V value2)
      Factory for a MapStream<K,V>; constructs a stream from two key-value pairs
      Type Parameters:
      K - The type of the map keys.
      V - The type of the map values.
      Parameters:
      key1 - The first key.
      value1 - The first value.
      key2 - The second key.
      value2 - The second value.
      Returns:
      A new MapStream<K,V>.
    • of

      @API(status=STABLE, since="0.0.4") static <K, V> MapStream<K,V> of(K key1, V value1, K key2, V value2, K key3, V value3)
      Factory for a MapStream<K,V>; constructs a stream from three key-value pairs
      Type Parameters:
      K - The type of the map keys.
      V - The type of the map values.
      Parameters:
      key1 - The first key.
      value1 - The first value.
      key2 - The second key.
      value2 - The second value.
      key3 - The third key.
      value3 - The third value.
      Returns:
      A new MapStream<K,V>.
    • of

      @API(status=STABLE, since="0.0.4") static <K, V> MapStream<K,V> of(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4)
      Factory for a MapStream<K,V>; constructs a stream from four key-value pairs
      Type Parameters:
      K - The type of the map keys.
      V - The type of the map values.
      Parameters:
      key1 - The first key.
      value1 - The first value.
      key2 - The second key.
      value2 - The second value.
      key3 - The third key.
      value3 - The third value.
      key4 - The third key.
      value4 - The third value.
      Returns:
      A new MapStream<K,V>.
    • of

      @API(status=STABLE, since="0.0.4") static <K, V> MapStream<K,V> of(K key1, V value1, K key2, V value2, K key3, V value3, K key4, V value4, K key5, V value5)
      Factory for a MapStream<K,V>; constructs a stream from five key-value pairs
      Type Parameters:
      K - The type of the map keys.
      V - The type of the map values.
      Parameters:
      key1 - The first key.
      value1 - The first value.
      key2 - The second key.
      value2 - The second value.
      key3 - The third key.
      value3 - The third value.
      key4 - The third key.
      value4 - The third value.
      key5 - The third key.
      value5 - The third value.
      Returns:
      A new MapStream<K,V>.
    • of

      @API(status=STABLE, since="0.0.4") @SafeVarargs static <K, V> MapStream<K,V> of(Map.Entry<K,V>... nvps)
      Factory for a MapStream<K,V>; constructs a stream from some key-value pairs
      Type Parameters:
      K - The type of the map keys.
      V - The type of the map values.
      Parameters:
      nvps - The key-value-pairs.
      Returns:
      A new MapStream<K,V>.
    • of

      @API(status=STABLE, since="0.0.4") static <K, V> MapStream<K,V> of(Collection<Map.Entry<K,V>> nvps)
      Factory for a MapStream<K,V>; constructs a stream from a Collection of key-value pairs
      Type Parameters:
      K - The type of the map keys.
      V - The type of the map values.
      Parameters:
      nvps - The key-value-pairs.
      Returns:
      A new MapStream<K,V>.
    • of

      @API(status=STABLE, since="0.0.4") static <K, V> MapStream<K,V> of(Map<K,V> map)
      Factory for a MapStream<K,V>; constructs a stream from an instance of Map.
      Type Parameters:
      K - The type of the map keys.
      V - The type of the map values.
      Parameters:
      map - The map to build the stream from.
      Returns:
      A new MapStream<K,V>.
    • ofMaps

      @API(status=STABLE, since="0.0.4") @SafeVarargs static <K, V> MapStream<K,V> ofMaps(Map<K,V>... maps)
      Factory for a MapStream<K,V>; constructs a stream from several instances of Map.
      Type Parameters:
      K - The type of the map keys.
      V - The type of the map values.
      Parameters:
      maps - The maps to build the stream from.
      Returns:
      A new MapStream<K,V>.
    • onClose

      MapStream<K,V> onClose(Runnable closeHandler)
      Specified by:
      onClose in interface BaseStream<K,V>
    • parallel

      Specified by:
      parallel in interface BaseStream<K,V>
    • peek

      MapStream<K,V> peek(Consumer<? super Map.Entry<K,V>> action)
      Specified by:
      peek in interface Stream<K>
    • sequential

      Specified by:
      sequential in interface BaseStream<K,V>
    • skip

      MapStream<K,V> skip(long n)
      Specified by:
      skip in interface Stream<K>
    • sorted

      Specified by:
      sorted in interface Stream<K>
    • sorted

      MapStream<K,V> sorted(Comparator<? super Map.Entry<K,V>> comparator)
      Specified by:
      sorted in interface Stream<K>
    • unordered

      Specified by:
      unordered in interface BaseStream<K,V>