Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.bitbucket.cowwoc.guava.stream;
  
Builds a stream java.util.stream.Collector that returns a com.google.common.collect.Table.

Parameters:
<T> the type of the input elements
<R> the type of rows stored in the table
<C> the type of columns stored in the table
<V> the type of values stored in the table
<O> the output type of the collector
Author(s):
Gili Tzabari
 
 public abstract class TableCollectorBuilder<T, R, C, V, O extends Table<R, C, V>>
 {
 	private final Function<? super T, ? extends R> rowMapper;
 	private final Function<? super T, ? extends C> columnMapper;
 	private final Function<? super T, ? extends V> valueMapper;
 	private Supplier<Table<R, C, V>> supplier;
 	private Function<Table<R, C, V>, O> finisher;
 	private Comparator<? super R> rowComparator;
 	private Comparator<? super C> columnComparator;

Creates a new builder.

Parameters:
rowMapper a function that transforms the input into table rows
columnMapper a function that transforms the input into table columns
valueMapper a function that transforms the input into table values
supplier a function which returns a new, empty Table into which intermediate results will be added
finisher a function that transforms the intermediate Table into the final result
characteristics the collector characteristics
Throws:
java.lang.NullPointerException if any of the arguments are null
 
 	public TableCollectorBuilder(Function<? super T, ? extends R> rowMapper,
 		Function<? super T, ? extends C> columnMapperFunction<? super T, ? extends V> valueMapper,
 		Supplier<Table<R, C, V>> supplierFunction<Table<R, C, V>, O> finisher,
 		Characteristics... characteristics)
 	{
 		Preconditions.requireThat(rowMapper"rowMapper").isNotNull();
 		Preconditions.requireThat(columnMapper"columnMapper").isNotNull();
 		Preconditions.requireThat(valueMapper"valueMapper").isNotNull();
 		Preconditions.requireThat(supplier"supplier").isNotNull();
 		Preconditions.requireThat(finisher"finisher").isNotNull();
 		Preconditions.requireThat(characteristics"characteristics").isNotNull();
 
 		this. = rowMapper;
 		this. = columnMapper;
 		this. = valueMapper;
 		this. = supplier;
 		this. = finisher;
 		this. = characteristics;
 	}

Returns:
a function that transforms the input into table rows
 
 	public Function<? super T, ? extends R> rowMapper()
 	{
 		return ;
 	}

Returns:
a function that transforms the input into table columns
 
 	public Function<? super T, ? extends C> columnMapper()
 	{
 		return ;
 	}

Returns:
a function that transforms the input into table values
 
 	public Function<? super T, ? extends V> valueMapper()
 	{
 		return ;
 	}

Returns:
a function which returns a new, empty Table into which intermediate results will be added
 
 	public Supplier<Table<R, C, V>> supplier()
 	{
 		return ;
 	}

Parameters:
supplier a function which returns a new, empty Table into which intermediate results will be added
Returns:
this
Throws:
java.lang.NullPointerException if supplier is null
	public TableCollectorBuilder<T, R, C, V, O> supplier(Supplier<Table<R, C, V>> supplier)
	{
		Preconditions.requireThat(supplier"supplier").isNotNull();
		this. = supplier;
		return this;
	}

Returns:
a function that transforms the intermediate Table into the final result
	public Function<Table<R, C, V>, O> finisher()
	{
		return ;
	}

Sets a function that transforms the intermediate Table into the final result.

Make sure to update the collector characteristics if necessary.

Parameters:
finisher a function that transforms the intermediate Table into the final result
Returns:
this
Throws:
java.lang.NullPointerException if finisher is null
	public TableCollectorBuilder<T, R, C, V, O> finisher(Function<Table<R, C, V>, O> finisher)
	{
		Preconditions.requireThat(finisher"finisher").isNotNull();
		this. = finisher;
		return this;
	}

Returns:
the collector characteristics
	@SuppressWarnings("ReturnOfCollectionOrArrayField")
	{
	}

Parameters:
characteristics the collector characteristics
Returns:
this
Throws:
java.lang.NullPointerException if characteristics is null
	@SuppressWarnings("AssignmentToCollectionOrArrayFieldFromParameter")
	public TableCollectorBuilder<T, R, C, V, O> characteristics(
		Characteristics... characteristicsthrows NullPointerException
	{
		Preconditions.requireThat(characteristics"characteristics").isNotNull();
		this. = characteristics;
		return this;
	}

Returns:
a new collector
	public Collector<T, ?, O> build()
	{
		BiConsumer<Table<R, C, V>, T> accumulator = (tableinput) ->
		{
row = .apply(input);
			if (row == null)
				throw new IllegalArgumentException("rowMapper(" + input + ") returned null");
column = .apply(input);
			if (column == null)
				throw new IllegalArgumentException("rowMapper(" + input + ") returned null");
value = .apply(input);
			if (value == null)
				throw new IllegalArgumentException("valueMapper(" + input + ") returned null");
			table.put(rowcolumnvalue);
		};
		BinaryOperator<Table<R, C, V>> combiner = (leftright) ->
		{
			left.putAll(right);
			return left;
		};
		return Collector.of(accumulatorcombiner);
	}
New to GrepCode? Check out our FAQ X