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

com.github.sseserver.util.LambdaUtil Maven / Gradle / Ivy

There is a newer version: 1.2.19
Show newest version
package com.github.sseserver.util;

import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;

public class LambdaUtil {

    public static  void sneakyThrows(Throwable t) throws E {
        throw (E) t;
    }

    public static  Function noop() {
        return o -> o;
    }

    public static Supplier defaultFalse() {
        return () -> Boolean.FALSE;
    }

    public static  Supplier defaultNull() {
        return () -> null;
    }

    public static Supplier defaultZero() {
        return () -> 0;
    }

    public static  BiFunction filterNull() {
        return (o1, o2) -> o1 != null ? o1 : o2;
    }

    public static , E> BiFunction reduceList() {
        return (o1, o2) -> {
            o1.addAll(o2);
            return o1;
        };
    }

    public static > Function> distinct() {
        return o -> new ArrayList<>(new LinkedHashSet<>(o));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy