public class Narrow extends Object
Class
types
See to(Object, Class)
Modifier and Type | Method and Description |
---|---|
static <X,T extends X> |
downTo(X o,
Class<T> aClass)
Should be used for casting down the hierarchy of classes.
|
static <X,T extends X> |
iterableDownTo(Iterable<X> iterable,
Class<T> aClass)
Filters given Iterable returning only these objects which could be narrowed to given type.
|
static <T> Iterable<T> |
iterableTo(Iterable<?> iterable,
Class<T> aClass)
Filters given Iterable returning only these objects which could be narrowed to given type
|
static <R> Function<Object,R> |
reinterpret(Class<R> aClass)
Returns a Function that narrows supplied arguments.
|
static <T> T |
reinterpret(Object o,
Class<T> aClass)
|
static <X,T extends X> |
streamDownTo(Stream<X> stream,
Class<T> aClass)
Filters given Stream returning only these objects which could be narrowed to given type.
|
static <X,T> Stream<T> |
streamTo(Stream<X> stream,
Class<T> aClass)
Filters given Stream returning only these objects which could be narrowed to given type.
|
static <T> T |
to(Object o,
Class<T> aClass)
|
@Nullable public static <T> T reinterpret(@Nullable Object o, @NotNull Class<T> aClass)
Object
to the type of the Class
. Using downTo(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 of Class.cast(Object)
T
- the type to be narrowed too
- the object to be narrowed. This object can be a null referenceaClass
- the class to narrow to@NotNull public static <R> Function<Object,R> reinterpret(@NotNull Class<R> aClass)
@Nullable public static <T> T to(@Nullable Object o, @NotNull Class<T> aClass)
Object
to the type of the Class
. Using downTo(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 of Class.cast(Object)
T
- the type to be narrowed too
- the object to be narrowed. This object can be a null referenceaClass
- the class to narrow to@Nullable public static <X,T extends X> T downTo(@Nullable X o, @NotNull Class<T> aClass)
to(Object, Class)
.public static <T> Iterable<T> iterableTo(@NotNull Iterable<?> iterable, @NotNull Class<T> aClass)
T
- iterable
- input iterable containing elements to filteraClass
- class used to narrow elements of iterablepublic static <X,T extends X> Iterable<T> iterableDownTo(@NotNull Iterable<X> iterable, @NotNull Class<T> aClass)
iterableTo(Iterable, Class)
and should be used when casting
down the class structure. (e.g. List<ImmutablePlan> -> Iterable<ImmutableChain>)iterable
- input iterable containing elements to filteraClass
- class used to narrow elements of iterablepublic static <X,T> Stream<T> streamTo(@NotNull Stream<X> stream, @NotNull Class<T> aClass)
stream
- input iterable containing elements to filteraClass
- class used to narrow elements of iterablepublic static <X,T extends X> Stream<T> streamDownTo(@NotNull Stream<X> stream, @NotNull Class<T> aClass)
streamTo(Stream, Class)
and should be used when casting
down the class structure. (e.g. List<ImmutablePlan> -> Iterable<ImmutableChain>)stream
- input iterable containing elements to filteraClass
- class used to narrow elements of iterableCopyright © 2017 Atlassian Software Systems Pty Ltd. All rights reserved.