Class JavaLangUtils

java.lang.Object
com.sun.enterprise.universal.JavaLangUtils

public final class JavaLangUtils extends Object
Utility class for all trivial functions missing in Java.
Author:
David Matejcek
  • Method Details

    • nonNull

      public static <T> T nonNull(T value, Supplier<? extends T> supplierOfDefault)
      If the value is null, calls the supplier to obtain the default value.
      Type Parameters:
      T - expected type
      Parameters:
      value - provided value
      supplierOfDefault - must not be null.
      Returns:
      value OR value provided by the supplier. Note that it may be null too.
    • nonNull

      public static <V, T> T nonNull(V value, Function<V,T> function, Supplier<? extends T> supplierOfDefault)
      If the value is null, calls the supplier to obtain the default value.

      If the value is not null, applies the function.

      Type Parameters:
      V - input value type
      T - expected type
      Parameters:
      value - provided value - can be null
      function - function to apply to the value. Must not be null.
      supplierOfDefault - can be null, then supplies null.
      Returns:
      result of a function OR value provided by the supplier. Note that the returned value may be null too.