Package com.atlassian.bamboo.utils
Class OptionalNarrow
- java.lang.Object
-
- com.atlassian.bamboo.utils.OptionalNarrow
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T,R extends T>
Function<T,Stream<R>>down(Class<R> aClass)
Converts an object to a stream of object if object can be cast to aClass or an empty stream otherwise.static <X,T extends X>
@NotNull Function<X,Optional<T>>downTo(@NotNull Class<T> aClass)
static <X,T extends X>
Optional<T>downTo(X o, @NotNull Class<T> aClass)
Should be used for casting down the hierarchy of classes.static <R> @NotNull Function<Object,Optional<R>>
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 Detail
-
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
@NotNull public static <X,T extends X> @NotNull Function<X,Optional<T>> downTo(@NotNull @NotNull Class<T> aClass)
-
downTo
public static <X,T extends X> Optional<T> downTo(@Nullable X o, @NotNull @NotNull Class<T> aClass)
Should be used for casting down the hierarchy of classes.
-
-