001/* 002 * Copyright 2002-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.util.function; 018 019import java.util.function.Supplier; 020 021import org.springframework.lang.Nullable; 022 023/** 024 * Convenience utilities for {@link java.util.function.Supplier} handling. 025 * 026 * @author Juergen Hoeller 027 * @since 5.1 028 * @see SingletonSupplier 029 */ 030public abstract class SupplierUtils { 031 032 /** 033 * Resolve the given {@code Supplier}, getting its result or immediately 034 * returning {@code null} if the supplier itself was {@code null}. 035 * @param supplier the supplier to resolve 036 * @return the supplier's result, or {@code null} if none 037 */ 038 @Nullable 039 public static <T> T resolve(@Nullable Supplier<T> supplier) { 040 return (supplier != null ? supplier.get() : null); 041 } 042 043}