Package tools.common
Class ObjectUtils
java.lang.Object
tools.common.ObjectUtils
Static methods
- Author:
- Pavel Ponec
-
Method Summary
Modifier and TypeMethodDescriptionstatic final <V> booleancheck(@Nullable Object value, @NotNull Class<V> requiredClass, @NotNull Function<V, Boolean> function) Check the result of a function in case the value have got the same class as the required one.static final <V,R> Optional<R> Run a function in case the value is an instance of the required class.static @NotNull PrintWritertoPrintWriter(@NotNull Appendable appendable) Convert appendable to object type of PrintWriter
-
Method Details
-
iof
public static final <V,R> Optional<R> iof(@Nullable @Nullable Object value, @NotNull @NotNull Class<V> requiredClass, @NotNull @NotNull Function<V, R> function) Run a function in case the value is an instance of the required class.
Usage:Object input = "ABC"; int result = ObjectUtils.iof(input, String.class, v -> v.length()).orElse(0); assertEquals(3, result);
-
check
public static final <V> boolean check(@Nullable @Nullable Object value, @NotNull @NotNull Class<V> requiredClass, @NotNull @NotNull Function<V, Boolean> function) Check the result of a function in case the value have got the same class as the required one.
Usage:Object input = "ABC"; int result = ObjectUtils.check(input, String.class, v -> v.length()).orElse(0); assertEquals(3, result);
-
toPrintWriter
Convert appendable to object type of PrintWriter
-