Class StringUtils

java.lang.Object
valorless.valorlessutils.json.StringUtils

public final class StringUtils extends Object
Utility functions related to Strings.
  • Method Details

    • isEmpty

      public static boolean isEmpty(@Nullable String string)
    • getNotEmpty

      public static @Nullable String getNotEmpty(@Nullable String string)
      Makes sure that the given String is not empty.
      Parameters:
      string - the String
      Returns:
      the String itself, or null if it is empty
    • getOrEmpty

      public static String getOrEmpty(@Nullable String string)
      Makes sure that the given String is not null.
      Parameters:
      string - the String
      Returns:
      the String itself, or an empty String if it is null
    • toStringOrEmpty

      public static String toStringOrEmpty(@Nullable Object object)
      Converts the given Object to a String via its Object.toString() method.

      If the object is null, or if its Object.toString() method returns null, this returns an empty String.

      Parameters:
      object - the object
      Returns:
      the String, not null
    • toStringOrNull

      public static @Nullable String toStringOrNull(@Nullable Object object)
      Converts the given Object to a String via its Object.toString() method.

      Returns null if the object is null, or if its Object.toString() method returns null.

      Parameters:
      object - the object
      Returns:
      the String, possibly null
    • contains

      public static boolean contains(@Nullable String string, int character)
      Checks if the given String contains the specified character.

      This is a shortcut for invoking String.indexOf(int) and checking if the return value does not equal -1.

      Parameters:
      string - the String
      character - the character
      Returns:
      true if the String contains the given character
    • normalizeKeepCase

      public static String normalizeKeepCase(String identifier)
      Normalizes the given identifier.

      This trims leading and trailing whitespace and converts all remaining whitespace and underscores to dashes ('-').

      Parameters:
      identifier - the identifier, not null
      Returns:
      the normalized identifier
    • normalize

      public static String normalize(String identifier)
      Normalizes the given identifier.

      This trims leading and trailing whitespace, converts all remaining whitespace and underscores to dashes ('-') and converts all characters to lower case.

      Parameters:
      identifier - the identifier, not null
      Returns:
      the normalized identifier
    • normalize

      public static List<@NonNull String> normalize(List<? extends @NonNull String> identifiers)
    • containsWhitespace

      public static boolean containsWhitespace(@Nullable String string)
      Checks if the given String contains whitespace characters.
      Parameters:
      string - the String
      Returns:
      true if the given String is not empty and contains at least one whitespace character
    • removeWhitespace

      public static String removeWhitespace(String source)
      Removes all whitespace characters inside the given source String.
      Parameters:
      source - the source String, not null
      Returns:
      the String without any whitespace characters
    • replaceWhitespace

      public static String replaceWhitespace(String source, String replacement)
      Replaces all whitespace characters inside the given source String.
      Parameters:
      source - the source String, not null
      replacement - the replacement String, not null
      Returns:
      the String with any whitespace characters replaced
    • capitalizeAll

      public static String capitalizeAll(String source)
    • splitLines

      public static @NonNull String[] splitLines(String source)
    • splitLines

      public static @NonNull String[] splitLines(String source, boolean splitLiteralNewlines)
    • stripTrailingNewlines

      public static String stripTrailingNewlines(String string)
    • containsNewline

      public static boolean containsNewline(@Nullable String string)
    • escapeNewlinesAndBackslash

      public static String escapeNewlinesAndBackslash(String string)
    • replaceFirst

      public static String replaceFirst(String source, String target, CharSequence replacement)
    • addArgumentsToMap

      public static <T> void addArgumentsToMap(Map<@NonNull String,@NonNull Object> argumentsMap, @NonNull Object... argumentPairs)
    • replaceArguments

      public static String replaceArguments(String source, @NonNull Object... argumentPairs)
    • replaceArguments

      public static String replaceArguments(String source, Map<? extends @NonNull String,@NonNull ?> arguments)
    • replaceArguments

      public static String replaceArguments(String source, MessageArguments arguments)
    • replaceArguments

      public static List<@NonNull String> replaceArguments(Collection<? extends @NonNull String> messages, @NonNull Object... argumentPairs)
    • replaceArguments

      public static List<@NonNull String> replaceArguments(Collection<? extends @NonNull String> sources, Map<? extends @NonNull String,@NonNull ?> arguments)
    • replaceArguments

      public static List<@NonNull String> replaceArguments(Collection<? extends @NonNull String> sources, MessageArguments arguments)