jp.skypencil.guava.stream.MultimapCollector Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of helper Show documentation
Show all versions of helper Show documentation
Helper classes to help Java8 to collaborate with Guava
The newest version!
package jp.skypencil.guava.stream;
import java.util.function.BiConsumer;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collector;
import com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.Multimap;
abstract class MultimapCollector>
implements Collector, R> {
private Function super T, ? extends K> keyMapper;
private Function super T, ? extends U> valueMapper;
MultimapCollector(Function super T, ? extends K> keyMapper,
Function super T, ? extends U> valueMapper) {
this.keyMapper = keyMapper;
this.valueMapper = valueMapper;
}
@Override
public Supplier> supplier() {
return LinkedListMultimap::create;
}
@Override
public BiConsumer, T> accumulator() {
return (map, data) ->
map.put(keyMapper.apply(data), valueMapper.apply(data))
;
}
@Override
public BinaryOperator> combiner() {
return (map, another) -> {
map.putAll(another);
return map;
};
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy