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

io.linguarobot.aws.cdk.maven.MoreCollectors Maven / Gradle / Ivy

Go to download

The AWS CDK Maven plugin produces and deploys CloudFormation templates based on the cloud infrastructure defined by means of CDK. The goal of the project is to improve the experience of Java developers while working with CDK by eliminating the need for installing Node.js and interacting with the CDK application by means of CDK Toolkit.

There is a newer version: 0.0.8
Show newest version
package io.linguarobot.aws.cdk.maven;

import java.util.Comparator;
import java.util.stream.Collector;
import java.util.stream.Collectors;

/**
 * Contains additional implementations of {@link Collector}.
 */
public final class MoreCollectors {

    private MoreCollectors() {
    }

    /**
     * Returns a {@link Collector} that will sort elements of the stream before passing them to the downstream collector.
     *
     * @param downstreamCollector a collector that will accept the sorted elements
     * @param  the types of the input elements
     * @param  the result type of the collector
     *
     * @return a collector sorting the elements of the stream before passing them to the next, downstream collector
     */
    public static , R> Collector sorting(Collector downstreamCollector) {
        return sorting(Comparator.naturalOrder(), downstreamCollector);
    }

    /**
     * Returns a {@link Collector} that will sort elements of the stream using the given comparator before passing
     * them to the downstream collector.
     *
     * @param comparator the comparator used to compare the elements of the stream
     * @param downstreamCollector a collector that will accept the sorted elements
     * @param  the types of the input elements
     * @param  the result type of the collector
     *
     * @return a collector sorting the elements of the stream before passing them to the next, downstream collector
     */
    public static  Collector sorting(Comparator comparator, Collector downstreamCollector) {
        return Collectors.collectingAndThen(
                Collectors.toList(),
                values -> values.stream().sorted(comparator).collect(downstreamCollector)
        );
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy