Class IpsStringUtils

java.lang.Object
org.faktorips.runtime.internal.IpsStringUtils

public final class IpsStringUtils extends Object
A collection of utility methods for Strings. We don't use a class library like apache-commons here to minimize the dependencies for the generated code.
  • Field Details

  • Method Details

    • isEmpty

      public static boolean isEmpty(String s)
      Returns true if s is either null or the empty string, otherwise false.
    • isNotEmpty

      public static boolean isNotEmpty(String s)
      Returns true if s is neither null nor the empty string, otherwise false.
    • isBlank

      public static boolean isBlank(String s)
      Returns true if s is either null, the empty string or a string that only contains whitespace, otherwise false.
    • isNotBlank

      public static boolean isNotBlank(String s)
      Returns true if s is neither null, the empty string nor a string that only contains whitespace, otherwise false.
    • trimEquals

      public static boolean trimEquals(String s1, String s2)
      Trims the parameters, if the are not null and checks for equality using Objects.equals(Object, Object).
      Parameters:
      s1 - a string
      s2 - another string to be compared with a for equality
      Returns:
      true if the arguments are equal to each other and false otherwise
    • equalsNullAsEmpty

      public static boolean equalsNullAsEmpty(String s1, String s2)
      Compares two strings, treating null as EMPTY.
      Parameters:
      s1 - a string
      s2 - another string
      Returns:
      whether both strings are equal
    • join

      public static String join(Collection<?> collection, String separator)
      Joins the elements of the provided Collection into a single String containing the provided elements with the given separator. No delimiter is added before or after the list.
      Parameters:
      collection - the Collection of values to join together, may be null
      separator - the separator to use, null treated as ""
      Returns:
      the joined String, empty if the collection is null
    • join

      public static String join(Iterable<?> iterable, String separator)
      Joins the elements of the provided Iterable into a single String containing the provided elements with the given separator. No delimiter is added before or after the list.
      Parameters:
      iterable - the Collection of values to join together, may be null
      separator - the separator to use, null treated as ""
      Returns:
      the joined String, empty if the collection is null
    • join

      public static String join(Iterable<?> iterable)
      Joins the elements of the provided Iterable into a single String containing the provided elements with the default separator ", ". No delimiter is added before or after the list.
      Parameters:
      iterable - the Collection of values to join together, may be null
      Returns:
      the joined String, empty if the collection is null
    • join

      public static String join(Object[] objectArray)
      Joins the elements of the provided array into a single String containing the provided elements with the default separator ", ". No delimiter is added before or after the list.
      Parameters:
      objectArray - the array of values to join together, may be null
      Returns:
      the joined String, empty if the collection is null
    • join

      public static String join(Object[] objectArray, String separator)
      Joins the elements of the provided array into a single String containing the provided elements with the given separator. No delimiter is added before or after the list.
      Parameters:
      objectArray - the array of values to join together, may be null
      separator - the separator to use, null treated as ""
      Returns:
      the joined String, empty if the collection is null
    • join

      public static <T> String join(Iterable<T> iterable, Function<? super T,String> toString)
      Joins the elements of the provided Iterable into a single String containing the provided elements, converted to String with the given toString Function, with the default separator ", ". No delimiter is added before or after the list.
      Parameters:
      iterable - the Collection of values to join together, may be null
      toString - the Function to convert an element from the Iterable to a String
      Returns:
      the joined String, null if the collection is null
    • join

      public static <T> String join(Iterable<T> iterable, Function<? super T,String> toString, String separator)
      Joins the elements of the provided Iterable into a single String containing the provided elements, converted to String with the given toString Function, with the given separator. No delimiter is added before or after the list.
      Parameters:
      iterable - the Collection of values to join together, may be null
      separator - the separator to use, null treated as ""
      toString - the Function to convert an element from the Iterable to a String
      Returns:
      the joined String, null if the collection is null
    • toLowerFirstChar

      public static String toLowerFirstChar(String string)
    • toUpperFirstChar

      public static String toUpperFirstChar(String string)
      Since:
      24.7
    • replaceEach

      public static String replaceEach(String text, String[] searchList, String[] replacementList)

      Replaces all occurrences of Strings within another String.

      A null reference passed to this method is a no-op, or if any "search string" or "string to replace" is null, that replace will be ignored.

        IpsStringUtils.replaceEach(null, *, *)        = null
        IpsStringUtils.replaceEach("", *, *)          = ""
        IpsStringUtils.replaceEach("aba", null, null) = "aba"
        IpsStringUtils.replaceEach("aba", new String[0], null) = "aba"
        IpsStringUtils.replaceEach("aba", null, new String[0]) = "aba"
        IpsStringUtils.replaceEach("aba", new String[]{"a"}, null)  = "aba"
        IpsStringUtils.replaceEach("aba", new String[]{"a"}, new String[]{""})  = "b"
        IpsStringUtils.replaceEach("aba", new String[]{null}, new String[]{"a"})  = "aba"
        IpsStringUtils.replaceEach("abcde", new String[]{"ab", "d"}, new String[]{"w", "t"})  = "wcte"
        (example of how it does not repeat)
        IpsStringUtils.replaceEach("abcde", new String[]{"ab", "d"}, new String[]{"d", "t"})  = "dcte"
       
      Parameters:
      text - text to search and replace in, no-op if null
      searchList - the Strings to search for, no-op if null
      replacementList - the Strings to replace them with, no-op if null
      Returns:
      the text with any replacements processed, null if null String input
      Throws:
      IllegalArgumentException - if the lengths of the arrays are not the same (null is ok, and/or size 0)