Class Narrow

    • Method Detail

      • reinterpret

        @Nullable
        public static <T> T reinterpret​(@Nullable
                                        @Nullable Object o,
                                        @NotNull
                                        @NotNull Class<T> aClass)
        Narrows the given 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)
        Type Parameters:
        T - the type to be narrowed to
        Parameters:
        o - the object to be narrowed. This object can be a null reference
        aClass - the class to narrow to
        Returns:
        narrowed object
      • reinterpret

        @NotNull
        public static <R> Function<Object,​R> reinterpret​(@NotNull
                                                               @NotNull Class<R> aClass)
        Returns a Function that narrows supplied arguments.
      • to

        @Nullable
        public static <T> T to​(@Nullable
                               @Nullable Object o,
                               @NotNull
                               @NotNull Class<T> aClass)
        Narrows the given 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)
        Type Parameters:
        T - the type to be narrowed to
        Parameters:
        o - the object to be narrowed. This object can be a null reference
        aClass - the class to narrow to
        Returns:
        narrowed object
      • downTo

        @Nullable
        public static <X,​T extends X> T downTo​(@Nullable
                                                     X o,
                                                     @NotNull
                                                     @NotNull Class<T> aClass)
        Should be used for casting down the hierarchy of classes. See to(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 filter
        aClass - 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 that iterableTo(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 filter
        aClass - 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 filter
        aClass - 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 that streamTo(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 filter
        aClass - class used to narrow elements of iterable
        Returns:
        filtered iterable with non-null elements narrowed to aClass