Class StringUtil

java.lang.Object
com.sshtools.daemon.util.StringUtil

public class StringUtil extends Object
The sole instance of this class provides several convienience methods for string manipulation such as substring replacement or character repetition.
Version:
2.0
Author:
Manfred Duchrow
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final char
    Constant for the carriage return character
    static final char
    Constant for the new line character
    static final char
    Constant for the space character
    static final char
    Constant for the tabulator character
    static final String
    Constant for the String representation of the carriage return character
    static final String
    Constant for the String representation of the new line character
    static final String
    Constant for the String representation of the space character
    static final String
    Constant for the String representation of the tabulator character
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    allParts(String text, String delimiters)
    Returns an array of substrings of the given text.
    allSubstrings(String text, String separator)
    Returns the given text split up into an array of strings, at the occurrances of the separator string.
    append(String[] strings, String string)
    Returns the given string array extended by one element that hold the specified string.
    append(String[] strings, String[] appendStrings)
    Returns an array of strings that contains all strings given by the first and second string array.
    appendIfNotThere(String[] strings, String appendString)
    Returns an array of strings that contains all strings given in the first plus the specified string to append, if it is not already in the given array.
    appendIfNotThere(String[] strings, String[] appendStrings)
    Returns an array of strings that contains all strings given in the first plus all strings of the second array that are not already in the first array.
    Returns a new map object that contains all key-value pairs of the specified string.
    asMap(String str, String elementSeparator)
    Returns a new map object that contains all key-value pairs of the specified string.
    asMap(String str, String elementSeparator, String keyValueSeparator)
    Returns a new map object that contains all key-value pairs of the specified string.
    Adds all key-value pairs of the given string to a new properties object.
    asString(String[] strings)
    Returns a string that contains all given strings concatenated and separated by comma.
    asString(String[] strings, String separator)
    Returns a string that contains all given strings concatenated and separated by the specified separator.
    center(String str, int len)
    Returns the given string filled (on the right and right) up to the specified length with spaces.
    centerCh(String str, int len, char ch)
    Returns the given string filled equally left and right up to the specified length with the given character.
    protected void
    collectParts(List list, StringTokenizer tokenizer)
     
    protected void
    collectParts(List list, StringTokenizer tokenizer, String delimiter)
     
    boolean
    contains(String[] strArray, StringPattern pattern)
    Returns whether or not a string can be found in the given string array that matches the specified string pattern.
    boolean
    contains(String[] strArray, String searchStr)
    Returns whether or not the specified string can be found in the given string array.
    boolean
    contains(String[] strArray, String searchStr, boolean ignoreCase)
    Returns whether or not the specified string can be found in the given string array.
    boolean
    containsIgnoreCase(String[] strArray, String searchStr)
    Returns whether or not the specified string can be found in the given string array.
    copyFrom(String[] from, int start)
    Returns all elements of string array from in a new array from index start up to the end.
    copyFrom(String[] from, int start, int end)
    Returns all elements of string array from in a new array from index start up to index end (inclusive).
    static StringUtil
    Returns the one and only instance of this class.
    cutHead(String text, String separator)
    Returns the portion of the given string that stands after the last occurance of the specified separator.
    cutTail(String text, String separator)
    Returns the portion of the given string that comes before the last occurance of the specified separator.
    Returns the first substring that is enclosed by the specified delimiter.
    getDelimitedSubstring(String text, String startDelimiter, String endDelimiter)
    Returns the first substring that is enclosed by the specified delimiters.
    int
    indexOf(String[] strArray, StringPattern pattern)
    Returns the index of the first string in the given string array that matches the specified string pattern.
    int
    indexOf(String[] strArray, String searchStr)
    Returns the index of the specified string in the given string array.
    int
    indexOfIgnoreCase(String[] strArray, String searchStr)
    Returns the index of the specified string in the given string array.
    protected int
    indexOfString(String[] strArray, String searchStr, boolean ignoreCase)
     
    leftPad(int value, int len)
    Returns the given integer as string filled (on the left) up to the specified length with zeroes.
    leftPad(String str, int len)
    Returns the given string filled (on the left) up to the specified length with spaces.
    leftPadCh(int value, int len, char fillChar)
    Returns the given integer as string filled (on the left) up to the specified length with the given fill character.
    leftPadCh(String str, int len, char ch)
    Returns the given string filled (on the left) up to the specified length with the given character.
    protected String
    padCh(String str, int len, char ch, boolean left)
     
    parts(String text, String delimiters)
    Returns an array of substrings of the given text.
    protected String[]
    parts(String text, String delimiters, boolean all)
    Returns an array of substrings of the given text.
    prefix(String str, String separator)
    Returns the substring of the given string that comes before the first occurance of the specified separator.
    protected String
    prefix(String str, String separator, boolean returnNull)
    Returns the substring of the given string that comes before the first occurance of the specified separator.
    remove(String[] strings, String removeString)
    Removes the given string from the specified string array.
    remove(String[] strings, String[] removeStrings)
    Removes all string of the second array from the first array.
    protected String[]
    removeFromStringArray(String[] strings, String[] removeStrings)
    Removes the given strings from the array.
    removeNull(String[] strings)
    Removes all null values from the given string array.
    repeat(char ch, int count)
    Returns a string with size of count and all characters initialized with ch.
    replaceAll(String sourceStr, String oldSubStr, String newSubStr)
    Returns the given string with all found oldSubStr replaced by newSubStr.
    Returns a string that contains all characters of the given string in reverse order.
    rightPad(int value, int len)
    Returns the given integer as string filled (on the right) up to the specified length with spaces.
    rightPad(String str, int len)
    Returns the given string filled (on the right) up to the specified length with spaces.
    rightPadCh(int value, int len, char fillChar)
    Returns the given integer as string filled (on the right) up to the specified length with the given character.
    rightPadCh(String str, int len, char ch)
    Returns the given string filled (on the right) up to the specified length with the given character.
    splitNameValue(String str, String separator)
    Returns a string array with two elements where the first is the attribute name and the second is the attribute value.
    stackTrace(Throwable throwable)
    Prints the stack trace of the specified throwable to a string and returns it.
    startingFrom(String str, String separator)
    Returns the substring of the given string that comes after the first occurance of the specified separator.
    substrings(String text, String separator)
    Returns the given text split up into an array of strings, at the occurrances of the separator string.
    protected String[]
    substrings(String text, String separator, boolean all)
    Returns the given text split up into an array of strings, at the occurrances of the separator string.
    suffix(String str, String separator)
    Returns the substring of the given string that comes after the first occurance of the specified separator.
    protected String
    suffix(String str, String separator, boolean returnNull)
    Returns the substring of the given string that comes after the first occurance of the specified separator.
    toMap(String str, String elementSeparator, String keyValueSeparator, Map map)
    Returns the given map with new entries from the specified String.
    toMap(String str, String elementSeparator, Map map)
    Returns the given map object with all key-value pairs of the specified string added to it.
    toMap(String str, Map map)
    Adds all key-value pairs of the given string to the specified map.
    toProperties(String str, Properties properties)
    Adds all key-value pairs of the given string to the specified properties.
    protected String
    trimSeparator(String text, String separator)
    Cuts off all leading and trailing occurences of separator in text.
    upTo(String str, String separator)
    Returns the substring of the given string that comes before the first occurance of the specified separator.
    words(String text)
    Returns an array of substrings of the given text.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • CH_SPACE

      public static final char CH_SPACE
      Constant for the space character
      See Also:
    • CH_NEWLINE

      public static final char CH_NEWLINE
      Constant for the new line character
      See Also:
    • CH_CR

      public static final char CH_CR
      Constant for the carriage return character
      See Also:
    • CH_TAB

      public static final char CH_TAB
      Constant for the tabulator character
      See Also:
    • STR_SPACE

      public static final String STR_SPACE
      Constant for the String representation of the space character
      See Also:
    • STR_NEWLINE

      public static final String STR_NEWLINE
      Constant for the String representation of the new line character
      See Also:
    • STR_CR

      public static final String STR_CR
      Constant for the String representation of the carriage return character
      See Also:
    • STR_TAB

      public static final String STR_TAB
      Constant for the String representation of the tabulator character
      See Also:
  • Constructor Details

    • StringUtil

      public StringUtil()
  • Method Details

    • current

      public static StringUtil current()
      Returns the one and only instance of this class.
      Returns:
    • replaceAll

      public String replaceAll(String sourceStr, String oldSubStr, String newSubStr)
      Returns the given string with all found oldSubStr replaced by newSubStr.
      Example: StringUtil.current().replaceAll( "Seven of ten", "even", "ix" ) ;
      results in: "Six of ten"
      Parameters:
      sourceStr - The string that should be checked for occurrences of oldSubStr
      oldSubStr - The string that is searched for in sourceStr
      newSubStr - The new string that is placed everywhere the oldSubStr was found
      Returns:
      The original string with all found substrings replaced by new strings
    • repeat

      public String repeat(char ch, int count)
      Returns a string with size of count and all characters initialized with ch.
      Parameters:
      ch - the character to be repeated in the result string.
      count - the number of times the given character should occur in the result string.
      Returns:
      A string containing count characters ch.
    • words

      public String[] words(String text)
      Returns an array of substrings of the given text.
      The delimiters between the substrings are the whitespace characters SPACE, NEWLINE, CR and TAB.
      Parameters:
      text - The string that should be splitted into whitespace separated words
      Returns:
      An array of substrings of the given text
      See Also:
    • parts

      public String[] parts(String text, String delimiters)
      Returns an array of substrings of the given text.
      The separators between the substrings are the given delimiters. Each character in the delimiter string is treated as a separator.
      All consecutive delimiters are treated as one delimiter, that is there will be no empty strings in the result.
      Parameters:
      text - The string that should be splitted into substrings
      delimiters - All characters that should be recognized as a separator or substrings
      Returns:
      An array of substrings of the given text
      See Also:
    • allParts

      public String[] allParts(String text, String delimiters)
      Returns an array of substrings of the given text.
      The separators between the substrings are the given delimiters. Each character in the delimiter string is treated as a separator.
      For each delimiter that is followed immediately by another delimiter an empty string will be added to the result. There are no empty strings added to the result for a delimiter at the very beginning of at the very end.

      Examples:

      allParts( "/A/B//", "/" ) --> { "A", "B", "" }
      allParts( "/A,B/C;D", ",;/" ) --> { "A", "B", "C", "D" }
      allParts( "A/B,C/D", "," ) --> { "A/B", "C/D" }

      Parameters:
      text - The string that should be splitted into substrings
      delimiters - All characters that should be recognized as a separator or substrings
      Returns:
      An array of substrings of the given text
      See Also:
    • substrings

      public String[] substrings(String text, String separator)
      Returns the given text split up into an array of strings, at the occurrances of the separator string. In contrary to method parts() the separator is a one or many character sequence delimiter. That is, only the exact sequence of the characters in separator identifies the end of a substring. Subsequent occurences of separator will be skipped. Therefore no empty strings ("") will be in the result array.
      Parameters:
      text - The text to be split up
      separator - The string that separates the substrings
      Returns:
      An array of substrings not containing any separator anymore
      See Also:
    • allSubstrings

      public String[] allSubstrings(String text, String separator)
      Returns the given text split up into an array of strings, at the occurrances of the separator string. In contrary to method allParts() the separator is a one or many character sequence delimiter. That is, only the exact sequence of the characters in separator identifies the end of a substring. Subsequent occurences of separator are not skipped. They are added as empty strings to the result.
      Parameters:
      text - The text to be split up
      separator - The string that separates the substrings
      Returns:
      An array of substrings not containing any separator anymore
      See Also:
    • getDelimitedSubstring

      public String getDelimitedSubstring(String text, String startDelimiter, String endDelimiter)
      Returns the first substring that is enclosed by the specified delimiters.
      The delimiters are not included in the return string.

      Example:
      getDelimitedSubstring( "This {placeholder} belongs to me", "{", "}" ) --> returns "placeholder"

      Parameters:
      text - The input string that contains the delimited part
      startDelimiter - The start delimiter of the substring
      endDelimiter - The end delimiter of the substring
      Returns:
      The substring or an empty string, if no delimiters are found.
    • getDelimitedSubstring

      public String getDelimitedSubstring(String text, String delimiter)
      Returns the first substring that is enclosed by the specified delimiter.
      The delimiters are not included in the return string.

      Example:
      getDelimitedSubstring( "File 'text.txt' not found.", "'", "'" ) --> returns "text.txt"

      Parameters:
      text - The input string that contains the delimited part
      delimiter - The start and end delimiter of the substring
      Returns:
      The substring or an empty string, if no delimiters are found.
    • stackTrace

      public String stackTrace(Throwable throwable)
      Prints the stack trace of the specified throwable to a string and returns it.
      Parameters:
      throwable -
      Returns:
    • leftPadCh

      public String leftPadCh(String str, int len, char ch)
      Returns the given string filled (on the left) up to the specified length with the given character.
      Example: leftPadCh( "12", 6, '0' ) --> "000012"
      Parameters:
      str -
      len -
      ch -
      Returns:
    • leftPad

      public String leftPad(String str, int len)
      Returns the given string filled (on the left) up to the specified length with spaces.
      Example: leftPad( "XX", 4 ) --> " XX"
      Parameters:
      str - The string that has to be filled up to the specified length
      len - The length of the result string
      Returns:
    • leftPadCh

      public String leftPadCh(int value, int len, char fillChar)
      Returns the given integer as string filled (on the left) up to the specified length with the given fill character.
      Example: leftPad( 24, 5, '' ) --> "24"
      Parameters:
      value -
      len -
      fillChar -
      Returns:
    • leftPad

      public String leftPad(int value, int len)
      Returns the given integer as string filled (on the left) up to the specified length with zeroes.
      Example: leftPad( 12, 4 ) --> "0012"
      Parameters:
      value -
      len -
      Returns:
    • rightPadCh

      public String rightPadCh(String str, int len, char ch)
      Returns the given string filled (on the right) up to the specified length with the given character.
      Example: rightPadCh( "34", 5, 'X' ) --> "34XXX"
      Parameters:
      str -
      len -
      ch -
      Returns:
    • rightPad

      public String rightPad(String str, int len)
      Returns the given string filled (on the right) up to the specified length with spaces.
      Example: rightPad( "88", 6 ) --> "88 "
      Parameters:
      str -
      len -
      Returns:
    • rightPadCh

      public String rightPadCh(int value, int len, char fillChar)
      Returns the given integer as string filled (on the right) up to the specified length with the given character.
      Example: rightPad( "32", 4, '#' ) --> "32##"
      Parameters:
      value -
      len -
      fillChar -
      Returns:
    • rightPad

      public String rightPad(int value, int len)
      Returns the given integer as string filled (on the right) up to the specified length with spaces.
      Example: rightPad( "17", 5 ) --> "17 "
      Parameters:
      value -
      len -
      Returns:
    • centerCh

      public String centerCh(String str, int len, char ch)
      Returns the given string filled equally left and right up to the specified length with the given character.
      Example: centerCh( "A", 5, '_' ) --> "__A__"
      Example: centerCh( "XX", 7, '+' ) --> "++XX+++"
      Parameters:
      str -
      len -
      ch -
      Returns:
    • center

      public String center(String str, int len)
      Returns the given string filled (on the right and right) up to the specified length with spaces.
      Example: center( "Mike", 10 ) --> " Mike "
      Parameters:
      str -
      len -
      Returns:
    • append

      public String[] append(String[] strings, String string)
      Returns the given string array extended by one element that hold the specified string.
      Parameters:
      strings -
      string -
      Returns:
    • append

      public String[] append(String[] strings, String[] appendStrings)
      Returns an array of strings that contains all strings given by the first and second string array. The strings from the second array will be added at the end of the first array.
      Parameters:
      strings - The array of string to which to append
      appendStrings - The string to be appended to the first array
      Returns:
    • appendIfNotThere

      public String[] appendIfNotThere(String[] strings, String appendString)
      Returns an array of strings that contains all strings given in the first plus the specified string to append, if it is not already in the given array.
      Parameters:
      strings -
      appendString -
      Returns:
    • appendIfNotThere

      public String[] appendIfNotThere(String[] strings, String[] appendStrings)
      Returns an array of strings that contains all strings given in the first plus all strings of the second array that are not already in the first array.
      Parameters:
      strings -
      appendStrings -
      Returns:
    • remove

      public String[] remove(String[] strings, String[] removeStrings)
      Removes all string of the second array from the first array. Returns a new array of string that contains all remaining strings of the original strings array.
      Parameters:
      strings - The array from which to remove the strings
      removeStrings - The strings to be removed
      Returns:
    • remove

      public String[] remove(String[] strings, String removeString)
      Removes the given string from the specified string array. Returns a new array of string that contains all remaining strings of the original strings array.
      Parameters:
      strings - The array from which to remove the string
      removeString - The string to be removed
      Returns:
    • removeNull

      public String[] removeNull(String[] strings)
      Removes all null values from the given string array. Returns a new string array that contains all none null values of the input array.
      Parameters:
      strings - The array to be cleared of null values
      Returns:
    • asString

      public String asString(String[] strings, String separator)
      Returns a string that contains all given strings concatenated and separated by the specified separator.
      Parameters:
      strings - The array of strings that should be concatenated
      separator - The separator between the strings
      Returns:
      One string containing the concatenated strings separated by separator
    • asString

      public String asString(String[] strings)
      Returns a string that contains all given strings concatenated and separated by comma.
      Parameters:
      strings - The array of strings that should be concatenated
      Returns:
      One string containing the concatenated strings separated by comma (",")
    • indexOf

      public int indexOf(String[] strArray, StringPattern pattern)
      Returns the index of the first string in the given string array that matches the specified string pattern. If no string is found in the array the result is -1.
      Parameters:
      strArray - An array of string (may contain null elements)
      pattern - The pattern the searched string must match
      Returns:
      The index of the matching string in the array or -1 if not found
    • indexOf

      public int indexOf(String[] strArray, String searchStr)
      Returns the index of the specified string in the given string array. It returns the index of the first occurrence of the string. If the string is not found in the array the result is -1. The comparison of the strings is case-sensitive!
      Parameters:
      strArray - An array of string (may contain null elements)
      searchStr - The string to be looked up in the array (null allowed)
      Returns:
      The index of the string in the array or -1 if not found
    • indexOfIgnoreCase

      public int indexOfIgnoreCase(String[] strArray, String searchStr)
      Returns the index of the specified string in the given string array. It returns the index of the first occurrence of the string. If the string is not found in the array the result is -1. The comparison of the strings is case-insensitive!
      Parameters:
      strArray - An array of string (may contain null elements)
      searchStr - The string to be looked up in the array (null allowed)
      Returns:
      The index of the string in the array or -1 if not found
    • contains

      public boolean contains(String[] strArray, String searchStr, boolean ignoreCase)
      Returns whether or not the specified string can be found in the given string array.
      Parameters:
      strArray - An array of string (may contain null elements)
      searchStr - The string to be looked up in the array (null allowed)
      ignoreCase - Defines whether or not the comparison is case-sensitive.
      Returns:
      true, if the specified array contains the given string
    • contains

      public boolean contains(String[] strArray, StringPattern pattern)
      Returns whether or not a string can be found in the given string array that matches the specified string pattern.
      Parameters:
      strArray - An array of string (may contain null elements)
      pattern - The string pattern to match against in the array (null allowed)
      Returns:
      true, if the specified array contains a string matching the pattern
    • contains

      public boolean contains(String[] strArray, String searchStr)
      Returns whether or not the specified string can be found in the given string array. The comparison of the strings is case-sensitive!
      Parameters:
      strArray - An array of string (may contain null elements)
      searchStr - The string to be looked up in the array (null allowed)
      Returns:
      true, if the specified array contains the given string
    • containsIgnoreCase

      public boolean containsIgnoreCase(String[] strArray, String searchStr)
      Returns whether or not the specified string can be found in the given string array. The comparison of the strings is case-insensitive!
      Parameters:
      strArray - An array of string (may contain null elements)
      searchStr - The string to be looked up in the array (null allowed)
      Returns:
      true, if the specified array contains the given string
    • copyFrom

      public String[] copyFrom(String[] from, int start)
      Returns all elements of string array from in a new array from index start up to the end. If start index is larger than the array's length, an empty array will be returned.
      Parameters:
      from - The string array the elements should be copied from
      start - Index of the first element to copy
      Returns:
    • copyFrom

      public String[] copyFrom(String[] from, int start, int end)
      Returns all elements of string array from in a new array from index start up to index end (inclusive). If end is larger than the last valid index, it will be reduced to the last index. If end index is less than start index, an empty array will be returned.
      Parameters:
      from - The string array the elements should be copied from
      start - Index of the first element to copy
      end - Index of last element to be copied
      Returns:
    • cutTail

      public String cutTail(String text, String separator)
      Returns the portion of the given string that comes before the last occurance of the specified separator.
      If the separator could not be found in the given string, then the string is returned unchanged.

      Examples:

      cutTail( "A/B/C", "/" ) ; // returns "A/B"
      cutTail( "A/B/C", "," ) ; // returns "A/B/C"

      Parameters:
      text - The string from which to cut off the tail
      separator - The separator from where to cut off
      Returns:
      the string without the separator and without the characters after the separator
      See Also:
    • cutHead

      public String cutHead(String text, String separator)
      Returns the portion of the given string that stands after the last occurance of the specified separator.
      If the separator could not be found in the given string, then the string is returned unchanged.

      Examples:

      cutHead( "A/B/C", "/" ) ; // returns "C"
      cutHead( "A/B/C", "," ) ; // returns "A/B/C"

      Parameters:
      text - The string from which to cut off the head
      separator - The separator up to which to cut off
      Returns:
      the string without the separator and without the characters before the separator
      See Also:
    • splitNameValue

      public String[] splitNameValue(String str, String separator)
      Returns a string array with two elements where the first is the attribute name and the second is the attribute value. Splits the given string at the first occurance of separator and returns the piece before the separator in element 0 and the piece after the separator in the returned array. If the separator is not found, the first element contains the full string and the second an empty string.
      Parameters:
      str - The string that contains the name-value pair
      separator - The separator between name and value
      Returns:
    • prefix

      public String prefix(String str, String separator)
      Returns the substring of the given string that comes before the first occurance of the specified separator. If the string starts with a separator, the result will be an empty string. If the string doesn't contain the separator the method returns null.

      Examples:

      prefix( "A/B/C", "/" ) ; // returns "A"
      prefix( "A/B/C", "," ) ; // returns null

      Parameters:
      str - The string of which the prefix is desired
      separator - Separates the prefix from the rest of the string
      Returns:
      See Also:
    • suffix

      public String suffix(String str, String separator)
      Returns the substring of the given string that comes after the first occurance of the specified separator. If the string ends with a separator, the result will be an empty string. If the string doesn't contain the separator the method returns null.

      Examples:

      suffix( "A/B/C", "/" ) ; // returns "B/C"
      suffix( "A/B/C", "," ) ; // returns null

      Parameters:
      str - The string of which the suffix is desired
      separator - Separates the suffix from the rest of the string
      Returns:
      See Also:
    • upTo

      public String upTo(String str, String separator)
      Returns the substring of the given string that comes before the first occurance of the specified separator. If the string starts with a separator, the result will be an empty string. If the string doesn't contain the separator the method returns the whole string unchanged.

      Examples:

      upTo( "A/B/C", "/" ) ; // returns "A"
      upTo( "A/B/C", "," ) ; // returns "A/B/C"
      upTo( "/A/B/C", "/" ) ; // returns ""

      Parameters:
      str - The string of which the prefix is desired
      separator - Separates the prefix from the rest of the string
      Returns:
      See Also:
    • startingFrom

      public String startingFrom(String str, String separator)
      Returns the substring of the given string that comes after the first occurance of the specified separator. If the string doesn't contain the separator the method returns the whole string unchanged.

      Examples:

      startingFrom( "A/B/C", "/" ) ; // returns "B/C"
      startingFrom( "A/B/C", "," ) ; // returns "A/B/C"

      Parameters:
      str - The string of which the suffix is desired
      separator - Separates the suffix from the rest of the string
      Returns:
      See Also:
    • reverse

      public String reverse(String str)
      Returns a string that contains all characters of the given string in reverse order.
      Parameters:
      str -
      Returns:
    • toMap

      public Map toMap(String str, String elementSeparator, String keyValueSeparator, Map map)
      Returns the given map with new entries from the specified String. If the specified map is null a new empty java.util.Hashtable will be created.
      The string is split up into elements separated by the elementSeparator parameter. If this parameter is null the default separator "," is used.
      After that each part is split up to a key-value pair separated by the keyValueSeparator parameter. If this parameter is null the default "=" is used.
      Then the key-value pairs are added to the map and the map is returned.

      Be aware that all leading and trailing whitespaces of keys and values will be removed!

      Parameters:
      str - The string that contains the list of key-value pairs
      elementSeparator - The separator between the elements of the list
      keyValueSeparator - The separator between the keys and values
      map - The map to which the key-value pairs are added
      Returns:
    • asMap

      public Map asMap(String str)
      Returns a new map object that contains all key-value pairs of the specified string.
      The separator between the elements is assumed to be "," and "=" between key and value.

      Example:
      "main=Fred,support1=John,support2=Stella,manager=Oscar"

      Be aware that all leading and trailing whitespaces of keys and values will be removed!

      Parameters:
      str - The string with the list of key-value pairs
      Returns:
    • asMap

      public Map asMap(String str, String elementSeparator)
      Returns a new map object that contains all key-value pairs of the specified string.
      The separator between the keys and values is assumed to be "=".

      Be aware that all leading and trailing whitespaces of keys and values will be removed!

      Parameters:
      str - The string that contains the list of key-value pairs
      elementSeparator - The separator between the elements of the list
      Returns:
    • asMap

      public Map asMap(String str, String elementSeparator, String keyValueSeparator)
      Returns a new map object that contains all key-value pairs of the specified string.

      Be aware that all leading and trailing whitespaces of keys and values will be removed!

      Parameters:
      str - The string that contains the list of key-value pairs
      elementSeparator - The separator between the elements of the list
      keyValueSeparator - The separator between the keys and values
      Returns:
    • toMap

      public Map toMap(String str, String elementSeparator, Map map)
      Returns the given map object with all key-value pairs of the specified string added to it.
      The separator between the keys and values is assumed to be "=".

      Be aware that all leading and trailing whitespaces of keys and values will be removed!

      Parameters:
      str - The string that contains the list of key-value pairs
      elementSeparator - The separator between the elements of the list
      map - The map to which the key-value pairs are added
      Returns:
    • toMap

      public Map toMap(String str, Map map)
      Adds all key-value pairs of the given string to the specified map.
      The separator between the elements is assumed to be "," and "=" between key and value.

      Be aware that all leading and trailing whitespaces of keys and values will be removed!

      Parameters:
      str - The string that contains the list of key-value pairs
      map - The map to which the key-value pairs are added
      Returns:
    • asProperties

      public Properties asProperties(String str)
      Adds all key-value pairs of the given string to a new properties object.
      The separator between the elements is assumed to be "," and "=" between key and value.

      Be aware that all leading and trailing whitespaces of keys and values will be removed!

      Parameters:
      str - The string that contains the list of key-value pairs
      Returns:
    • toProperties

      public Properties toProperties(String str, Properties properties)
      Adds all key-value pairs of the given string to the specified properties.
      The separator between the elements is assumed to be "," and "=" between key and value.

      Be aware that all leading and trailing whitespaces of keys and values will be removed!

      Parameters:
      str - The string that contains the list of key-value pairs
      properties - The properties where the key-value pairs should be added
      Returns:
    • trimSeparator

      protected String trimSeparator(String text, String separator)
      Cuts off all leading and trailing occurences of separator in text.
      Parameters:
      text -
      separator -
      Returns:
    • parts

      protected String[] parts(String text, String delimiters, boolean all)
      Returns an array of substrings of the given text.
      The separators between the substrings are the given delimiters. Each character in the delimiter string is treated as a separator.
      Parameters:
      text - The string that should be splitted into substrings
      delimiters - All characters that should be recognized as a separator or substrings
      all - If true, empty elements will be returned, otherwise thye are skipped
      Returns:
      An array of substrings of the given text
    • collectParts

      protected void collectParts(List list, StringTokenizer tokenizer)
    • collectParts

      protected void collectParts(List list, StringTokenizer tokenizer, String delimiter)
    • substrings

      protected String[] substrings(String text, String separator, boolean all)
      Returns the given text split up into an array of strings, at the occurrances of the separator string. In contrary to method parts() the separator is a one or many character sequence delimiter. That is, only the exact sequence of the characters in separator identifies the end of a substring. Parameter all defines whether empty strings between consecutive separators are added to the result or not.
      Parameters:
      text - The text to be split up
      separator - The string that separates the substrings
      all - If true, empty strings are added, otherwise skipped
      Returns:
      An array of substrings not containing any separator anymore
      See Also:
    • padCh

      protected String padCh(String str, int len, char ch, boolean left)
    • indexOfString

      protected int indexOfString(String[] strArray, String searchStr, boolean ignoreCase)
    • prefix

      protected String prefix(String str, String separator, boolean returnNull)
      Returns the substring of the given string that comes before the first occurance of the specified separator. If the string starts with a separator, the result will be an empty string. If the string doesn't contain the separator the method returns null or the whole string, depending on the returnNull flag.
      Parameters:
      str - The string of which the prefix is desired
      separator - Separates the prefix from the rest of the string
      returnNull - Specifies if null will be returned if no separator is found
      Returns:
    • suffix

      protected String suffix(String str, String separator, boolean returnNull)
      Returns the substring of the given string that comes after the first occurance of the specified separator. If the string ends with a separator, the result will be an empty string. If the string doesn't contain the separator the method returns null or the whole string, depending on the returnNull flag.
      Parameters:
      str - The string of which the suffix is desired
      separator - Separates the suffix from the rest of the string
      returnNull - Specifies if null will be returned if no separator is found
      Returns:
    • removeFromStringArray

      protected String[] removeFromStringArray(String[] strings, String[] removeStrings)
      Removes the given strings from the array. If removeStrings is null it means that all null values are removed from the first array.
      Parameters:
      strings -
      removeStrings -
      Returns: