Class ObjUtil

java.lang.Object
de.eldoria.eldoutilities.utils.ObjUtil

public final class ObjUtil extends Object
General handling of objects.
Since:
1.0.0
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> boolean
    nonNull(T obj, Consumer<T> execute)
    Consumes a object if object is not null
    static <T> boolean
    nonNull(T obj, Consumer<T> execute, Runnable runnable)
    Consumes a object if object is not null or executes a runnable when object is null
    static <T, U> U
    nonNull(T obj, Function<T,U> execute)
    Execute a function on a object if the object is not null
    static <T> T
    nonNull(T obj, T otherObject)
    get the object or the other object if object is null
    static <R, A> R
    nonNullOrElse(A obj, Function<A,R> function, R defaultVal)
    Executes a function on object and return value or default value if object is null

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • nonNull

      public static <T> boolean nonNull(@Nullable T obj, Consumer<T> execute)
      Consumes a object if object is not null
      Type Parameters:
      T - type of object
      Parameters:
      obj - object to condume
      execute - consumer to handle object
      Returns:
      true if the object was not null and the consumer was applied
    • nonNull

      public static <T> boolean nonNull(@Nullable T obj, Consumer<T> execute, Runnable runnable)
      Consumes a object if object is not null or executes a runnable when object is null
      Type Parameters:
      T - type of object
      Parameters:
      obj - object to condume
      execute - consumer to handle object
      runnable - runnable to run when object is null
      Returns:
      true if the object was not null and the consumer was applied false if the object was null
    • nonNull

      public static <T, U> U nonNull(@Nullable T obj, Function<T,U> execute)
      Execute a function on a object if the object is not null
      Type Parameters:
      T - object type
      U - return type
      Parameters:
      obj - object to check
      execute - function to parse object to return type
      Returns:
      object of return type U
    • nonNull

      public static <T> T nonNull(@Nullable T obj, @NotNull T otherObject)
      get the object or the other object if object is null
      Type Parameters:
      T - type of object
      Parameters:
      obj - object to check
      otherObject - other object
      Returns:
      object or other object if object is null
    • nonNullOrElse

      public static <R, A> R nonNullOrElse(@Nullable A obj, Function<A,R> function, R defaultVal)
      Executes a function on object and return value or default value if object is null
      Type Parameters:
      R - type of output object
      A - type of input object
      Parameters:
      obj - object
      function - function to parse
      defaultVal - default value
      Returns:
      value of function or default value