Package tools.common

Class ObjectUtils

java.lang.Object
tools.common.ObjectUtils

public abstract class ObjectUtils extends Object
Static methods
Author:
Pavel Ponec
  • 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

      @NotNull public static @NotNull PrintWriter toPrintWriter(@NotNull @NotNull Appendable appendable)
      Convert appendable to object type of PrintWriter