public class

MoreCollectors

extends Object
java.lang.Object
   ↳ com.atlassian.bitbucket.util.MoreCollectors

Class Overview

Additional utility methods missing from Collectors. The implementation of these collectors, where possible, attempts to emulate the behavior of the standard Collectors factories.

Summary

Public Methods
@Nonnull static <T> Collector<T, ?, List<T>> toImmutableList()
Returns a Collector that accumulates elements into an immutable list.
@Nonnull static <T, K, U> Collector<T, ?, Map<K, U>> toImmutableMap(Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends U> valueMapper)
Returns a Collector that accumulates elements into an immutable map whose keys and values are the result of applying the provided mapping functions to the input elements.
@Nonnull static <T> Collector<T, ?, Set<T>> toImmutableSet()
Returns a Collector that accumulates elements into an immutable set.
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

@Nonnull public static Collector<T, ?, List<T>> toImmutableList ()

Returns a Collector that accumulates elements into an immutable list.

The Stream being collected may contain null elements and, when it does, the collected list will also contain null elements.

Returns
  • a Collector which collects elements into an immutable list
See Also

@Nonnull public static Collector<T, ?, Map<K, U>> toImmutableMap (Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends U> valueMapper)

Returns a Collector that accumulates elements into an immutable map whose keys and values are the result of applying the provided mapping functions to the input elements.

The Stream being collected may contain null elements, if the mapping functions handle nulls. However, like Collectors.toMap(Function, Function), this collector uses a HashMap to collect keys and values. Since its implementation is uses merge(K, V, BiFunction), the valueMapper may not produce null values, even for null inputs, or a NullPointerException will be thrown. The keyMapper, on the other hand, may return null keys, but may not return duplicate keys or an IllegalStateException will be thrown.

Parameters
keyMapper a mapping function to produce keys, which may return null
valueMapper a mapping function to produce values, which may not return null
Returns
  • a Collector which collects elements into an immutable map

@Nonnull public static Collector<T, ?, Set<T>> toImmutableSet ()

Returns a Collector that accumulates elements into an immutable set.

The Stream being collected may contain null elements and, when it does, the collected set will also contain a null element. Unlike Collectors.toSet(), this collector attempts to retain the traversal order of the stream's elements.

Returns
  • a Collector which collects elements into an immutable set
See Also