@ParameterizedTest @ArgumentsSource(TestCaseArgumentsProvider.class) @TestCase({"null", "java.lang.String", "empty"}) @TestCase({"null", "java.lang.Integer", "empty"}) @TestCase({"null", "java.lang.Object", "empty"}) @TestCase({"abc", "java.lang.String", "abc"}) @TestCase({"abc", "java.lang.Object", "abc"}) @TestCase({"abc", "java.lang.Integer", "empty"}) void asTypeTokenWithValue(String input, Class<? extends String> target, Optional<String> expected) { Optional<?> result = OptionalUtil.as(TypeToken.of(target), input); assertThat(result, is(expected)); }
public static <T, U> Optional<U> as(Class<U> targetClass, Optional<T> source) { return source .filter(v -> targetClass.isAssignableFrom(v.getClass())) .map(targetClass::cast); }
OptionalUtil extends UtilityClass { public static <T, U> Optional<U> as(Class<U> targetClass, Optional<T> source) { return source .filter(v -> targetClass.isAssignableFrom(v.getClass())) .map(targetClass::cast); } }
OptionalUtil extends UtilityClass { public static <T, U> Optional<U> as(Class<U> targetClass, Optional<T> source) { return source .filter(v -> targetClass.isAssignableFrom(v.getClass())) .map(targetClass::cast); }  }
OptionalUtil extends UtilityClass { public static <T, U> Optional<U> as(Class<U> targetClass, Optional<T> source) { return source .filter(v -> targetClass.isAssignableFrom(v.getClass())) .map(targetClass::cast); }  static Optional<T> ofBlankable(T s); static Optional<T> ofOnly(Iterable<T> iterable); static OptionalWrapper<T> with(Optional<T> optional); static Optional<T> or(Optional<T> optional, Optional<T> other); static Optional<T> orGet(Optional<T> optional, Supplier<? extends Optional<? extends T>> supplier); static Optional<U> as(Class<U> targetClass, Optional<T> source); @SuppressWarnings("unchecked") static Optional<U> as(TypeToken<U> targetType, Optional<T> source); static Optional<U> as(Class<U> targetClass, T source); @SuppressWarnings("unchecked") static Optional<U> as(TypeToken<U> targetType, T source); }
OptionalUtil extends UtilityClass { public static <T, U> Optional<U> as(Class<U> targetClass, Optional<T> source) { return source .filter(v -> targetClass.isAssignableFrom(v.getClass())) .map(targetClass::cast); }  static Optional<T> ofBlankable(T s); static Optional<T> ofOnly(Iterable<T> iterable); static OptionalWrapper<T> with(Optional<T> optional); static Optional<T> or(Optional<T> optional, Optional<T> other); static Optional<T> orGet(Optional<T> optional, Supplier<? extends Optional<? extends T>> supplier); static Optional<U> as(Class<U> targetClass, Optional<T> source); @SuppressWarnings("unchecked") static Optional<U> as(TypeToken<U> targetType, Optional<T> source); static Optional<U> as(Class<U> targetClass, T source); @SuppressWarnings("unchecked") static Optional<U> as(TypeToken<U> targetType, T source);  }