Class ObjectUtils

java.lang.Object
com.kingsrook.qqq.backend.core.utils.ObjectUtils

public class ObjectUtils extends Object
  • Constructor Details

    • ObjectUtils

      public ObjectUtils()
  • Method Details

    • requireNonNullElse

      @SafeVarargs public static <T> T requireNonNullElse(T... objects)
      A varargs version of Objects.requireNonNullElse
    • tryElse

      public static <T> T tryElse(UnsafeSupplier<T,?> supplier, T defaultIfThrew)
      Like Objects.requireNonNullElse, only use an (unsafe) supplier as the first arg, and only if it throws, return the 2nd arg
    • tryAndRequireNonNullElse

      public static <T> T tryAndRequireNonNullElse(UnsafeSupplier<T,?> supplier, T defaultIfThrew)
      Like Objects.requireNonNullElse, only use an (unsafe) supplier as the first arg, and if it throws or returns null, then return the 2nd arg
    • ifNotNull

      public static <T> void ifNotNull(T object, Consumer<T> consumer)
    • ifNotNullUnsafe

      public static <T, E extends Exception> void ifNotNullUnsafe(T object, UnsafeConsumer<T,E> consumer) throws E
      Throws:
      E
    • requireConditionElse

      public static <T> T requireConditionElse(T a, Predicate<T> condition, T b)
    • ifCan

      public static boolean ifCan(UnsafeSupplier<Boolean,? extends Throwable> supplier)
      Utility to test a chained unsafe expression CAN get to the end and return true. e.g., instead of: if(a invalid input: '&'invalid input: '&' a.b invalid input: '&'invalid input: '&' a.b.c invalid input: '&'invalid input: '&' a.b.c.d) we can do: if(ifCan(() -> a.b.c.d)) Note - if the supplier returns null, that counts as false!