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

com.softicar.platform.common.core.utils.NullUtils Maven / Gradle / Ivy

Go to download

The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.

There is a newer version: 50.0.0
Show newest version
package com.softicar.platform.common.core.utils;

import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;

public class NullUtils {

	/**
	 * Applies the given {@link Function} to the given value iff the given value
	 * is not null.
	 * 

* Workaround for Java lacking a null coalescing operator. * * @param value * @param applyMeIfNonNull * @return Iff the given value is not null, the result of applying the given * {@link Function} to the given value is returned. Null otherwise. */ public static R ifNotNull(V value, Function applyMeIfNonNull) { return ifNotNull(value, applyMeIfNonNull, null); } /** * WARNING: This method must not be used with a non-null third argument on a * Java 1.8.0_45 runtime, due to a compiler bug. */ private static R ifNotNull(V value, Function applyMeIfNonNull, R returnMeIfNull) { return (value != null)? applyMeIfNonNull.apply(value) : returnMeIfNull; } public static void consumeIfNotNull(V value, Consumer applyMeIfNonNull) { if (value != null) { applyMeIfNonNull.accept(value); } } public static R supplyIfNotNull(V value, Supplier applyMeIfNonNull) { return (value != null)? applyMeIfNonNull.get() : null; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy