Class APIUtil


  • public final class APIUtil
    extends Object
    General utility class providing a collection of useful little helper methods.


    Contains various non-specific helper methods used to process common tasks like checking for (non)empty Strings or converting values into a String representation.

    • Method Detail

      • hasValue

        public static boolean hasValue​(String... strings)
        Checks if all of the given Strings are non-empty character sequences
        Parameters:
        strings - The strings to check
        Returns:
        Boolean.FALSE if at least one of the given Strings is null or contains only blanks.
      • hasNoValue

        public static boolean hasNoValue​(String... strings)
        Checks if at least one of the given strings is an empty character sequence
        Parameters:
        strings - The strings to check
        Returns:
        Boolean.TRUE if at least one of the given Strings is null or contains only blanks.
      • prettyPrint

        public static String prettyPrint​(@Nonnull
                                         com.fasterxml.jackson.databind.JsonNode obj)
                                  throws com.fasterxml.jackson.core.JsonProcessingException
        Serializes the given JSON object as String using a pretty print output with indentation to produce an easy-to-read String representation of the JSON object.
        Parameters:
        obj - The JSON object to be printed in a pretty fashion
        Returns:
        Easy-to-read String representation of the given JSON object
        Throws:
        com.fasterxml.jackson.core.JsonProcessingException - If an error occurred while processing the JSON object
      • toString

        public static <T> String toString​(Supplier<T> valueSupplier)
        Converts the value returned by the given valueSupplier into a new String. The output depends on the actual type argument <T> of the given supplier. If the supplied value is unconvertible an empty String will be returned instead.
        Type Parameters:
        T - The type of results supplied by the given supplier
        Parameters:
        valueSupplier - The supplier whose Supplier.get() output should be converted into a String
        Returns:
        Supplier output value converted to a String representation or an empty String
      • toString

        public static <T> String toString​(Supplier<T> valueSupplier,
                                          String nullDefault)
        Converts the value returned by the given valueSupplier into a new String. The output depends on the actual type argument <T> of the given supplier. If the supplied value is unconvertible the value of nullDefault will be returned instead.
        Type Parameters:
        T - The type of results supplied by the given supplier
        Parameters:
        valueSupplier - The supplier whose Supplier.get() output should be converted into a String
        nullDefault - The fallback default value to be returned by this method if the supplied value could not be converted
        Returns:
        Supplier output value converted to a String representation or nullDefault