All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ansitable.Collectors Maven / Gradle / Ivy

The newest version!
package ansitable;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;

import java.util.Set;
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;

public final class Collectors {
    private Collectors() {}

    private static final class ImmutableListCollector implements Collector, ImmutableList> {
        @Override
        public Supplier> supplier() {
            return ImmutableList::builder;
        }

        @Override
        public BiConsumer, T> accumulator() {
            return (builder, elem) -> builder.add(elem);
        }

        @Override
        public BinaryOperator> combiner() {
            return (left, right) -> left.addAll(right.build());
        }

        @Override
        public Function, ImmutableList> finisher() {
            return ImmutableList.Builder::build;
        }

        @Override
        public Set characteristics() {
            return ImmutableSet.of();
        }
    }

    public static  Collector, ImmutableList> toImmutableList() {
        return new ImmutableListCollector<>();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy