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 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- 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
-