Class OptionalNarrow

java.lang.Object
com.atlassian.bamboo.utils.OptionalNarrow

public class OptionalNarrow extends Object
Utility for narrowing object instances to Class types
Since:
5.10
  • Method Details

    • reinterpret

      public static <T> Optional<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> @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.
    • down

      public 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.