- java.lang.Object
-
- com.rezzedup.util.constants.types.Cast
-
public class Cast extends Object
Utilities for casting objects.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCast.UnsafeUnsafe utilities for casting objects.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Function<@NullOr Object,Optional<T>>as(Class<T> type)Creates a function that attempts to cast objects into the specified type.static <T> Optional<T>as(Class<T> type, @NullOr Object object)Attempts to cast an object into the specified type.static <T> Optional<T>optional(Class<T> type, Optional<?> optional)Attempts to cast anOptional's contents into the specified type.static Cast.Unsafeunsafe()Gets the unsafe casting utilities instance.
-
-
-
Method Detail
-
as
public static <T> Optional<T> as(Class<T> type, @NullOr Object object)
Attempts to cast an object into the specified type.- Type Parameters:
T- the type- Parameters:
type- type to cast intoobject- object to cast- Returns:
- the successfully cast object, otherwise empty
-
as
public static <T> Function<@NullOr Object,Optional<T>> as(Class<T> type)
Creates a function that attempts to cast objects into the specified type.- Type Parameters:
T- the type- Parameters:
type- type to cast into- Returns:
- a function that casts objects into the specified type
- See Also:
as(Class, Object)
-
optional
public static <T> Optional<T> optional(Class<T> type, Optional<?> optional)
Attempts to cast anOptional's contents into the specified type.- Type Parameters:
T- the type- Parameters:
type- type to cast intooptional- optional to cast- Returns:
- a present optional if its contents were successfully cast, otherwise empty
-
unsafe
public static Cast.Unsafe unsafe()
Gets the unsafe casting utilities instance.Warning!
The unsafe instance cannot guarantee accurate casts.
- Returns:
- the unsafe casting utilities instance
-
-