Class ObjectUtils

java.lang.Object
dev.prozilla.pine.common.util.ObjectUtils

public final class ObjectUtils extends Object
Utility methods related to objects.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <I, O> O
    preserveNull(I input, Function<I,O> function)
    Applies a function to an object and returns the result, or immediately returns null without calling the function if the input object is null.
    static boolean
    unbox(Boolean value)
    Safely unboxes a boxed value and turns null into the default value.
    static char
    Safely unboxes a boxed value and turns null into the default value.
    static float
    unbox(Float value)
    Safely unboxes a boxed value and turns null into the default value.
    static int
    unbox(Integer value)
    Safely unboxes a boxed value and turns null into the default value.

    Methods inherited from class java.lang.Object

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

    • preserveNull

      @Contract("null, _ -> null") public static <I, O> O preserveNull(I input, Function<I,O> function)
      Applies a function to an object and returns the result, or immediately returns null without calling the function if the input object is null.
      Type Parameters:
      I - The type of the input object
      O - The type of the result object
      Parameters:
      input - The input object
      function - The function to apply to the object
      Returns:
      The result of the function, or null.
    • unbox

      public static int unbox(Integer value)
      Safely unboxes a boxed value and turns null into the default value.
      Parameters:
      value - The boxed value
      Returns:
      The unboxed value.
    • unbox

      public static float unbox(Float value)
      Safely unboxes a boxed value and turns null into the default value.
      Parameters:
      value - The boxed value
      Returns:
      The unboxed value.
    • unbox

      public static boolean unbox(Boolean value)
      Safely unboxes a boxed value and turns null into the default value.
      Parameters:
      value - The boxed value
      Returns:
      The unboxed value.
    • unbox

      public static char unbox(Character value)
      Safely unboxes a boxed value and turns null into the default value.
      Parameters:
      value - The boxed value
      Returns:
      The unboxed value.