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

angry1980.utils.ImmutableCollectors Maven / Gradle / Ivy

There is a newer version: 0.0.10
Show newest version
package angry1980.utils;

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

import java.util.stream.Collector;

public class ImmutableCollectors {

    public static  Collector, ImmutableList> toList() {
        return Collector.of(
                ImmutableList.Builder::new,
                ImmutableList.Builder::add,
                (b1, b2) -> b1.addAll(b2.build()),
                (builder) -> builder.build()
        );
    }

    public static  Collector, ImmutableSet> toSet() {
        return Collector.of(
                ImmutableSet.Builder::new,
                ImmutableSet.Builder::add,
                (b1, b2) -> b1.addAll(b2.build()),
                (builder) -> builder.build()
        );
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy