Package com.atlassian.bamboo.utils
Class OptionalNarrow
java.lang.Object
com.atlassian.bamboo.utils.OptionalNarrow
Utility for narrowing object instances to
Class
types- Since:
- 5.10
-
Method Summary
Modifier and TypeMethodDescriptionConverts an object to a stream of object if object can be cast to aClass or an empty stream otherwise.static <X,
T extends X>
Optional<T>Should be used for casting down the hierarchy of classes.reinterpret
(@NotNull Class<R> aClass) Returns a Function that narrows supplied arguments.static <T> Optional<T>
reinterpret
(@Nullable Object o, @NotNull Class<T> aClass)
-
Method Details
-
reinterpret
public static <T> Optional<T> reinterpret(@Nullable @Nullable Object o, @NotNull @NotNull Class<T> aClass) Narrows the givenObject
to the type of theClass
. UsingdownTo(Object, Class)
is always preferred over using this method. If object cannot be narrowed to the given type this method returns null This is a non-throwing form ofClass.cast(Object)
- Type Parameters:
T
- the type to be narrowed to- Parameters:
o
- the object to be narrowed. This object can be a null referenceaClass
- the class to narrow to- Returns:
- narrowed object
-
reinterpret
@NotNull public static <R> @NotNull Function<Object,Optional<R>> reinterpret(@NotNull @NotNull Class<R> aClass) Returns a Function that narrows supplied arguments. -
downTo
-
downTo
Should be used for casting down the hierarchy of classes. -
down
Converts an object to a stream of object if object can be cast to aClass or an empty stream otherwise.
-