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

net.dongliu.commons.function.Suppliers Maven / Gradle / Ivy

There is a newer version: 12.0.2
Show newest version
package net.dongliu.commons.function;

import net.dongliu.commons.Result;

import java.util.Objects;
import java.util.function.Supplier;

/**
 * Utils method for Supplier
 */
public class Suppliers {

    /**
     * Run a Supplier, and return Result.
     *
     * @throws NullPointerException if supplier if null, or supplier returns null.
     */
    public static  Result run(Supplier supplier) {
        Objects.requireNonNull(supplier);
        T value;
        try {
            value = supplier.get();
        } catch (Throwable e) {
            return Result.failed(e);
        }
        return Result.of(value);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy