java.lang.Object
ushiosan.jvm.internal.validators.UObjectValidators
ushiosan.jvm.UObject
-
Field Summary
Fields inherited from class ushiosan.jvm.internal.validators.UObjectValidators
NULLABLE_VALIDATORS -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanCheck if one object can be cast to another type.static booleanCheck if one object can be cast to another type.static booleancanCastNotNull(@Nullable Object obj, @NotNull Class<?> cls) Check if one object can be cast to another type.static <T> TRecast the object towards the assigned destination.static <T> TRecast the object towards the assigned destination.static booleanChecks if an object or reference is not null.static booleanChecks if an object or reference is null.static <T> voidnotNull(T obj, @NotNull UEmptyFun.UEmptyFun1<T> action) Method used to prevent null references and avoid errors for this type of objects.static <T> TnotNull(T obj, T defaultValue) Method used to prevent null references and avoid errors for this type of objects.static voidWrite information into a data streamstatic voidWrite information into a data streamstatic voidWrite information into a data streamstatic voidprintln()Write information into a data stream (insert a line break at the end of the content)static voidWrite information into a data stream (insert a line break at the end of the content)static voidprintlnErr(@NotNull Object format, Object @Nullable ... args) Write information into a data stream (insert a line break at the end of the content)static voidprintlnErrV(@NotNull Object format, Object @Nullable ... args) Write information into a data stream (insert a line break at the end of the content)static voidprintlnRef(@NotNull PrintStream printStream, @Nullable Object format, Object @Nullable ... args) Write information into a data stream (insert a line break at the end of the content)static voidprintlnRefV(@NotNull PrintStream printStream, @Nullable Object format, Object @Nullable ... args) Write information into a data stream (insert a line break at the end of the content)static voidWrite information into a data stream (insert a line break at the end of the content)static voidWrite information into a data streamstatic voidWrite information into a data streamstatic voidWrite information into a data streamstatic voidChecks that a given argument is not nullstatic voidrequireNotNull(@Nullable Object obj, @Nullable String name) Checks that a given argument is not nullGenerates a text with the representation of the object.Generates a text with the representation of the object.Tries to recast the object towards the assigned destination, but does not generate an error.static <T> voidTries to recast the object towards the assigned destination, but does not generate an error.Methods inherited from class ushiosan.jvm.internal.validators.UObjectValidators
validate, validateNotNull
-
Method Details
-
isNull
Checks if an object or reference is null. This method also checks if an object of typeOptionalis empty (this means that the reference is null).- Parameters:
obj- the object to inspect- Returns:
trueif reference isnullorfalseotherwise- See Also:
-
isNotNull
Checks if an object or reference is not null. This method also checks if an object of typeOptionalis empty (this means that the reference is null).- Parameters:
obj- the object to inspect- Returns:
trueif reference is notnullorfalseotherwise- See Also:
-
notNull
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 inspectdefaultValue- default value used when reference is null- Returns:
- the original reference if not
nullor the default value otherwise - Throws:
IllegalArgumentException- error ifdefaultValueisnull
-
notNull
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 inspectaction- the action that is executed when the reference is not null- Throws:
IllegalArgumentException- error ifactionisnull
-
requireNotNull
Checks that a given argument is not null- Parameters:
obj- the object to inspectname- the parameter name- Throws:
IllegalArgumentException- error when the value passed as a parameter is a null value
-
requireNotNull
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 checkcls- target class to convertnullable- param used to accept null objects- Returns:
- return
trueif the object can be converted to the desired type orfalseotherwise
-
canCast
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 checkcls- target class to convert- Returns:
- return
trueif the object can be converted to the desired type orfalseotherwise
-
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 checkcls- target class to convert- Returns:
- return
trueif the object can be converted to the desired type orfalseotherwise
-
cast
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
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 convertcls- 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 convertcls- the class to which you want to promoteaction- the action to execute if casting is valid- Throws:
IllegalArgumentException- error ifclsoractionarenull
-
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 convertcls- 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 ifclsisnull
-
toString
Generates a text with the representation of the object. Very similar to what theObject.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 representationverbose- option used to determine if the output will be long or simple- Returns:
- object string representation
-
toString
Generates a text with the representation of the object. Very similar to what theObject.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 writeformat- the data writing formatargs- 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 writeformat- the data writing formatargs- the data format arguments- See Also:
-
print
Write information into a data stream- Parameters:
format- the data writing formatargs- the data format arguments- See Also:
-
printErr
Write information into a data stream- Parameters:
format- the data writing formatargs- the data format arguments- See Also:
-
println
Write information into a data stream (insert a line break at the end of the content)- Parameters:
format- the data writing formatargs- the data format arguments- See Also:
-
printlnErr
Write information into a data stream (insert a line break at the end of the content)- Parameters:
format- the data writing formatargs- 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) -
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 writeformat- the data writing formatargs- 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 writeformat- the data writing formatargs- the data format arguments- See Also:
-
printV
Write information into a data stream- Parameters:
format- the data writing formatargs- the data format arguments- See Also:
-
printErrV
Write information into a data stream- Parameters:
format- the data writing formatargs- the data format arguments- See Also:
-
printlnV
Write information into a data stream (insert a line break at the end of the content)- Parameters:
format- the data writing formatargs- the data format arguments- See Also:
-
printlnErrV
Write information into a data stream (insert a line break at the end of the content)- Parameters:
format- the data writing formatargs- the data format arguments- See Also:
-