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

pl.allegro.tech.hermes.common.http.ExtraRequestHeadersCollector Maven / Gradle / Ivy

There is a newer version: 2.6.21
Show newest version
package pl.allegro.tech.hermes.common.http;

import java.util.Collections;
import java.util.Map;
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 class ExtraRequestHeadersCollector implements Collector, StringBuilder, String> {
    private ExtraRequestHeadersCollector() {
    }

    public static ExtraRequestHeadersCollector extraRequestHeadersCollector() {
        return new ExtraRequestHeadersCollector();
    }

    @Override
    public Supplier supplier() {
        return StringBuilder::new;
    }

    @Override
    public BiConsumer> accumulator() {
        return (StringBuilder accumulator, Map.Entry entry) -> {
            accumulator.append(entry.getKey());
            accumulator.append(": ");
            accumulator.append(entry.getValue());
            accumulator.append('\n');
        };
    }

    @Override
    public BinaryOperator combiner() {
        return StringBuilder::append;
    }

    @Override
    public Function finisher() {
        return (StringBuilder acc) -> {
            if (acc.length() > 0) {
                acc.setLength(acc.length() - 1);
            }
            return acc.toString();
        };
    }

    @Override
    public Set characteristics() {
        return Collections.emptySet();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy