Top Description Inners Fields Constructors Methods
org.apache.commons.lang3.stream

public final Class LangCollectors

extends Object
Class Inheritance
Imports
java.util.Arrays, .Collections, .Objects, .Set, .StringJoiner, java.util.function.BiConsumer, .BinaryOperator, .Function, .Supplier, java.util.stream.Collector, .Collectors, .Stream, org.apache.commons.lang3.StringUtils

Implementations of Collector that implement various reduction operations.

This class is called LangCollectors instead of Collectors to avoid clashes with Collectors.

Since
3.13.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
LangCollectors.SimpleCollector<
the type of elements to be collected
T
, A,
the type of the result
R
>

Simple implementation class for Collector.

Field Summary

Modifier and TypeField and Description
private static final Set<Collector.Characteristics>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static <
The type of the array elements.
T
,
the type of the result.
R
,
the intermediate accumulation type of the Collector.
A
>
R

Returns:

the result of the reduction
collect
(final Collector<? super T, A, R>
the Collector describing the reduction.
collector
,
final T...
The array, assumed to be unmodified during use, a null array treated as an empty array.
array
)

Delegates to Stream#collect(Collector) for a Stream on the given array.

public static Collector<Object, ?, String>

Returns:

A Collector which concatenates Object elements, separated by the specified delimiter, in encounter order.
joining
()

Returns a Collector that concatenates the input elements, separated by the specified delimiter, in encounter order.

public static Collector<Object, ?, String>

Returns:

A Collector which concatenates Object elements, separated by the specified delimiter, in encounter order.
joining
(final CharSequence
the delimiter to be used between each element.
delimiter
)

Returns a Collector that concatenates the input elements, separated by the specified delimiter, in encounter order.

public static Collector<Object, ?, String>

Returns:

A Collector which concatenates CharSequence elements, separated by the specified delimiter, in encounter order
joining
(final CharSequence
the delimiter to be used between each element
delimiter
,
final CharSequence
the sequence of characters to be used at the beginning of the joined result
prefix
,
final CharSequence
the sequence of characters to be used at the end of the joined result
suffix
)

Returns a Collector that concatenates the input elements, separated by the specified delimiter, with the specified prefix and suffix, in encounter order.

public static Collector<Object, ?, String>

Returns:

A Collector which concatenates CharSequence elements, separated by the specified delimiter, in encounter order
joining
(final CharSequence
the delimiter to be used between each element
delimiter
,
final CharSequence
the sequence of characters to be used at the beginning of the joined result
prefix
,
final CharSequence
the sequence of characters to be used at the end of the joined result
suffix
,
final Function<Object, String>
A function that takes an Object and returns a non-null String.
toString
)

Returns a Collector that concatenates the input elements, separated by the specified delimiter, with the specified prefix and suffix, in encounter order.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CH_NOIDback to summary
private static final Set<Collector.Characteristics> CH_NOID

Constructor Detail

LangCollectorsback to summary
private LangCollectors()

Method Detail

collectback to summary
public static <T, R, A> R collect(final Collector<? super T, A, R> collector, final T... array)

Delegates to Stream#collect(Collector) for a Stream on the given array.

Parameters
<T>
The type of the array elements.
<R>
the type of the result.
<A>
the intermediate accumulation type of the Collector.
collector:Collector<? super T, A, R>

the Collector describing the reduction.

array:T[]

The array, assumed to be unmodified during use, a null array treated as an empty array.

Returns:R

the result of the reduction

Annotations
@SafeVarargs
Since
3.16.0
See Also
Stream#collect(Collector), Arrays#stream(Object[]), Collectors
joiningback to summary
public static Collector<Object, ?, String> joining()

Returns a Collector that concatenates the input elements, separated by the specified delimiter, in encounter order.

This is a variation of Collectors#joining() that works with any element class, not just CharSequence.

For example:

Stream.of(Long.valueOf(1), Long.valueOf(2), Long.valueOf(3))
   .collect(LangCollectors.joining())
returns "123"
Returns:Collector<Object, ?, String>

A Collector which concatenates Object elements, separated by the specified delimiter, in encounter order.

joiningback to summary
public static Collector<Object, ?, String> joining(final CharSequence delimiter)

Returns a Collector that concatenates the input elements, separated by the specified delimiter, in encounter order.

This is a variation of Collectors#joining(CharSequence) that works with any element class, not just CharSequence.

For example:

Stream.of(Long.valueOf(1), Long.valueOf(2), Long.valueOf(3))
  .collect(LangCollectors.joining("-"))
returns "1-2-3"
Parameters
delimiter:CharSequence

the delimiter to be used between each element.

Returns:Collector<Object, ?, String>

A Collector which concatenates Object elements, separated by the specified delimiter, in encounter order.

joiningback to summary
public static Collector<Object, ?, String> joining(final CharSequence delimiter, final CharSequence prefix, final CharSequence suffix)

Returns a Collector that concatenates the input elements, separated by the specified delimiter, with the specified prefix and suffix, in encounter order.

This is a variation of Collectors#joining(CharSequence, CharSequence, CharSequence) that works with any element class, not just CharSequence.

For example:

Stream.of(Long.valueOf(1), Long.valueOf(2), Long.valueOf(3))
  .collect(LangCollectors.joining("-", "[", "]"))
returns "[1-2-3]"
Parameters
delimiter:CharSequence

the delimiter to be used between each element

prefix:CharSequence

the sequence of characters to be used at the beginning of the joined result

suffix:CharSequence

the sequence of characters to be used at the end of the joined result

Returns:Collector<Object, ?, String>

A Collector which concatenates CharSequence elements, separated by the specified delimiter, in encounter order

joiningback to summary
public static Collector<Object, ?, String> joining(final CharSequence delimiter, final CharSequence prefix, final CharSequence suffix, final Function<Object, String> toString)

Returns a Collector that concatenates the input elements, separated by the specified delimiter, with the specified prefix and suffix, in encounter order.

This is a variation of Collectors#joining(CharSequence, CharSequence, CharSequence) that works with any element class, not just CharSequence.

For example:

Stream.of(Long.valueOf(1), null, Long.valueOf(3))
  .collect(LangCollectors.joining("-", "[", "]", o -> Objects.toString(o, "NUL")))
returns "[1-NUL-3]"
Parameters
delimiter:CharSequence

the delimiter to be used between each element

prefix:CharSequence

the sequence of characters to be used at the beginning of the joined result

suffix:CharSequence

the sequence of characters to be used at the end of the joined result

toString:Function<Object, String>

A function that takes an Object and returns a non-null String.

Returns:Collector<Object, ?, String>

A Collector which concatenates CharSequence elements, separated by the specified delimiter, in encounter order

org.apache.commons.lang3.stream back to summary

private final Class LangCollectors.SimpleCollector<T, A, R>

extends Object
implements Collector<T, A, R>
Class Inheritance
  • java.lang.Object
  • org.apache.commons.lang3.stream.LangCollectors.SimpleCollector
All Implemented Interfaces
java.util.stream.Collector
Type Parameters
<T>
the type of elements to be collected
<R>
the type of the result

Simple implementation class for Collector.

Field Summary

Modifier and TypeField and Description
private final BiConsumer<A, T>
private final Set<Collector.Characteristics>
private final BinaryOperator<A>
private final Function<A, R>
private final Supplier<A>

Constructor Summary

AccessConstructor and Description
private
SimpleCollector(final Supplier<A> supplier, final BiConsumer<A, T> accumulator, final BinaryOperator<A> combiner, final Function<A, R> finisher, final Set<Collector.Characteristics> characteristics)

Method Summary

Modifier and TypeMethod and Description
public BiConsumer<A, T>
accumulator()

Implements java.util.stream.Collector.accumulator.

A function that folds a value into a mutable result container.

public Set<Collector.Characteristics>
characteristics()

Implements java.util.stream.Collector.characteristics.

Returns a Set of Collector.Characteristics indicating the characteristics of this Collector.

public BinaryOperator<A>
combiner()

Implements java.util.stream.Collector.combiner.

A function that accepts two partial results and merges them.

public Function<A, R>
finisher()

Implements java.util.stream.Collector.finisher.

Perform the final transformation from the intermediate accumulation type A to the final result type R.

public Supplier<A>
supplier()

Implements java.util.stream.Collector.supplier.

A function that creates and returns a new mutable result container.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

accumulatorback to summary
private final BiConsumer<A, T> accumulator
characteristicsback to summary
private final Set<Collector.Characteristics> characteristics
combinerback to summary
private final BinaryOperator<A> combiner
finisherback to summary
private final Function<A, R> finisher
supplierback to summary
private final Supplier<A> supplier

Constructor Detail

SimpleCollectorback to summary
private SimpleCollector(final Supplier<A> supplier, final BiConsumer<A, T> accumulator, final BinaryOperator<A> combiner, final Function<A, R> finisher, final Set<Collector.Characteristics> characteristics)

Method Detail

accumulatorback to summary
public BiConsumer<A, T> accumulator()

Implements java.util.stream.Collector.accumulator.

Doc from java.util.stream.Collector.accumulator.

A function that folds a value into a mutable result container.

Annotations
@Override
characteristicsback to summary
public Set<Collector.Characteristics> characteristics()

Implements java.util.stream.Collector.characteristics.

Doc from java.util.stream.Collector.characteristics.

Returns a Set of Collector.Characteristics indicating the characteristics of this Collector. This set should be immutable.

Annotations
@Override
combinerback to summary
public BinaryOperator<A> combiner()

Implements java.util.stream.Collector.combiner.

Doc from java.util.stream.Collector.combiner.

A function that accepts two partial results and merges them. The combiner function may fold state from one argument into the other and return that, or may return a new result container.

Annotations
@Override
finisherback to summary
public Function<A, R> finisher()

Implements java.util.stream.Collector.finisher.

Doc from java.util.stream.Collector.finisher.

Perform the final transformation from the intermediate accumulation type A to the final result type R.

If the characteristic IDENTITY_FINISH is set, this function may be presumed to be an identity transform with an unchecked cast from A to R.

Annotations
@Override
supplierback to summary
public Supplier<A> supplier()

Implements java.util.stream.Collector.supplier.

Doc from java.util.stream.Collector.supplier.

A function that creates and returns a new mutable result container.

Annotations
@Override