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

com.mogudiandian.util.function.BinaryOperators Maven / Gradle / Ivy

package com.mogudiandian.util.function;

import java.util.function.BinaryOperator;

/**
 * 封装了常用的BinaryOperator
 *
 * @author Joshua Sun
 * @since 1.0.15
 */
public interface BinaryOperators {

    /**
     * Returns a {@link BinaryOperator} which returns the first argument it receives.
     *
     * @param  the type of the input arguments of the operator
     * @return a {@link BinaryOperator} which returns the first argument it receives
     */
    static  BinaryOperator useFirst() {
        return (t1, t2) -> t1;
    }

    /**
     * Returns a {@link BinaryOperator} which returns the last argument it receives.
     *
     * @param  the type of the input arguments of the operator
     * @return a {@link BinaryOperator} which returns the last argument it receives
     */
    static  BinaryOperator useLast() {
        return (t1, t2) -> t2;
    }

    /**
     * Returns a {@link BinaryOperator} which returns the first non-null argument it receives.
     *
     * @param  the type of the input arguments of the operator
     * @return a {@link BinaryOperator} which returns the first non-null argument it receives
     */
    static  BinaryOperator useFirstNonNull() {
        return (t1, t2) -> t1 != null ? t1 : t2;
    }

    /**
     * Returns a {@link BinaryOperator} which returns the last non-null argument it receives.
     *
     * @param  the type of the input arguments of the operator
     * @return a {@link BinaryOperator} which returns the last non-null argument it receives
     */
    static  BinaryOperator useLastNonNull() {
        return (t1, t2) -> t2 != null ? t2 : t1;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy