Package ushiosan.jvm

Class UObject


public final class UObject extends UObjectValidators
  • Method Details

    • isNull

      public static boolean isNull(@Nullable @Nullable Object obj)
      Checks if an object or reference is null. This method also checks if an object of type Optional is empty (this means that the reference is null).
      Parameters:
      obj - the object to inspect
      Returns:
      true if reference is null or false otherwise
      See Also:
    • isNotNull

      public static boolean isNotNull(@Nullable @Nullable Object obj)
      Checks if an object or reference is not null. This method also checks if an object of type Optional is empty (this means that the reference is null).
      Parameters:
      obj - the object to inspect
      Returns:
      true if reference is not null or false otherwise
      See Also:
    • notNull

      @NotNull public static <T> T notNull(@Nullable T obj, @NotNull T defaultValue)
      Method used to prevent null references and avoid errors for this type of objects.
      Type Parameters:
      T - generic object type
      Parameters:
      obj - the object to inspect
      defaultValue - default value used when reference is null
      Returns:
      the original reference if not null or the default value otherwise
      Throws:
      IllegalArgumentException - error if defaultValue is null
    • notNull

      public static <T> void notNull(@Nullable T obj, @NotNull UEmptyFun.UEmptyFun1<T> action)
      Method used to prevent null references and avoid errors for this type of objects.
      Type Parameters:
      T - generic object type
      Parameters:
      obj - the object to inspect
      action - the action that is executed when the reference is not null
      Throws:
      IllegalArgumentException - error if action is null
    • requireNotNull

      public static void requireNotNull(@Nullable @Nullable Object obj, @Nullable @Nullable String name)
      Checks that a given argument is not null
      Parameters:
      obj - the object to inspect
      name - the parameter name
      Throws:
      IllegalArgumentException - error when the value passed as a parameter is a null value
    • requireNotNull

      public static void requireNotNull(@Nullable @Nullable Object obj)
      Checks that a given argument is not null
      Parameters:
      obj - the object to inspect
    • canCast

      public static boolean canCast(@Nullable @Nullable Object obj, @NotNull @NotNull Class<?> cls, boolean nullable)
      Check if one object can be cast to another type.

      Be careful: Remember that null values are valid candidates to change to any data type (except primitive types).

      Parameters:
      obj - the object to check
      cls - target class to convert
      nullable - param used to accept null objects
      Returns:
      return true if the object can be converted to the desired type or false otherwise
    • canCast

      public static boolean canCast(@Nullable @Nullable Object obj, @NotNull @NotNull Class<?> cls)
      Check if one object can be cast to another type.

      Be careful: Remember that null values are valid candidates to change to any data type (except primitive types).

      Parameters:
      obj - the object to check
      cls - target class to convert
      Returns:
      return true if the object can be converted to the desired type or false otherwise
    • canCastNotNull

      public static boolean canCastNotNull(@Nullable @Nullable Object obj, @NotNull @NotNull Class<?> cls)
      Check if one object can be cast to another type.

      Be careful: Remember that null values are valid candidates to change to any data type (except primitive types).

      Parameters:
      obj - the object to check
      cls - target class to convert
      Returns:
      return true if the object can be converted to the desired type or false otherwise
    • cast

      public static <T> T cast(@Nullable @Nullable Object obj)
      Recast the object towards the assigned destination.

      Note: this method returns the result depending on the context

      Be careful: this method must be sure that the object is of the desired type, or it will generate an error.

      Type Parameters:
      T - class cast type
      Parameters:
      obj - the object to convert
      Returns:
      the transformed object
      Throws:
      ClassCastException - error if object is not compatible type
    • cast

      public static <T> T cast(@Nullable @Nullable Object obj, @NotNull @NotNull Class<T> cls)
      Recast the object towards the assigned destination.

      Be careful: this method must be sure that the object is of the desired type, or it will generate an error.

      Type Parameters:
      T - class cast type
      Parameters:
      obj - the object to convert
      cls - target class to convert
      Returns:
      the transformed object
      Throws:
      ClassCastException - error if object is not compatible type
    • tryCast

      public static <T> void tryCast(@Nullable @Nullable Object obj, @NotNull @NotNull Class<T> cls, @NotNull UEmptyFun.UEmptyFun1<T> action)
      Tries to recast the object towards the assigned destination, but does not generate an error. Instead, the action passed as the third parameter is executed, as long as the condition is true.
      Type Parameters:
      T - class cast type
      Parameters:
      obj - the object to convert
      cls - the class to which you want to promote
      action - the action to execute if casting is valid
      Throws:
      IllegalArgumentException - error if cls or action are null
    • tryCast

      @NotNull public static <T> @NotNull Optional<T> tryCast(@Nullable @Nullable Object obj, @NotNull @NotNull Class<T> cls)
      Tries to recast the object towards the assigned destination, but does not generate an error. Instead, the action passed as the third parameter is executed, as long as the condition is true.
      Type Parameters:
      T - class cast type
      Parameters:
      obj - the object to convert
      cls - the class to which you want to promote
      Returns:
      the object to the target data type or Optional.empty() if the cast is invalid
      Throws:
      IllegalArgumentException - error if cls is null
    • toString

      @NotNull public static @NotNull String toString(@Nullable @Nullable Object object, boolean verbose)
      Generates a text with the representation of the object. Very similar to what the Object.toString() method does, but it ensures that all objects have an easily identifiable representation.
      Parameters:
      object - the object that you want to get the text representation
      verbose - option used to determine if the output will be long or simple
      Returns:
      object string representation
    • toString

      @NotNull public static @NotNull String toString(@Nullable @Nullable Object object)
      Generates a text with the representation of the object. Very similar to what the Object.toString() method does, but it ensures that all objects have an easily identifiable representation.
      Parameters:
      object - the object that you want to get the text representation
      Returns:
      object string representation
    • printRef

      public static void printRef(@NotNull @NotNull PrintStream printStream, @Nullable @Nullable Object format, Object @Nullable ... args)
      Write information into a data stream
      Parameters:
      printStream - the data stream you want to write
      format - the data writing format
      args - the data format arguments
      See Also:
    • printlnRef

      public static void printlnRef(@NotNull @NotNull PrintStream printStream, @Nullable @Nullable Object format, Object @Nullable ... args)
      Write information into a data stream (insert a line break at the end of the content)
      Parameters:
      printStream - the data stream you want to write
      format - the data writing format
      args - the data format arguments
      See Also:
    • print

      public static void print(@Nullable @Nullable Object format, Object @Nullable ... args)
      Write information into a data stream
      Parameters:
      format - the data writing format
      args - the data format arguments
      See Also:
    • printErr

      public static void printErr(@Nullable @Nullable Object format, Object @Nullable ... args)
      Write information into a data stream
      Parameters:
      format - the data writing format
      args - the data format arguments
      See Also:
    • println

      public static void println(@NotNull @NotNull Object format, Object @Nullable ... args)
      Write information into a data stream (insert a line break at the end of the content)
      Parameters:
      format - the data writing format
      args - the data format arguments
      See Also:
    • printlnErr

      public static void printlnErr(@NotNull @NotNull Object format, Object @Nullable ... args)
      Write information into a data stream (insert a line break at the end of the content)
      Parameters:
      format - the data writing format
      args - the data format arguments
      See Also:
    • println

      public static void println()
      Write information into a data stream (insert a line break at the end of the content)
      See Also:
    • printRefV

      public static void printRefV(@NotNull @NotNull PrintStream printStream, @Nullable @Nullable Object format, Object @Nullable ... args)
      Write information into a data stream
      Parameters:
      printStream - the data stream you want to write
      format - the data writing format
      args - the data format arguments
      See Also:
    • printlnRefV

      public static void printlnRefV(@NotNull @NotNull PrintStream printStream, @Nullable @Nullable Object format, Object @Nullable ... args)
      Write information into a data stream (insert a line break at the end of the content)
      Parameters:
      printStream - the data stream you want to write
      format - the data writing format
      args - the data format arguments
      See Also:
    • printV

      public static void printV(@Nullable @Nullable Object format, Object @Nullable ... args)
      Write information into a data stream
      Parameters:
      format - the data writing format
      args - the data format arguments
      See Also:
    • printErrV

      public static void printErrV(@Nullable @Nullable Object format, Object @Nullable ... args)
      Write information into a data stream
      Parameters:
      format - the data writing format
      args - the data format arguments
      See Also:
    • printlnV

      public static void printlnV(@NotNull @NotNull Object format, Object @Nullable ... args)
      Write information into a data stream (insert a line break at the end of the content)
      Parameters:
      format - the data writing format
      args - the data format arguments
      See Also:
    • printlnErrV

      public static void printlnErrV(@NotNull @NotNull Object format, Object @Nullable ... args)
      Write information into a data stream (insert a line break at the end of the content)
      Parameters:
      format - the data writing format
      args - the data format arguments
      See Also: