- java.lang.Object
-
- com.github.ushiosan23.jvm.base.Obj
-
public final class Obj extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Tapply(T obj, IApply.WithResult<T,T> action)Apply configuration to the object and return it as a resultstatic <T> TnotNull(T obj, T defValue)Get not null valuestatic @NotNull StringtoBaseString(@Nullable Object data)Get object string representationstatic @NotNull StringtoInfoString(@Nullable Object data)Get object info representationstatic <T> TtryCast(@NotNull Object obj, @NotNull Class<T> tClass)It tries to recast the object towards the assigned destination, but does not generate an error.static <T> voidtryCast(@NotNull Object obj, @NotNull Class<T> tClass, IApply.EmptyResult<T> action)It tries to recast the object towards the assigned destination, but does not generate an error.
-
-
-
Method Detail
-
toBaseString
@NotNull public static @NotNull String toBaseString(@Nullable @Nullable Object data)
Get object string representation- Parameters:
data- The data to convert- Returns:
- Returns an object string representation
-
toInfoString
@NotNull public static @NotNull String toInfoString(@Nullable @Nullable Object data)
Get object info representation- Parameters:
data- The data to convert- Returns:
- Returns an object info string representation
-
notNull
public static <T> T notNull(@Nullable T obj, T defValue)
Get not null value- Type Parameters:
T- Generic object type- Parameters:
obj- Object to check if it's nulldefValue- Default value ifobjis null- Returns:
- Return
objif it's not null ordefValueotherwise
-
apply
public static <T> T apply(T obj, @NotNull IApply.WithResult<T,T> action)Apply configuration to the object and return it as a result- Type Parameters:
T- Generic object type- Parameters:
obj- Object to which the action appliesaction- Apply action to execute- Returns:
- Returns the same object is returned but with the changes made
-
tryCast
public static <T> void tryCast(@NotNull @NotNull Object obj, @NotNull @NotNull Class<T> tClass, @NotNull IApply.EmptyResult<T> action)
It 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.Example:
Object unknownType = "Hello, World!"; Obj.tryCast( unknownType, // Object to be evaluated String.class, // Destination class object -> System.out.println(object) // Action that is only executed if the recast is valid );- Type Parameters:
T- Generic destination type- Parameters:
obj- Object to analyzetClass- Destination classaction- action that is executed when the recast is valid.
-
tryCast
@Nullable public static <T> T tryCast(@NotNull @NotNull Object obj, @NotNull @NotNull Class<T> tClass)
It tries to recast the object towards the assigned destination, but does not generate an error.- Type Parameters:
T- Generic destination type- Parameters:
obj- Object to analyzetClass- Destination class- Returns:
- Returns a recast object or
nullif the cast fails
-
-