Package com.atlassian.bamboo.util
Class Narrow
java.lang.Object
com.atlassian.bamboo.util.Narrow
Utility for narrowing object instances to
Class
types
See to(Object, Class)
- Since:
- 2.7
-
Method Summary
Modifier and TypeMethodDescriptionstatic <X,
T extends X>
TShould be used for casting down the hierarchy of classes.static <X,
T extends X>
Iterable<T>iterableDownTo
(@NotNull Iterable<X> iterable, @NotNull Class<T> aClass) Filters given Iterable returning only these objects which could be narrowed to given type.static <T> Iterable<T>
iterableTo
(@NotNull Iterable<?> iterable, @NotNull Class<T> aClass) Filters given Iterable returning only these objects which could be narrowed to given typereinterpret
(@NotNull Class<R> aClass) Returns a Function that narrows supplied arguments.static <T> T
reinterpret
(@Nullable Object o, @NotNull Class<T> aClass) static <X,
T extends X>
Stream<T>streamDownTo
(@NotNull Stream<X> stream, @NotNull Class<T> aClass) Filters given Stream returning only these objects which could be narrowed to given type.static <X,
T> Stream<T> Filters given Stream returning only these objects which could be narrowed to given type.static <T> T
-
Method Details
-
reinterpret
@Nullable public static <T> 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
Returns a Function that narrows supplied arguments. -
to
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
-
downTo
Should be used for casting down the hierarchy of classes. Seeto(Object, Class)
. -
iterableTo
public static <T> Iterable<T> iterableTo(@NotNull @NotNull Iterable<?> iterable, @NotNull @NotNull Class<T> aClass) Filters given Iterable returning only these objects which could be narrowed to given type- Type Parameters:
T
-- Parameters:
iterable
- input iterable containing elements to filteraClass
- class used to narrow elements of iterable- Returns:
- filtered iterable with non-null elements narrowed to aClass
-
iterableDownTo
public static <X,T extends X> Iterable<T> iterableDownTo(@NotNull @NotNull Iterable<X> iterable, @NotNull @NotNull Class<T> aClass) Filters given Iterable returning only these objects which could be narrowed to given type. This version is more typesafe thatiterableTo(Iterable, Class)
and should be used when casting down the class structure. (e.g. List<ImmutablePlan> -> Iterable<ImmutableChain>)- Parameters:
iterable
- input iterable containing elements to filteraClass
- class used to narrow elements of iterable- Returns:
- filtered iterable with non-null elements narrowed to aClass
-
streamTo
public static <X,T> Stream<T> streamTo(@NotNull @NotNull Stream<X> stream, @NotNull @NotNull Class<T> aClass) Filters given Stream returning only these objects which could be narrowed to given type.- Parameters:
stream
- input iterable containing elements to filteraClass
- class used to narrow elements of iterable- Returns:
- filtered iterable with non-null elements narrowed to aClass
-
streamDownTo
public static <X,T extends X> Stream<T> streamDownTo(@NotNull @NotNull Stream<X> stream, @NotNull @NotNull Class<T> aClass) Filters given Stream returning only these objects which could be narrowed to given type. This version is more typesafe thatstreamTo(Stream, Class)
and should be used when casting down the class structure. (e.g. List<ImmutablePlan> -> Iterable<ImmutableChain>)- Parameters:
stream
- input iterable containing elements to filteraClass
- class used to narrow elements of iterable- Returns:
- filtered iterable with non-null elements narrowed to aClass
-