Class StringUtil

java.lang.Object
org.apache.ofbiz.base.util.StringUtil

public final class StringUtil extends Object
Misc String Utility Functions
  • Field Details

    • INSTANCE

      public static final StringUtil INSTANCE
  • Method Details

    • internString

      public static String internString(String value)
    • replaceString

      public static String replaceString(String mainString, String oldString, String newString)
      Replaces all occurrences of oldString in mainString with newString
      Parameters:
      mainString - The original string
      oldString - The string to replace
      newString - The string to insert in place of the old
      Returns:
      mainString with all occurrences of oldString replaced by newString
    • join

      public static String join(Collection<?> col, CharSequence delim)
      Creates a single string from a Collection of strings separated by a delimiter.
      Parameters:
      col - a collection of strings to join
      delim - the delimiter character(s) to use. (null value will join with no delimiter)
      Returns:
      a String of all values in the collection separated by the delimiter
    • split

      public static List<String> split(String str, String delim)
      Splits a String on a delimiter into a List of Strings.
      Parameters:
      str - the String to split
      delim - the delimiter character(s) to join on (null will split on whitespace)
      Returns:
      a list of Strings
    • strToMap

      public static Map<String,String> strToMap(String str, String delim, boolean trim)
      Creates a Map from an encoded name/value pair string
      Parameters:
      str - The string to decode and format
      delim - the delimiter character(s) to join on (null will split on whitespace)
      trim - Trim whitespace off fields
      Returns:
      a Map of name/value pairs
    • strToMap

      public static Map<String,String> strToMap(String str, String delim, boolean trim, String pairsSeparator)
      Creates a Map from a name/value pair string
      Parameters:
      str - The string to decode and format
      delim - the delimiter character(s) to join on (null will split on whitespace)
      trim - Trim whitespace off fields
      pairsSeparator - in case you use not encoded name/value pairs strings and want to replace "=" to avoid clashes with parameters values in a not encoded URL, default to "="
      Returns:
      a Map of name/value pairs
    • strToMap

      public static Map<String,String> strToMap(String str, boolean trim)
      Creates a Map from an encoded name/value pair string
      Parameters:
      str - The string to decode and format
      trim - Trim whitespace off fields
      Returns:
      a Map of name/value pairs
    • strToMap

      public static Map<String,String> strToMap(String str)
      Creates a Map from an encoded name/value pair string
      Parameters:
      str - The string to decode and format
      Returns:
      a Map of name/value pairs
    • toList

      public static List<String> toList(String s)
      Reads a String version of a List (should contain only strings) and creates a new List
      Parameters:
      s - String value of a Map ({n1=v1, n2=v2})
      Returns:
      new List
    • toSet

      public static Set<String> toSet(String s)
      Reads a String version of a Set (should contain only strings) and creates a new Set
      Parameters:
      s - String value of a Map ({n1=v1, n2=v2})
      Returns:
      new List
    • createMap

      public static <K, V> Map<K,V> createMap(List<K> keys, List<V> values)
      Create a Map from a List of keys and a List of values
      Parameters:
      keys - List of keys
      values - List of values
      Returns:
      Map of combined lists
      Throws:
      IllegalArgumentException - When either List is null or the sizes do not equal
    • cleanUpPathPrefix

      public static String cleanUpPathPrefix(String prefix)
      Make sure the string starts with a forward slash but does not end with one; converts back-slashes to forward-slashes; if in String is null or empty, returns zero length string.
    • removeSpaces

      public static String removeSpaces(String str)
      Removes all spaces from a string
    • toHexString

      public static String toHexString(byte[] bytes)
    • cleanHexString

      public static String cleanHexString(String str)
    • fromHexString

      public static byte[] fromHexString(String str)
    • encodeInt

      public static char[] encodeInt(int i, int j, char[] digestChars)
    • removeNonNumeric

      public static String removeNonNumeric(String str)
      Removes all non-numbers from str
    • removeRegex

      public static String removeRegex(String str, String regex)
      Parameters:
      str -
      regex - Removes all matches of regex from a str
    • addToNumberString

      public static String addToNumberString(String numberString, long addAmount)
      Add the number to the string, keeping (padding to min of original length)
      Returns:
      the new value
    • padNumberString

      public static String padNumberString(String numberString, int targetMinLength)
    • convertOperatorSubstitutions

      public static String convertOperatorSubstitutions(String expression)
      Converts operator substitutions (@and, @or, etc) back to their original form.

      OFBiz script syntax provides special forms of common operators to make it easier to embed logical expressions in XML

      OFBiz XML operators
      OFBiz operatorSubstitution
      @and&&
      @or||
      @gt>
      @gteq>=
      @lt<
      @lteq<=
      Parameters:
      expression - The String to convert
      Returns:
      The converted String
    • wrapString

      public static StringUtil.StringWrapper wrapString(String theString)
    • makeStringWrapper

      public static StringUtil.StringWrapper makeStringWrapper(String theString)