Source code
Description: source: package: org.apache.commons.lang3.function, interface: FailableSupplier

    001/*
    002 * Licensed to the Apache Software Foundation (ASF) under one or more
    003 * contributor license agreements.  See the NOTICE file distributed with
    004 * this work for additional information regarding copyright ownership.
    005 * The ASF licenses this file to You under the Apache License, Version 2.0
    006 * (the "License"); you may not use this file except in compliance with
    007 * the License.  You may obtain a copy of the License at
    008 *
    009 *      https://www.apache.org/licenses/LICENSE-2.0
    010 *
    011 * Unless required by applicable law or agreed to in writing, software
    012 * distributed under the License is distributed on an "AS IS" BASIS,
    013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    014 * See the License for the specific language governing permissions and
    015 * limitations under the License.
    016 */
    017
    018package org.apache.commons.lang3.function;
    019
    020import java.util.function.Supplier;
    021
    022/**
    023 * A functional interface like {@link Supplier} that declares a {@link Throwable}.
    024 *
    025 * @param <T> The type of results supplied by this supplier.
    026 * @param <E> The kind of thrown exception or error.
    027 * @since 3.11
    028 */
    029@FunctionalInterface
    030public interface FailableSupplier<T, E extends Throwable> {
    031
    032    /**
    033     * Returns the singleton supplier that always returns null.
    034     * <p>
    035     * This supplier never throws an exception.
    036     * </p>
    037     *
    038     * @since 3.14.0
    039     */
    040    @SuppressWarnings("rawtypes")
    041    FailableSupplier NUL = () -> null;
    042
    043    /**
    044     * Gets the singleton supplier that always returns null.
    045     * <p>
    046     * This supplier never throws an exception.
    047     * </p>
    048     *
    049     * @param <T> Supplied type.
    050     * @param <E> The kind of thrown exception or error.
    051     * @return The NUL singleton.
    052     * @since 3.14.0
    053     */
    054    @SuppressWarnings("unchecked")
    055    static <T, E extends Exception> FailableSupplier<T, E> nul() {
    056        return NUL;
    057    }
    058
    059    /**
    060     * Supplies an object
    061     *
    062     * @return a result
    063     * @throws E if the supplier fails
    064     */
    065    T get() throws E;
    066}