Class Lang


  • public final class Lang
    extends Object
    • Method Detail

      • isEmpty

        public static boolean isEmpty​(String string)
        Returns true if the given string is null or is empty.
        Parameters:
        string - The string to be checked on emptiness.
        Returns:
        true if the given string is null or is empty.
      • isEmpty

        public static boolean isEmpty​(Object[] array)
        Returns true if the given array is null or is empty.
        Parameters:
        array - The array to be checked on emptiness.
        Returns:
        true if the given array is null or is empty.
      • isEmpty

        public static boolean isEmpty​(Collection<?> collection)
        Returns true if the given collection is null or is empty.
        Parameters:
        collection - The collection to be checked on emptiness.
        Returns:
        true if the given collection is null or is empty.
      • isEmpty

        public static boolean isEmpty​(Map<?,​?> map)
        Returns true if the given map is null or is empty.
        Parameters:
        map - The map to be checked on emptiness.
        Returns:
        true if the given map is null or is empty.
      • isEmpty

        public static boolean isEmpty​(Object value)
        Returns true if the given value is null or is empty. Types of String, Collection, Map, Optional and Array are recognized. If none is recognized, then examine the emptiness of the toString() representation instead.
        Parameters:
        value - The value to be checked on emptiness.
        Returns:
        true if the given value is null or is empty.
      • isAllEmpty

        public static boolean isAllEmpty​(Object... values)
        Returns true if all values are empty, false if at least one value is not empty.
        Parameters:
        values - the values to be checked on emptiness
        Returns:
        True if all values are empty, false otherwise
      • isAnyEmpty

        public static boolean isAnyEmpty​(Object... values)
        Returns true if at least one value is empty.
        Parameters:
        values - the values to be checked on emptiness
        Returns:
        true if any value is empty and false if no values are empty
      • isNotBlank

        public static boolean isNotBlank​(String string)
      • requireNotEmpty

        public static <T,​E extends Exception> T requireNotEmpty​(T value,
                                                                      Supplier<E> exceptionSupplier)
                                                               throws E extends Exception
        Throws:
        E extends Exception
      • ifEmptyGet

        public static <T> T ifEmptyGet​(T value,
                                       Supplier<T> defaultSupplier)
      • setIfNotEmpty

        public static <T> void setIfNotEmpty​(T value,
                                             Consumer<? super T> setter)
        Call the given setter with the given value if isEmpty(Object) returns false for the given value.
        Type Parameters:
        T - the generic type of the value
        Parameters:
        value - the value to set
        setter - a consumer that calls the setter with the value
      • coalesce

        @SafeVarargs
        public static <T> T coalesce​(T... objects)
        Returns the first non-null object of the argument list, or null if there is no such element.
        Type Parameters:
        T - The generic object type.
        Parameters:
        objects - The argument list of objects to be tested for non-null.
        Returns:
        The first non-null object of the argument list, or null if there is no such element.
      • isOneOf

        @SafeVarargs
        public static <T> boolean isOneOf​(T object,
                                          T... objects)
        Returns true if the given object equals one of the given objects.
        Type Parameters:
        T - The generic object type.
        Parameters:
        object - The object to be checked if it equals one of the given objects.
        objects - The argument list of objects to be tested for equality.
        Returns:
        true if the given object equals one of the given objects.
      • startsWithOneOf

        public static boolean startsWithOneOf​(String string,
                                              String... prefixes)
        Returns true if the given string starts with one of the given prefixes.
        Parameters:
        string - The string to be checked if it starts with one of the given prefixes.
        prefixes - The argument list of prefixes to be checked.
        Returns:
        true if the given string starts with one of the given prefixes.
      • endsWithOneOf

        public static boolean endsWithOneOf​(String string,
                                            String... suffixes)
        Returns true if the given string ends with one of the given suffixes.
        Parameters:
        string - The string to be checked if it ends with one of the given suffixes.
        suffixes - The argument list of suffixes to be checked.
        Returns:
        true if the given string ends with one of the given suffixes.
      • replaceLast

        public static String replaceLast​(String string,
                                         String regex,
                                         String replacement)
        Replaces the last substring of given string that matches the given regular expression with the given replacement. Author: https://stackoverflow.com/a/2282998
        Parameters:
        string - The string to be replaced.
        regex - The regular expression to which given string is to be matched.
        replacement - The string to be substituted for the last match.
        Returns:
        The resulting string.
      • containsIsoControlCharacters

        public static boolean containsIsoControlCharacters​(String string)
        Returns true if the given string contains any ISO control characters.
        Parameters:
        string - the string to check for control characters
        Returns:
        true if the string contains any ISO control characters and false otherwise
      • capitalize

        public static String capitalize​(String string)
        Converts the first character of given string to upper case.
        Parameters:
        string - String to be capitalized.
        Returns:
        The given string capitalized.
      • toTitleCase

        public static String toTitleCase​(String string)
        Converts given string to title case.
        Parameters:
        string - String to be converted to title case.
        Returns:
        The given string converted to title case.
      • toUrlSafe

        public static String toUrlSafe​(String string)
        Converts given string to URL safe format, also called a "slug".
        Parameters:
        string - String to be converted to URL safe format.
        Returns:
        The given string converted to URL safe format.
      • escapeAsProperty

        public static String escapeAsProperty​(String string)
                                       throws IOException
        Escape given string as valid Properties entry value.
        Parameters:
        string - String to be escaped as valid Properties entry value.
        Returns:
        The given string escaped as valid Properties entry value.
        Throws:
        IOException - When appending a character fails.