org.pfsw.text
Class StringUtil

java.lang.Object
  extended by org.pfsw.text.StringUtil

public class StringUtil
extends java.lang.Object

The sole instance of this class provides several convenience methods for string manipulation such as substring replacement or character repetition.
It also provides many convenience methods to split up strings and to handle string arrays.

Get the instance by calling StringUtil.current().


Field Summary
static char CH_CR
          Constant for the carriage return character
static char CH_NEWLINE
          Constant for the new line character
static char CH_SPACE
          Constant for the space character
static char CH_TAB
          Constant for the tabulator character
static org.pfsw.bif.text.IStringPair[] DEFAULT_TEXT_DELIMITERS
          Defines the delimiter string pair for two apostrophes: ' '
static org.pfsw.bif.text.IStringPair DELIMITER_APOS
          Defines the delimiter string pair for two apostrophes: ' '
static org.pfsw.bif.text.IStringPair DELIMITER_QUOTE
          Defines the delimiter string pair for two quotes: " "
static java.lang.String EMPTY_STRING
          An empty String to avoid multiple creation of such an object
static java.lang.String[] EMPTY_STRING_ARRAY
          An empty String array to avoid multiple creation of such an object
static java.lang.String NULL_STRING
          A string representing null (containing character '\0')
static java.lang.String STR_CR
          Constant for the String representation of the carriage return character
static java.lang.String STR_INNER_CLASS_SEPARATOR
          Constant that defines the separator for inner classes in full qualified class names ("$")
static java.lang.String STR_NEWLINE
          Constant for the String representation of the new line character
static java.lang.String STR_PACKAGE_SEPARATOR
          Constant that defines the separator for package elements and classes (".")
static java.lang.String STR_SPACE
          Constant for the String representation of the space character
static java.lang.String STR_TAB
          Constant for the String representation of the tabulator character
static StringUtil SU
          An instance of this class which can be easily included as static import and then used like SU.repeat('x', 3).
 
Constructor Summary
protected StringUtil()
          Creates new instance.
 
Method Summary
 void addAll(java.util.Collection<java.lang.String> collection, java.lang.String... strings)
          Adds all given strings to the specified collection.
protected  void addAll(java.util.Collection<java.lang.String> collection, java.lang.String[] strings, boolean justNew)
          Adds all given strings to the specified collection.
 void addAllNew(java.util.Collection<java.lang.String> collection, java.lang.String... strings)
          Adds all given strings to the specified collection, if they are not already in the collection.
 java.lang.String[] allParts(java.lang.String text, java.lang.String separators)
          Returns an array of substrings of the given text.
 java.lang.String[] allParts(java.lang.String text, java.lang.String separators, char quoteChar)
          Returns an array of substrings of the given text.
 java.lang.String[] allParts(java.lang.String text, java.lang.String separators, char[] quoteChars)
          Returns an array of substrings of the given text.
 java.lang.String[] allSubstrings(java.lang.String text, java.lang.String separator)
          Returns the given text split up into an array of strings, at the occurrences of the separator string.
 java.lang.String[] append(java.lang.String[] strings, java.lang.String string)
          Returns the given string array extended by one element that hold the specified string.
 java.lang.String[] append(java.lang.String[] strings, java.lang.String[] appendStrings)
          Returns an array of strings that contains all strings given by the first and second string array.
 java.lang.String[] appendIfNotThere(java.lang.String[] strings, java.lang.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.
 java.lang.String[] appendIfNotThere(java.lang.String[] strings, java.lang.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.
 boolean areEqual(java.lang.String[] strings1, java.lang.String[] strings2)
          Returns true if all elements of the first given array are in the second given array and the length of both arrays are equal.
 boolean areEqualIgnoreCase(java.lang.String[] strings1, java.lang.String[] strings2)
          Returns true if all elements of the first given array are in the second given array and the length of both arrays are equal.
 org.pfsw.bif.configuration.IConfigSettings asConfigSettings(java.util.Map<java.lang.String,java.lang.String> map)
          Converts the given map to an object that conforms to interface IConfigSettings.
 org.pfsw.bif.configuration.IConfigSettings asConfigSettings(java.util.Properties properties)
          Converts the given properties to an object that conforms to interface IConfigSettings.
 org.pfsw.bif.configuration.IConfigSettings asConfigSettings(java.lang.String str)
          Returns a new IConfigSettings object that contains all key-value pairs of the specified string.
 org.pfsw.bif.configuration.IConfigSettings asConfigSettings(java.lang.String str, java.lang.String elementSeparator, java.lang.String keyValueSeparator)
          Returns a new IConfigSettings object that contains all key-value pairs of the specified string.
 int asInteger(java.lang.String value, int defaultValue)
          Converts the given string to an int or returns the given default value if the string does not represent a valid integer value.
 java.util.List<java.lang.String> asList(java.lang.String... strings)
          Returns a new List initialized with the given strings.
 long asLong(java.lang.String value, long defaultValue)
          Converts the given string to a long or returns the given default value if the string does not represent a valid long value.
 java.util.Map<java.lang.String,java.lang.String> asMap(java.lang.String str)
          Returns a new map object that contains all key-value pairs of the specified string.
 java.util.Map<java.lang.String,java.lang.String> asMap(java.lang.String[][] stringPairArray)
          Converts the given array of string arrays to a map.
 java.util.Map<java.lang.String,java.lang.String> asMap(java.lang.String str, java.lang.String elementSeparator)
          Returns a new map object that contains all key-value pairs of the specified string.
 java.util.Map<java.lang.String,java.lang.String> asMap(java.lang.String str, java.lang.String elementSeparator, java.lang.String keyValueSeparator)
          Returns a new map object that contains all key-value pairs of the specified string.
 java.util.Properties asProperties(java.lang.String str)
          Adds all key-value pairs of the given string to a new properties object.
<T> org.pfsw.bif.facet.IReadOnlyNamedValues<T>
asReadOnlyNamedValues(java.util.Map<java.lang.String,T> map)
          Converts the given map to an object that conforms to interface IReadOnlyNamedValues.
 org.pfsw.bif.facet.IReadOnlyNamedValues<java.lang.String> asReadOnlyNamedValues(java.util.Properties properties)
          Converts the given properties to an object that conforms to interface IReadOnlyNamedValues.
 java.lang.String asSortedString(java.lang.String[] strings)
          Returns a string that contains all given strings sorted (in ascending order), concatenated and separated by the specified separator.
 java.lang.String asSortedString(java.lang.String[] strings, java.lang.String separator)
          Returns a string that contains all given strings sorted (in ascending order), concatenated and separated by the specified separator.
 java.lang.String asSortedString(java.lang.String[] strings, java.lang.String separator, boolean ascending)
          Returns a string that contains all given strings sorted, concatenated and separated by the specified separator.
 java.lang.String asSortedString(java.lang.String[] strings, java.lang.String separator, java.util.Comparator<java.lang.String> comparator)
          Returns a string that contains all given strings sorted, concatenated and separated by the specified separator.
 java.lang.String asString(char ch)
          Returns a new string that contains only the given character.
 java.lang.String asString(java.util.Collection<java.lang.String> strings)
          Returns a string that contains all strings from the given collection concatenated and separated by comma.
 java.lang.String asString(java.util.Collection<java.lang.String> strings, java.lang.String separator)
          Returns a string that contains all strings from the given collection concatenated and separated by the specified separator.
 java.lang.String asString(java.util.Map<?,?> map)
          Converts the given map to a string.
 java.lang.String asString(java.util.Map<?,?> map, java.lang.String elementSeparator)
          Converts the given map to a string utilizing the given separator.
 java.lang.String asString(java.util.Map map, java.lang.String elementSeparator, java.lang.String keyValueSeparator)
          Converts the given map to a string utilizing the given separators.
 java.lang.String asString(java.lang.Object object)
          Returns a string representation of the given object.
 java.lang.String asString(java.lang.String[] strings)
          Returns a string that contains all given strings concatenated and separated by comma.
 java.lang.String asString(java.lang.String[] strings, java.lang.String separator)
          Returns a string that contains all given strings concatenated and separated by the specified separator.
 java.lang.String asStringEnclosed(java.util.Collection<java.lang.String> strings, java.lang.String prefix, java.lang.String suffix, java.lang.String separator)
          Returns a string that contains all strings from the given collection concatenated and separated by the specified separator.
 java.lang.String[] asStrings(java.util.Collection<java.lang.String> collection)
          Returns a string array containing all elements of the given collection.
 java.lang.String[] asStrings(java.util.Enumeration<java.lang.String> enumeration)
          Returns a string array containing all elements of the given enumeration.
 java.lang.String bytesToHex(byte... bytes)
          Converts the given bytes to a string with a hex representation for each byte.
 java.lang.String bytesToHex(java.lang.String separator, byte... bytes)
          Converts the given bytes to a string with a hex representation for each byte.
 java.lang.String center(java.lang.String str, int len)
          Returns the given string filled (on the right and right) up to the specified length with spaces.
 java.lang.String centerCh(java.lang.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(java.util.List<java.lang.String> list, java.util.StringTokenizer tokenizer)
           
protected  void collectParts(java.util.List<java.lang.String> list, java.util.StringTokenizer tokenizer, java.lang.String delimiter)
           
 java.lang.String concat(java.lang.String... elements)
          Creates a string from the given elements, all separated by comma (',').
 boolean contains(java.lang.String[] strArray, java.lang.String searchStr)
          Returns whether or not the specified string can be found in the given string array.
 boolean contains(java.lang.String[] strArray, java.lang.String searchStr, boolean ignoreCase)
          Returns whether or not the specified string can be found in the given string array.
 boolean contains(java.lang.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(java.lang.String str, char ch)
          Returns whether or not the specified string contains the given character.
 boolean containsAll(java.lang.String[] strArray, boolean ignoreCase, java.lang.String... strings)
          Returns whether or not the specified strings can all be found in the specified string array.
 boolean containsAll(java.lang.String[] strArray, java.lang.String... strings)
          Returns whether or not the specified strings can all be found in the specified string array.
 boolean containsAllIgnoreCase(java.lang.String[] strArray, java.lang.String... strings)
          Returns whether or not the specified strings can all be found in the specified string array.
 boolean containsIgnoreCase(java.lang.String[] strArray, java.lang.String searchStr)
          Returns whether or not the specified string can be found in the given string array.
 java.util.Collection<java.lang.String> copy(java.util.Collection<java.lang.String> strings, org.pfsw.bif.text.IStringFilter filter)
          Returns a new array that contains all strings of the given array that matched the specified filter.
 java.lang.String[] copy(java.lang.String... strings)
          Returns a copy (new array) that contains all the strings of the given array
 java.lang.String[] copy(java.lang.String[] strings, org.pfsw.bif.text.IStringFilter filter)
          Returns a new array that contains all strings of the given array that matched the specified filter.
 java.lang.String[] copyFrom(java.lang.String[] from, int start)
          Returns all elements of string array from in a new array from index start up to the end.
 java.lang.String[] copyFrom(java.lang.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).
 java.lang.String[] copyLowerCase(java.lang.String[] strings)
          Returns a copy of the given string array where all elements are converted to lower case.
 void copyMapToProperties(java.util.Map<java.lang.String,java.lang.String> map, java.util.Properties properties)
          Copies all entries from the given map to the given properties object.
protected
<T extends java.util.Collection<java.lang.String>>
T
copyStrings(java.lang.Class<T> collClass, java.lang.String[] strings, org.pfsw.bif.text.IStringFilter filter, boolean allMatching)
           
 java.lang.String[] copyUpperCase(java.lang.String[] strings)
          Returns a copy of the given string array where all elements are converted to upper case.
 java.util.Collection<java.lang.String> copyWithout(java.util.Collection<java.lang.String> strings, org.pfsw.bif.text.IStringFilter filter)
          Returns a new collection that contains all strings of the given collection that do NOT match the specified filter.
 java.lang.String[] copyWithout(java.lang.String[] strings, org.pfsw.bif.text.IStringFilter filter)
          Returns a new array that contains all strings of the given array that do NOT match the specified filter.
 int count(java.lang.String sourceStr, java.lang.String subStr)
          Returns how often the given sub string occurs in the source String.
static StringUtil current()
          Returns the one and only instance of this class.
 java.lang.String cutHead(java.lang.String text, java.lang.String separator)
          Returns the portion of the given string that comes after the last occurrence of the specified separator.
 java.lang.String cutTail(java.lang.String text, java.lang.String separator)
          Returns the portion of the given string that comes before the last occurrence of the specified separator.
protected  boolean equals(java.lang.String[] strings1, java.lang.String[] strings2, boolean ignoreCase)
          Returns true if all elements of the first array are in the second array and the length of both arrays are equal.
protected  org.pfsw.bif.text.IStringPair findInString1(org.pfsw.bif.text.IStringPair[] stringPairs, char ch, boolean ignoreCase)
          Returns the string pair of the specified array that's first string starts with the specified character.
 java.lang.String getDelimitedSubstring(java.lang.String text, org.pfsw.bif.text.IStringPair... delimiters)
          Returns the first substring that is enclosed by one of the specified delimiter pairs.
 java.lang.String getDelimitedSubstring(java.lang.String text, org.pfsw.bif.text.IStringPair delimiter)
          Returns the first substring that is enclosed by the specified delimiter pair.
 java.lang.String getDelimitedSubstring(java.lang.String text, java.lang.String delimiter)
          Returns the first substring that is enclosed by the specified delimiter.
 java.lang.String getDelimitedSubstring(java.lang.String text, java.lang.String startDelimiter, java.lang.String endDelimiter)
          Returns the first substring that is enclosed by the specified delimiters.
 java.lang.String getPackageName(java.lang.String qualifiedClassName)
          Returns the package name of the given full qualified class name.
 java.lang.String getString(java.lang.String text)
          Returns a string that does not contain the optional enclosing delimiters " or '.
 java.lang.String getString(java.lang.String text, org.pfsw.bif.text.IStringPair delimiter)
          Returns a string that does not contain the optional enclosing delimiters specified in the second parameter.
 java.lang.String getString(java.lang.String text, org.pfsw.bif.text.IStringPair[] delimiters)
          Returns a string that does not contain the optional enclosing delimiters specified in the second parameter.
 java.lang.String getUnqualifiedClassName(java.lang.String qualifiedClassName)
          Returns the class name without the package name.
 byte[] hexToBytes(java.lang.String hex)
          Converts the given hex string to a byte array.
 byte[] hexToBytes(java.lang.String hex, java.lang.String separator)
          Converts the given hex string to a byte array.
 int indexOf(char[] charArray, char ch, boolean ignoreCase)
          Returns the index of the specified character in the given char array.
 int indexOf(java.lang.String[] strArray, java.lang.String searchStr)
          Returns the index of the specified string in the given string array.
 int indexOf(java.lang.String[] strArray, StringPattern pattern)
          Returns the index of the first string in the given string array that matches the specified string pattern.
 int indexOfIgnoreCase(java.lang.String[] strArray, java.lang.String searchStr)
          Returns the index of the specified string in the given string array.
 int indexOfString(java.lang.String[] strArray, java.lang.String searchStr, boolean ignoreCase)
          Returns the index of the specified string in the given string array.
 boolean isAnyNullOrBlank(java.lang.String... strings)
          Returns true if any one of the given strings is null or blank.
 boolean isFalse(java.lang.String string)
          Returns true if the given string represents a false setting.
 boolean isInteger(java.lang.String value)
          Returns true if the given value is a string containing only digits and optionally a leading minus ('-') and is in the range of a valid integer Integer.MIN_VALUE <= value <= Integer.MAX_VALUE.
 boolean isLong(java.lang.String value)
          Returns true if the given value is a string containing only digits and optionally a leading minus ('-') and is in the range of a valid long - Long.MIN_VALUE <= value <= Long.MAX_VALUE.
 boolean isNoneNullOrBlank(java.lang.String... strings)
          Returns true if none of the given strings is null or blank.
 boolean isNullOrBlank(java.lang.String str)
          Returns true if the given string is null or empty or consists of whitespace characters only.
 boolean isNullOrEmpty(java.lang.String str)
          Returns true if the given string is null or empty
 boolean isNullOrEmpty(java.lang.String[] strings)
          Returns true if the given string array is null or empty
 boolean isPositiveInteger(java.lang.String value)
          Returns true if the given string represents a valid positive integer.
 boolean isPositiveLong(java.lang.String value)
          Returns true if the given string represents a valid positive long.
 boolean isTrue(java.lang.String string)
          Returns true if the given string represents a true setting.
 boolean isZeroOrPositiveInteger(java.lang.String value)
          Returns true if the given string represents a valid positive or zero integer.
 boolean isZeroOrPositiveLong(java.lang.String value)
          Returns true if the given string represents a valid positive or zero long.
 java.lang.String join(java.lang.String separator, java.lang.String... elements)
          Creates a string from the given elements, all separated by the specified separator.
 java.lang.String leftPad(int value, int len)
          Returns the given integer as string filled (on the left) up to the specified length with zeroes.
 java.lang.String leftPad(long value, int len)
          Returns the given long as string filled (on the left) up to the specified length with zeroes.
 java.lang.String leftPad(java.lang.String str, int len)
          Returns the given string filled (on the left) up to the specified length with spaces.
 java.lang.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.
 java.lang.String leftPadCh(long value, int len, char fillChar)
          Returns the given long as string filled (on the left) up to the specified length with the given fill character.
 void leftPadCh(java.lang.StringBuffer buffer, long value, int len, char fillChar)
          Returns the given long as string filled (on the left) up to the specified length with the given fill character.
 java.lang.String leftPadCh(java.lang.String str, int len, char ch)
          Returns the given string filled (on the left) up to the specified length with the given character.
 boolean notNullOrBlank(java.lang.String str)
          Returns true if the given string is not null and not empty and does not consist of whitespace characters only.
 boolean notNullOrEmpty(java.lang.String str)
          Returns true if the given string is not null and not empty
 boolean notNullOrEmpty(java.lang.String[] strings)
          Returns true if the given string array is not null and not empty
protected  void padCh(java.lang.StringBuffer buffer, java.lang.String str, int len, char ch, boolean left)
           
protected  java.lang.String padCh(java.lang.String str, int len, char ch, boolean left)
           
 java.lang.String[] parts(java.lang.String text, java.lang.String separators)
          Returns an array of substrings of the given text.
protected  java.lang.String[] parts(java.lang.String text, java.lang.String delimiters, boolean all)
          Returns an array of substrings of the given text.
 java.lang.String[] parts(java.lang.String text, java.lang.String separators, char quoteChar)
          Returns an array of substrings of the given text.
 java.lang.String[] parts(java.lang.String text, java.lang.String separators, char[] quoteChars)
          Returns an array of substrings of the given text.
 java.lang.String[] parts(java.lang.String text, java.lang.String separators, org.pfsw.bif.text.IStringPair[] quotePairs)
          Returns an array of substrings of the given text.
 java.lang.String prefix(java.lang.String str, java.lang.String separator)
          Returns the substring of the given string that comes before the first occurrence of the specified separator.
protected  java.lang.String prefix(java.lang.String str, java.lang.String separator, boolean returnNull)
          Returns the substring of the given string that comes before the first occurance of the specified separator.
protected  java.lang.String[] quotedParts(java.lang.String str, java.lang.String separators, char[] quoteChars, boolean all)
          Quotes are removed from all parts If str is null an empty array will be returned!
protected  java.lang.String[] quotedParts(java.lang.String str, java.lang.String separators, org.pfsw.bif.text.IStringPair[] quotePairs, boolean all)
           
 java.lang.String[] remove(java.lang.String[] strings, java.lang.String removeString)
          Removes the given string from the specified string array.
 java.lang.String[] remove(java.lang.String[] strings, java.lang.String[] removeStrings)
          Removes all string of the second array from the first array.
 java.lang.String removeAllChars(java.lang.String string, java.lang.String charsToRemove)
          Returns a copy of the given string where all characters have been removed that also occurred in the second string.
 java.lang.String removeChar(java.lang.String string, char charToRemove)
          Returns a copy of the given string where the specified character has been removed.
protected  java.lang.String removeCharsFromString(java.lang.String string, java.lang.String charsToRemove)
           
protected  java.lang.String[] removeFromStringArray(java.lang.String[] strings, java.lang.String[] removeStrings)
          Removes the given strings from the array.
 java.lang.String[] removeNull(java.lang.String[] strings)
          Removes all null values from the given string array.
 java.lang.String repeat(char ch, int count)
          Returns a string with size of count and all characters initialized with ch.
 java.lang.String replaceAll(java.lang.String sourceStr, java.lang.String oldSubStr, java.lang.String newSubStr)
          Returns the given string with all found oldSubStr replaced by newSubStr.
 java.lang.String replaceEach(java.lang.String sourceStr, java.lang.String oldChars, java.lang.String newChars)
          Returns the given sourceString with all characters occurring in oldChars replaced by the characters at the corresponding index in newChars.
 java.lang.String reverse(java.lang.String str)
          Returns a string that contains all characters of the given string in reverse order.
 java.lang.String rightPad(int value, int len)
          Returns the given integer as string filled (on the right) up to the specified length with spaces.
 java.lang.String rightPad(long value, int len)
          Returns the given integer as string filled (on the right) up to the specified length with spaces.
 java.lang.String rightPad(java.lang.String str, int len)
          Returns the given string filled (on the right) up to the specified length with spaces.
 java.lang.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.
 java.lang.String rightPadCh(long value, int len, char fillChar)
          Returns the given long as string filled (on the right) up to the specified length with the given character.
 java.lang.String rightPadCh(java.lang.String str, int len, char ch)
          Returns the given string filled (on the right) up to the specified length with the given character.
 java.lang.String setFileNameExtension(java.lang.String filename, java.lang.String extension, boolean replace)
          Sets the given extension as filename extension to the given filename.
 java.lang.String[] split(java.lang.String string, java.lang.String separator)
          Splits the given string at each occurrence of the specified separator.
 java.lang.String[] splitNameValue(java.lang.String str, java.lang.String separator)
          Returns a string array with two elements where the first is the attribute name and the second is the attribute value.
 org.pfsw.bif.text.IStringPair splitStringPair(java.lang.String str, java.lang.String separator)
          Returns a string pair where the first is the string before the first occurrence of the defined separator and the second string is everything after that separator.
 java.lang.String stackTrace(java.lang.Throwable throwable)
          Prints the stack trace of the specified Throwable to a string and returns it.
 java.lang.String startingFrom(java.lang.String str, java.lang.String separator)
          Returns the substring of the given string that comes after the first occurrence of the specified separator.
 java.lang.String[] substrings(java.lang.String text, java.lang.String separator)
          Returns the given text split up into an array of strings, at the occurrences of the separator string.
protected  java.lang.String[] substrings(java.lang.String text, java.lang.String separator, boolean all)
          Returns the given text split up into an array of strings, at the occurrences of the separator string.
 java.lang.String suffix(java.lang.String str, java.lang.String separator)
          Returns the substring of the given string that comes after the first occurrence of the specified separator.
protected  java.lang.String suffix(java.lang.String str, java.lang.String separator, boolean returnNull)
          Returns the substring of the given string that comes after the first occurance of the specified separator.
 void toLowerCase(java.lang.String[] strings)
          Modifies the strings in the given array to be all lower case.
 java.util.Map<java.lang.String,java.lang.String> toMap(java.lang.String str, java.util.Map<java.lang.String,java.lang.String> map)
          Adds all key-value pairs of the given string to the specified map.
 java.util.Map<java.lang.String,java.lang.String> toMap(java.lang.String str, java.lang.String elementSeparator, java.util.Map<java.lang.String,java.lang.String> map)
          Returns the given map object with all key-value pairs of the specified string added to it.
 java.util.Map<java.lang.String,java.lang.String> toMap(java.lang.String str, java.lang.String elementSeparator, java.lang.String keyValueSeparator, java.util.Map<java.lang.String,java.lang.String> map)
          Returns the given map with new entries from the specified String.
 java.util.Properties toProperties(java.lang.String str, java.util.Properties properties)
          Adds all key-value pairs of the given string to the specified properties.
 void toUpperCase(java.lang.String[] strings)
          Modifies the strings in the given array to be all upper case.
 java.lang.String translate(java.lang.String text, java.lang.String replacementChars, java.lang.String charsToReplace)
          Returns a string of the same length as the given text parameter.
 java.lang.String trim(java.lang.String str, java.lang.String... unwanted)
          Returns a new string where all leading and trailing unwanted substrings are removed.
protected  java.lang.String trimLoop(int maxLoop, java.lang.String str, java.lang.String[] unwanted)
          Returns a new string where all leading and trailing unwanted substrings are removed.
 java.lang.String[] trimmedParts(java.lang.String text, java.lang.String separators)
          Returns an array of substrings of the given text.
 java.util.List<java.lang.String> trimmedSplit(java.lang.String text, java.lang.String separators)
          Returns a list of substrings of the given text.
 java.lang.String trimOnce(java.lang.String str, java.lang.String... unwanted)
          Returns a new string where the first leading and first trailing unwanted substrings are removed.
protected  java.lang.String trimSeparator(java.lang.String input, java.lang.String separator)
          Cuts off all leading and trailing occurrences of separator in text.
 java.lang.String truncate(java.lang.String string, int len)
          Returns a string that is shortened (chopped off the end) to the specified length.
 java.lang.String upTo(java.lang.String str, java.lang.String separator)
          Returns the substring of the given string that comes before the first occurrence of the specified separator.
 java.lang.String withLeadingChar(java.lang.String string, char ch)
          Returns the given string and ensures that it starts with the given character.
 java.lang.String withoutLeadingChar(java.lang.String string, char ch)
          Returns the given string and ensures that it does not start with the given character.
 java.lang.String withoutTrailingChar(java.lang.String string, char ch)
          Returns the given string and ensures that it does not end with the given character.
 java.lang.String withTrailingChar(java.lang.String string, char ch)
          Returns the given string and ensures that it ends with the given character.
 java.lang.String[] words(java.lang.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 Detail

SU

public static final StringUtil SU
An instance of this class which can be easily included as static import and then used like SU.repeat('x', 3).


CH_SPACE

public static final char CH_SPACE
Constant for the space character

See Also:
Constant Field Values

CH_NEWLINE

public static final char CH_NEWLINE
Constant for the new line character

See Also:
Constant Field Values

CH_CR

public static final char CH_CR
Constant for the carriage return character

See Also:
Constant Field Values

CH_TAB

public static final char CH_TAB
Constant for the tabulator character

See Also:
Constant Field Values

STR_SPACE

public static final java.lang.String STR_SPACE
Constant for the String representation of the space character

See Also:
Constant Field Values

STR_NEWLINE

public static final java.lang.String STR_NEWLINE
Constant for the String representation of the new line character

See Also:
Constant Field Values

STR_CR

public static final java.lang.String STR_CR
Constant for the String representation of the carriage return character

See Also:
Constant Field Values

STR_TAB

public static final java.lang.String STR_TAB
Constant for the String representation of the tabulator character

See Also:
Constant Field Values

STR_PACKAGE_SEPARATOR

public static final java.lang.String STR_PACKAGE_SEPARATOR
Constant that defines the separator for package elements and classes (".")

See Also:
Constant Field Values

STR_INNER_CLASS_SEPARATOR

public static final java.lang.String STR_INNER_CLASS_SEPARATOR
Constant that defines the separator for inner classes in full qualified class names ("$")

See Also:
Constant Field Values

NULL_STRING

public static final java.lang.String NULL_STRING
A string representing null (containing character '\0')

See Also:
Constant Field Values

EMPTY_STRING

public static final java.lang.String EMPTY_STRING
An empty String to avoid multiple creation of such an object

See Also:
Constant Field Values

EMPTY_STRING_ARRAY

public static final java.lang.String[] EMPTY_STRING_ARRAY
An empty String array to avoid multiple creation of such an object


DELIMITER_QUOTE

public static final org.pfsw.bif.text.IStringPair DELIMITER_QUOTE
Defines the delimiter string pair for two quotes: " "


DELIMITER_APOS

public static final org.pfsw.bif.text.IStringPair DELIMITER_APOS
Defines the delimiter string pair for two apostrophes: ' '


DEFAULT_TEXT_DELIMITERS

public static final org.pfsw.bif.text.IStringPair[] DEFAULT_TEXT_DELIMITERS
Defines the delimiter string pair for two apostrophes: ' '

Constructor Detail

StringUtil

protected StringUtil()
Creates new instance.

Method Detail

current

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


addAll

public void addAll(java.util.Collection<java.lang.String> collection,
                   java.lang.String... strings)
Adds all given strings to the specified collection. All null values in the string array will be skipped.

Parameters:
collection - The collection to which the strings are added
strings - The strings to add to the collection

addAllNew

public void addAllNew(java.util.Collection<java.lang.String> collection,
                      java.lang.String... strings)
Adds all given strings to the specified collection, if they are not already in the collection. All null values in the string array will be skipped.

Parameters:
collection - The collection to which the strings are added
strings - The strings to add to the collection

replaceAll

public java.lang.String replaceAll(java.lang.String sourceStr,
                                   java.lang.String oldSubStr,
                                   java.lang.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

replaceEach

public java.lang.String replaceEach(java.lang.String sourceStr,
                                    java.lang.String oldChars,
                                    java.lang.String newChars)
Returns the given sourceString with all characters occurring in oldChars replaced by the characters at the corresponding index in newChars.
This is faster and more convenient than calling sourceString.replace( oldChar, newChar) for each character to replace.

Example: replaceEach( "(Test):77", "():7", "[]/9" ) ==> "[Test]/99"

If oldChars or newChars is null or empty the source string will be returned unchanged. The strings oldChars and newChars should have the same length. However, this method also works with different lengths.

Parameters:
sourceStr - The string in which to replace the characters
oldChars - The characters that must be replaced in sourceString
newChars - The characters that must be used instead of the old characters
Returns:
A new string with the old characters replaced by the new characters

count

public int count(java.lang.String sourceStr,
                 java.lang.String subStr)
Returns how often the given sub string occurs in the source String.
Example: StringUtil.current().count( "Seven of ten", "en" ) ;
returns: 2

Parameters:
sourceStr - The string that should be checked for occurrences of subStr (must not be null)
subStr - The string that is searched for in sourceStr (must not be null)
Returns:
The number of occurrences of subStr in sourceStr

repeat

public java.lang.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 java.lang.String[] words(java.lang.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 split up into whitespace separated words
Returns:
An array of substrings of the given text
See Also:
parts(String, String)

split

public java.lang.String[] split(java.lang.String string,
                                java.lang.String separator)
Splits the given string at each occurrence of the specified separator.

Parameters:
string - The string to be split up.
separator - The separator (whole value is used as separator not the single characters). Must not be null.
Returns:
The split-up elements or null if the given string was null.
Throws:
java.lang.IllegalArgumentException - if the given separator is null or empty.

trimmedParts

public java.lang.String[] trimmedParts(java.lang.String text,
                                       java.lang.String separators)
Returns an array of substrings of the given text.
The separators between the substrings are the given delimiters. Each character in the separators string is treated as a separator.
All consecutive separators are treated as one separator, that is there will be no empty strings in the result.
It is also ensured that all strings in the result array have no leading or trailing white space characters.

Parameters:
text - The string that should be split up into substrings.
separators - All characters that should be recognized as a separator of substrings.
Returns:
An array of substrings of the given text or null if the given text was null.
See Also:
parts(String, String), allParts(String, String), substrings(String, String), allSubstrings(String, String)

trimmedSplit

public java.util.List<java.lang.String> trimmedSplit(java.lang.String text,
                                                     java.lang.String separators)
Returns a list of substrings of the given text.
The separators between the substrings are the given delimiters. Each character in the separators string is treated as a separator.
All consecutive separators are treated as one separator, that is there will be no empty strings in the result.
It is also ensured that all strings in the result array have no leading or trailing white space characters.

Parameters:
text - The string that should be split up into substrings.
separators - All characters that should be recognized as a separator of substrings.
Returns:
A list of substrings of the given text or null if the given text was null.
See Also:
trimmedParts(String, String), parts(String, String), allParts(String, String), substrings(String, String), allSubstrings(String, String)

parts

public java.lang.String[] parts(java.lang.String text,
                                java.lang.String separators)
Returns an array of substrings of the given text.
The separators between the substrings are the given delimiters. Each character in the separators string is treated as a separator.
All consecutive separators are treated as one separator, that is there will be no empty strings in the result.

Parameters:
text - The string that should be split up into substrings
separators - All characters that should be recognized as a separator of substrings
Returns:
An array of substrings of the given text
See Also:
parts(String, String, char), allParts(String, String), substrings(String, String), allSubstrings(String, String)

parts

public java.lang.String[] parts(java.lang.String text,
                                java.lang.String separators,
                                char quoteChar)
Returns an array of substrings of the given text.
The separators between the substrings are the given separators. Each character in the separators string is treated as a separator.
All consecutive separators are treated as one separator, so there will be no empty strings in the result.

Examples:

parts( "A,B,C", ",", '*' ) --> { "A", "B", "C" }
parts( "A,*B,C*", ",", '*' ) --> { "A", "B,C" }
parts( "%A,B;C%;D;E", ";,", '%' ) --> { "A,B;C", "D", "E" }

Parameters:
text - The string that should be split up into substrings
separators - All characters that should be recognized as a separator of substrings
quoteChar - A character that is used to enclose string that might contain a separator
Returns:
An array of substrings of the given text
See Also:
parts(String, String), allParts(String, String), substrings(String, String), allSubstrings(String, String)

parts

public java.lang.String[] parts(java.lang.String text,
                                java.lang.String separators,
                                char[] quoteChars)
Returns an array of substrings of the given text.
The separators between the substrings are the given separators. Each character in the separators string is treated as a separator.
All consecutive separators are treated as one separator, so there will be no empty strings in the result.

The quote characters define that strings enclosed in a pair of such a quote character can contain separators and will not be split up.

Parameters:
text - The string that should be split up into substrings
separators - All characters that should be recognized as a separator of substrings
quoteChars - All characters that can be used to enclose strings that might contain a separator
Returns:
An array of substrings of the given text
See Also:
parts(String, String), allParts(String, String), substrings(String, String), allSubstrings(String, String)

parts

public java.lang.String[] parts(java.lang.String text,
                                java.lang.String separators,
                                org.pfsw.bif.text.IStringPair[] quotePairs)
Returns an array of substrings of the given text.
The separators between the substrings are the given separators. Each character in the separators string is treated as a separator.
All consecutive separators are treated as one separator, so there will be no empty strings in the result.

The quote pairs define that strings enclosed by the characters of such a quote pair can contain separators and will not be split up.


allParts

public java.lang.String[] allParts(java.lang.String text,
                                   java.lang.String separators)
Returns an array of substrings of the given text.
The separators between the substrings are specified in parameter separators. Each character in the separators string is treated as a separator.
For each separator that is followed immediately by another separator 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 split up into substrings
separators - All characters that should be recognized as a separator of substrings
Returns:
An array of substrings of the given text
See Also:
parts(String, String), substrings(String, String), allSubstrings(String, String)

allParts

public java.lang.String[] allParts(java.lang.String text,
                                   java.lang.String separators,
                                   char quoteChar)
Returns an array of substrings of the given text.
The separators between the substrings are specified in parameter separators. Each character in the separators string is treated as a separator.
For each separator that is followed immediately by another separator 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 or at the very end.

Examples:

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 split up into substrings
separators - All characters that should be recognized as a separator of substrings
quoteChar - A character that is used to enclose string that might contain a separator
Returns:
An array of substrings of the given text
See Also:
parts(String, String), substrings(String, String), allSubstrings(String, String)

allParts

public java.lang.String[] allParts(java.lang.String text,
                                   java.lang.String separators,
                                   char[] quoteChars)
Returns an array of substrings of the given text.
The separators between the substrings are specified in parameter separators. Each character in the separators string is treated as a separator.
For each separator that is followed immediately by another separator 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 or at the very end.

The quote character define the delimiters to be used to enclose sub-strings that contain separators but must not be split-up into different parts.

Parameters:
text - The string that should be split up into substrings
separators - All characters that should be recognized as a separator of substrings
quoteChars - The characters that are used to enclose strings that might contain a separator
Returns:
An array of substrings of the given text
See Also:
parts(String, String), substrings(String, String), allSubstrings(String, String)

substrings

public java.lang.String[] substrings(java.lang.String text,
                                     java.lang.String separator)
Returns the given text split up into an array of strings, at the occurrences 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 occurrences 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(String, String), parts(String, String), allParts(String, String)

allSubstrings

public java.lang.String[] allSubstrings(java.lang.String text,
                                        java.lang.String separator)
Returns the given text split up into an array of strings, at the occurrences 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 occurrences 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:
substrings(String, String), parts(String, String), allParts(String, String)

getDelimitedSubstring

public java.lang.String getDelimitedSubstring(java.lang.String text,
                                              org.pfsw.bif.text.IStringPair... delimiters)
Returns the first substring that is enclosed by one of the specified delimiter pairs. It automatically chooses the delimiters that are found first from left to right.
The delimiters are not included in the return string.

Parameters:
text - The input string that contains the delimited part.
delimiters - The start and end delimiters to be looked for.
Returns:
The substring or if no delimiters are found, an empty string.

getDelimitedSubstring

public java.lang.String getDelimitedSubstring(java.lang.String text,
                                              org.pfsw.bif.text.IStringPair delimiter)
Returns the first substring that is enclosed by the specified delimiter pair.
The delimiters are not included in the return string.

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

getDelimitedSubstring

public java.lang.String getDelimitedSubstring(java.lang.String text,
                                              java.lang.String startDelimiter,
                                              java.lang.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 java.lang.String getDelimitedSubstring(java.lang.String text,
                                              java.lang.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.

getString

public java.lang.String getString(java.lang.String text)
Returns a string that does not contain the optional enclosing delimiters " or '. If the given text is null, "" will be returned.

Examples see getString(String, IStringPair[]).

Parameters:
text - The input string that optionally is enclosed in one of the delimiter pairs.
Returns:
The string derived from the input text (never null).

getString

public java.lang.String getString(java.lang.String text,
                                  org.pfsw.bif.text.IStringPair delimiter)
Returns a string that does not contain the optional enclosing delimiters specified in the second parameter. If the given text is null, "" will be returned.

Examples see getString(String, IStringPair[]).

Parameters:
text - The input string that optionally is enclosed in one of the delimiter pairs.
delimiter - The start and end delimiter to be looked for.
Returns:
The string derived from the input text (never null).

getString

public java.lang.String getString(java.lang.String text,
                                  org.pfsw.bif.text.IStringPair[] delimiters)
Returns a string that does not contain the optional enclosing delimiters specified in the second parameter. If the given text is null, "" will be returned.

Examples:
" 'The quick brown fox'", StringPair("'") --> "The quick brown fox"
" last minute ", StringPair("'") --> "last minute"
" ", StringPair("'") --> ""
" ' ' ", StringPair("'") --> " "
" 'Paul Newman ' ", StringPair("\"") --> "'Paul Newman '"
" \"Paul Newman \" ", StringPair("\"") --> "Paul Newman"

Parameters:
text - The input string that optionally is enclosed in one of the delimiter pairs.
delimiters - The start and end delimiter to be looked for.
Returns:
The string derived from the input text (never null).

stackTrace

public java.lang.String stackTrace(java.lang.Throwable throwable)
Prints the stack trace of the specified Throwable to a string and returns it.


leftPadCh

public java.lang.String leftPadCh(java.lang.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"


leftPad

public java.lang.String leftPad(java.lang.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

leftPadCh

public java.lang.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"
leftPadCh( -288, 8, '#' ) --> "-####288"


leftPad

public java.lang.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"


leftPadCh

public java.lang.String leftPadCh(long value,
                                  int len,
                                  char fillChar)
Returns the given long as string filled (on the left) up to the specified length with the given fill character.
Negative values will also be filled-up but the minus character will be the most left character.
Examples: leftPadCh( 24L, 5, '*' ) --> "***24"
leftPadCh( -109L, 8, '0' ) --> "-0000109"


leftPadCh

public void leftPadCh(java.lang.StringBuffer buffer,
                      long value,
                      int len,
                      char fillChar)
Returns the given long as string filled (on the left) up to the specified length with the given fill character.
Negative values will also be filled-up but the minus character will be the most left character.
Examples: leftPadCh( 24L, 5, '*' ) --> "***24"
leftPadCh( -109L, 8, '0' ) --> "-0000109"

Parameters:
buffer - The buffer to append the result to.
value - The value to fill-up to the specified length.
len - The length of the resulting string.
fillChar - The character to use for filling up.

leftPad

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


rightPadCh

public java.lang.String rightPadCh(java.lang.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"


rightPad

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


rightPadCh

public java.lang.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##"


rightPad

public java.lang.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 "


rightPadCh

public java.lang.String rightPadCh(long value,
                                   int len,
                                   char fillChar)
Returns the given long as string filled (on the right) up to the specified length with the given character.
Example: rightPad( 32L, 7, '#' ) --> "32#####"


rightPad

public java.lang.String rightPad(long value,
                                 int len)
Returns the given integer as string filled (on the right) up to the specified length with spaces.
Example: rightPad( 233L, 5 ) --> "233 "


centerCh

public java.lang.String centerCh(java.lang.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+++"


center

public java.lang.String center(java.lang.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 "


append

public java.lang.String[] append(java.lang.String[] strings,
                                 java.lang.String string)
Returns the given string array extended by one element that hold the specified string.


append

public java.lang.String[] append(java.lang.String[] strings,
                                 java.lang.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

appendIfNotThere

public java.lang.String[] appendIfNotThere(java.lang.String[] strings,
                                           java.lang.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

public java.lang.String[] appendIfNotThere(java.lang.String[] strings,
                                           java.lang.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.


remove

public java.lang.String[] remove(java.lang.String[] strings,
                                 java.lang.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

remove

public java.lang.String[] remove(java.lang.String[] strings,
                                 java.lang.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

removeNull

public java.lang.String[] removeNull(java.lang.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.

join

public java.lang.String join(java.lang.String separator,
                             java.lang.String... elements)
Creates a string from the given elements, all separated by the specified separator. All null values in the given elements array will be silently skipped.

Parameters:
separator - The separator to be put between the elements (must not be null).
elements - The elements to concatenate (must not be null).
Returns:
A new string containing all elements separated by the specified separator.

concat

public java.lang.String concat(java.lang.String... elements)
Creates a string from the given elements, all separated by comma (','). All null values in the given elements array will be silently skipped.

Parameters:
elements - The elements to concatenate (must not be null).
Returns:
A new string containing all elements separated by comma.

asString

public java.lang.String asString(java.lang.Object object)
Returns a string representation of the given object. If object is null the NULL_STRING will be returned.

Parameters:
object - The object to get the string representation of.
Returns:
A string representing the given object.

asString

public java.lang.String asString(java.lang.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 (",")

asString

public java.lang.String asString(java.lang.String[] strings,
                                 java.lang.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 (if null the default is used).
Returns:
One string containing the concatenated strings separated by separator.

asString

public java.lang.String asString(java.util.Collection<java.lang.String> strings)
Returns a string that contains all strings from the given collection concatenated and separated by comma.

Parameters:
strings - The collection of strings that should be concatenated
Returns:
One string containing the concatenated strings separated by comma (",")

asString

public java.lang.String asString(java.util.Collection<java.lang.String> strings,
                                 java.lang.String separator)
Returns a string that contains all strings from the given collection concatenated and separated by the specified separator.

Parameters:
strings - The collection of strings that should be concatenated
separator - The separator between the strings
Returns:
One string containing the concatenated strings separated by separator

asStringEnclosed

public java.lang.String asStringEnclosed(java.util.Collection<java.lang.String> strings,
                                         java.lang.String prefix,
                                         java.lang.String suffix,
                                         java.lang.String separator)
Returns a string that contains all strings from the given collection concatenated and separated by the specified separator.

Parameters:
strings - The collection of strings that should be concatenated
separator - The separator between the strings
Returns:
One string containing the concatenated strings separated by separator

asSortedString

public java.lang.String asSortedString(java.lang.String[] strings)
Returns a string that contains all given strings sorted (in ascending order), concatenated and separated by the specified separator.
The comparator used is the java.text.Collator for the default locale.

Example: asSortedString( new String[] {"Carmen","Rose","Anna","Rita"} )
returns "Anna,Carmen,Rita,Rose"

Parameters:
strings - The array of strings that should be concatenated
Returns:
One string containing the concatenated strings separated by separator

asSortedString

public java.lang.String asSortedString(java.lang.String[] strings,
                                       java.lang.String separator)
Returns a string that contains all given strings sorted (in ascending order), concatenated and separated by the specified separator.
The comparator used is the java.text.Collator for the default locale.

Example: asSortedString( new String[] {"Mike","Ben","Gil"}, "/")
returns "Ben/Gil/Mike"

Parameters:
strings - The array of strings that should be concatenated
separator - The separator between the strings (must not be null)
Returns:
One string containing the concatenated strings separated by separator

asSortedString

public java.lang.String asSortedString(java.lang.String[] strings,
                                       java.lang.String separator,
                                       boolean ascending)
Returns a string that contains all given strings sorted, concatenated and separated by the specified separator.
The comparator used is the java.text.Collator for the default locale.

Example: asSortedString( new String[] {"Fred","Sam","Joe"}, ";", false)
returns "Sam;Joe;Fred"

Parameters:
strings - The array of strings that should be concatenated
separator - The separator between the strings (must not be null)
ascending - If true the strings are sorted ascending otherwise descending
Returns:
One string containing the concatenated strings separated by separator

asSortedString

public java.lang.String asSortedString(java.lang.String[] strings,
                                       java.lang.String separator,
                                       java.util.Comparator<java.lang.String> comparator)
Returns a string that contains all given strings sorted, concatenated and separated by the specified separator.

Parameters:
strings - The array of strings that should be concatenated
separator - The separator between the strings (must not be null)
comparator - A comparator that is used to compare the strings when sorting (must not be null)
Returns:
One string containing the sorted, concatenated strings separated by separator

asStrings

public java.lang.String[] asStrings(java.util.Collection<java.lang.String> collection)
Returns a string array containing all elements of the given collection. Of course the elements must be strings, otherwise ClassCastException will be thrown.
If the given collection is null, the result is null as well.

Parameters:
collection - A collection of strings

asStrings

public java.lang.String[] asStrings(java.util.Enumeration<java.lang.String> enumeration)
Returns a string array containing all elements of the given enumeration. Of course the elements must be strings, otherwise ClassCastException will be thrown.
If the given enumeration is null, the result is null as well.

Parameters:
enumeration - An enumeration of strings

asString

public java.lang.String asString(java.util.Map map,
                                 java.lang.String elementSeparator,
                                 java.lang.String keyValueSeparator)
Converts the given map to a string utilizing the given separators. If the given elementSeparator is null it defaults to ','. If the given keyValueSeparator is null it defaults to '='. On all keys and values from the given map the toString() method gets called to add the string representation to the result. If the given map is null the result will also be null. If the given map is empty the result string will be an empty string.

A result string might look like this: "alpha=200,beta=872,delta=N/A"

Parameters:
map - The map that contains the key-value pairs
elementSeparator - The separator between the elements in the string representation
keyValueSeparator - The separator between the keys and values in the string representation
See Also:
toMap(String, String, String, Map)

asString

public java.lang.String asString(java.util.Map<?,?> map,
                                 java.lang.String elementSeparator)
Converts the given map to a string utilizing the given separator. If the given elementSeparator is null it defaults to ','. The separator between keys and values will be '='. On all keys and values from the given map the toString() method gets called to add the string representation to the result. If the given map is null the result will also be null. If the given map is empty the result string will be an empty string.

A result string might look like this: "alpha=200,beta=872,delta=N/A"

Parameters:
map - The map that contains the key-value pairs
elementSeparator - The separator between the elements in the string representation
See Also:
asString(Map, String, String), toMap(String, String, String, Map)

asString

public java.lang.String asString(java.util.Map<?,?> map)
Converts the given map to a string. The separator between the elements will be ','. The separator between keys and values will be '='. On all keys and values from the given map the toString() method gets called to add the string representation to the result. If the given map is null the result will also be null. If the given map is empty the result string will be an empty string.

A result string might look like this: "alpha=200,beta=872,delta=N/A"

Parameters:
map - The map that contains the key-value pairs
See Also:
asString(Map, String, String), toMap(String, String, String, Map)

indexOf

public int indexOf(java.lang.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(java.lang.String[] strArray,
                   java.lang.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(java.lang.String[] strArray,
                             java.lang.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

indexOfString

public int indexOfString(java.lang.String[] strArray,
                         java.lang.String searchStr,
                         boolean ignoreCase)
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 if the ignoreCase parameter is true.

Parameters:
strArray - An array of string (may contain null elements)
searchStr - The string to be looked up in the array (null allowed)
ignoreCase - If true, do case-insensitive comparison.
Returns:
The index of the string in the array or -1 if not found

indexOf

public int indexOf(char[] charArray,
                   char ch,
                   boolean ignoreCase)
Returns the index of the specified character in the given char array. It returns the index of the first occurrence of the character. If the character is not found in the array the result is -1.

Parameters:
charArray - An array of string (may contain null elements)
ch - The string to be looked up in the array (null allowed)
ignoreCase - If comparison should be case-insensitive
Returns:
The index of the character in the array or -1 if not found

contains

public boolean contains(java.lang.String str,
                        char ch)
Returns whether or not the specified string contains the given character.

Parameters:
str - The string to be examined (if null, false will be returned).
ch - The character to look for.

contains

public boolean contains(java.lang.String[] strArray,
                        java.lang.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(java.lang.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(java.lang.String[] strArray,
                        java.lang.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(java.lang.String[] strArray,
                                  java.lang.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

containsAll

public boolean containsAll(java.lang.String[] strArray,
                           java.lang.String... strings)
Returns whether or not the specified strings can all be found in the specified string array. The comparison is case-sensitive.

Parameters:
strArray - An array of strings (may contain null elements)
strings - The strings to be looked up in the array (null not allowed).
Returns:
true, if the specified array contains the all given strings.

containsAllIgnoreCase

public boolean containsAllIgnoreCase(java.lang.String[] strArray,
                                     java.lang.String... strings)
Returns whether or not the specified strings can all be found in the specified string array. The comparison is case-insensitive.

Parameters:
strArray - An array of strings (may contain null elements)
strings - The strings to be looked up in the array (null not allowed).
Returns:
true, if the specified array contains the all given strings.

containsAll

public boolean containsAll(java.lang.String[] strArray,
                           boolean ignoreCase,
                           java.lang.String... strings)
Returns whether or not the specified strings can all be found in the specified string array.

Parameters:
strArray - An array of strings (may contain null elements)
ignoreCase - Defines whether or not the comparison is case-sensitive.
strings - The strings to be looked up in the array (null not allowed).
Returns:
true, if the specified array contains the all given strings.

copyFrom

public java.lang.String[] copyFrom(java.lang.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

copyFrom

public java.lang.String[] copyFrom(java.lang.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

copy

public java.lang.String[] copy(java.lang.String[] strings,
                               org.pfsw.bif.text.IStringFilter filter)
Returns a new array that contains all strings of the given array that matched the specified filter.

Parameters:
strings - The string array to copy from (must not be null)
filter - The filter that determines which strings to copy (if null an empty array will be returned)

copy

public java.lang.String[] copy(java.lang.String... strings)
Returns a copy (new array) that contains all the strings of the given array


copyWithout

public java.lang.String[] copyWithout(java.lang.String[] strings,
                                      org.pfsw.bif.text.IStringFilter filter)
Returns a new array that contains all strings of the given array that do NOT match the specified filter.

Parameters:
strings - The string array to copy from (must not be null)
filter - The filter that determines which strings to copy (if null an empty array will be returned)

copy

public java.util.Collection<java.lang.String> copy(java.util.Collection<java.lang.String> strings,
                                                   org.pfsw.bif.text.IStringFilter filter)
Returns a new array that contains all strings of the given array that matched the specified filter.

Parameters:
strings - A collection of strings to copy from (must not be null)
filter - The filter that determines which strings to copy (if null an empty collection will be returned)

copyWithout

public java.util.Collection<java.lang.String> copyWithout(java.util.Collection<java.lang.String> strings,
                                                          org.pfsw.bif.text.IStringFilter filter)
Returns a new collection that contains all strings of the given collection that do NOT match the specified filter.

Parameters:
strings - A collection of strings to copy from (must not be null)
filter - The filter that determines which strings to copy (if null an empty collection will be returned)

cutTail

public java.lang.String cutTail(java.lang.String text,
                                java.lang.String separator)
Returns the portion of the given string that comes before the last occurrence 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:
prefix( String, String ), suffix( String, String ), cutHead( String, String ), startingFrom( String, String ), upTo( String, String )

cutHead

public java.lang.String cutHead(java.lang.String text,
                                java.lang.String separator)
Returns the portion of the given string that comes after the last occurrence 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:
prefix( String, String ), cutTail( String, String ), suffix( String, String ), startingFrom( String, String ), upTo( String, String )

splitNameValue

public java.lang.String[] splitNameValue(java.lang.String str,
                                         java.lang.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 occurrence 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

splitStringPair

public org.pfsw.bif.text.IStringPair splitStringPair(java.lang.String str,
                                                     java.lang.String separator)
Returns a string pair where the first is the string before the first occurrence of the defined separator and the second string is everything after that separator. 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

prefix

public java.lang.String prefix(java.lang.String str,
                               java.lang.String separator)
Returns the substring of the given string that comes before the first occurrence 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
See Also:
suffix( String, String ), cutTail( String, String ), cutHead( String, String ), startingFrom( String, String ), upTo( String, String )

suffix

public java.lang.String suffix(java.lang.String str,
                               java.lang.String separator)
Returns the substring of the given string that comes after the first occurrence 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
See Also:
prefix( String, String ), cutTail( String, String ), cutHead( String, String ), startingFrom( String, String ), upTo( String, String )

upTo

public java.lang.String upTo(java.lang.String str,
                             java.lang.String separator)
Returns the substring of the given string that comes before the first occurrence 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
See Also:
prefix( String, String ), cutTail( String, String ), cutHead( String, String ), startingFrom( String, String ), suffix( String, String )

startingFrom

public java.lang.String startingFrom(java.lang.String str,
                                     java.lang.String separator)
Returns the substring of the given string that comes after the first occurrence 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
See Also:
prefix( String, String ), cutTail( String, String ), cutHead( String, String ), suffix( String, String ), upTo( String, String )

trim

public java.lang.String trim(java.lang.String str,
                             java.lang.String... unwanted)
Returns a new string where all leading and trailing unwanted substrings are removed. If the given string is null then null will be returned. If the given array of unwanted substrings is empty the string will be stripped off its leading and trailing white spaces, see String.trim().


trimOnce

public java.lang.String trimOnce(java.lang.String str,
                                 java.lang.String... unwanted)
Returns a new string where the first leading and first trailing unwanted substrings are removed. This method removes only ONE leading and ONE trailing unwanted substring. For more see trim(String, String...). If the given string is null then null will be returned. If the given array of unwanted substrings is empty the string will be stripped off its leading and trailing white spaces, see String.trim().


reverse

public java.lang.String reverse(java.lang.String str)
Returns a string that contains all characters of the given string in reverse order.


toMap

public java.util.Map<java.lang.String,java.lang.String> toMap(java.lang.String str,
                                                              java.lang.String elementSeparator,
                                                              java.lang.String keyValueSeparator,
                                                              java.util.Map<java.lang.String,java.lang.String> 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 white spaces 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

asMap

public java.util.Map<java.lang.String,java.lang.String> asMap(java.lang.String[][] stringPairArray)
Converts the given array of string arrays to a map. The string arrays must all contain exactly 2 string elements.
For any wrong input data NullPointerException or ArrayIndexOutOfBoundsException or IllegalArgumentException or other runtime exceptions will be thrown.

Parameters:
stringPairArray - An array of string arrays with two strings each.
Returns:
The map containing all the string pairs from the given array.

asMap

public java.util.Map<java.lang.String,java.lang.String> asMap(java.lang.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 white spaces of keys and values will be removed!

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

asMap

public java.util.Map<java.lang.String,java.lang.String> asMap(java.lang.String str,
                                                              java.lang.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 white spaces 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

asMap

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

Be aware that all leading and trailing white spaces 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

toMap

public java.util.Map<java.lang.String,java.lang.String> toMap(java.lang.String str,
                                                              java.lang.String elementSeparator,
                                                              java.util.Map<java.lang.String,java.lang.String> 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 white spaces 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.

toMap

public java.util.Map<java.lang.String,java.lang.String> toMap(java.lang.String str,
                                                              java.util.Map<java.lang.String,java.lang.String> 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 white spaces 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

asProperties

public java.util.Properties asProperties(java.lang.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 white spaces of keys and values will be removed!

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

toProperties

public java.util.Properties toProperties(java.lang.String str,
                                         java.util.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 white spaces 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

copyMapToProperties

public void copyMapToProperties(java.util.Map<java.lang.String,java.lang.String> map,
                                java.util.Properties properties)
Copies all entries from the given map to the given properties object.

Parameters:
map - The map to copy from (must not be null).
properties - The properties to copy to (must not be null).

asList

public java.util.List<java.lang.String> asList(java.lang.String... strings)
Returns a new List initialized with the given strings. In contrary to Arrays.asList(Object...) this method creates a list mutable list.

Parameters:
strings - The strings to be added to the list (must not be null).
Returns:
The new list.

asReadOnlyNamedValues

public org.pfsw.bif.facet.IReadOnlyNamedValues<java.lang.String> asReadOnlyNamedValues(java.util.Properties properties)
Converts the given properties to an object that conforms to interface IReadOnlyNamedValues.

Parameters:
properties - The properties to be adapted to interface IReadOnlyNamedValues (must not be null).

asReadOnlyNamedValues

public <T> org.pfsw.bif.facet.IReadOnlyNamedValues<T> asReadOnlyNamedValues(java.util.Map<java.lang.String,T> map)
Converts the given map to an object that conforms to interface IReadOnlyNamedValues.

Parameters:
map - The map to be adapted to interface IReadOnlyNamedValues (must not be null).

asConfigSettings

public org.pfsw.bif.configuration.IConfigSettings asConfigSettings(java.util.Map<java.lang.String,java.lang.String> map)
Converts the given map to an object that conforms to interface IConfigSettings.

Parameters:
map - The map to be adapted to interface IConfigSettings (must not be null).

asConfigSettings

public org.pfsw.bif.configuration.IConfigSettings asConfigSettings(java.util.Properties properties)
Converts the given properties to an object that conforms to interface IConfigSettings.

Parameters:
properties - The properties to be adapted to interface IConfigSettings (must not be null).

asConfigSettings

public org.pfsw.bif.configuration.IConfigSettings asConfigSettings(java.lang.String str)
Returns a new IConfigSettings 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 white spaces of keys and values will be removed!

Parameters:
str - The string with the list of key-value pairs (must not be null).

asConfigSettings

public org.pfsw.bif.configuration.IConfigSettings asConfigSettings(java.lang.String str,
                                                                   java.lang.String elementSeparator,
                                                                   java.lang.String keyValueSeparator)
Returns a new IConfigSettings object that contains all key-value pairs of the specified string.

Be aware that all leading and trailing white spaces 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.

isAnyNullOrBlank

public boolean isAnyNullOrBlank(java.lang.String... strings)
Returns true if any one of the given strings is null or blank. Blanks means "" as well as strings filled with white spaces only (e.g. "\t ").


isNoneNullOrBlank

public boolean isNoneNullOrBlank(java.lang.String... strings)
Returns true if none of the given strings is null or blank. Blanks means "" as well as strings filled with white spaces only (e.g. "\t ").


isNullOrEmpty

public boolean isNullOrEmpty(java.lang.String[] strings)
Returns true if the given string array is null or empty

Parameters:
strings - The string array to check

isNullOrEmpty

public boolean isNullOrEmpty(java.lang.String str)
Returns true if the given string is null or empty

Parameters:
str - The string to check

isNullOrBlank

public boolean isNullOrBlank(java.lang.String str)
Returns true if the given string is null or empty or consists of whitespace characters only.

Parameters:
str - The string to check

notNullOrEmpty

public boolean notNullOrEmpty(java.lang.String[] strings)
Returns true if the given string array is not null and not empty

Parameters:
strings - The string array to check

notNullOrEmpty

public boolean notNullOrEmpty(java.lang.String str)
Returns true if the given string is not null and not empty

Parameters:
str - The string to check

notNullOrBlank

public boolean notNullOrBlank(java.lang.String str)
Returns true if the given string is not null and not empty and does not consist of whitespace characters only.

Parameters:
str - The string to check

asString

public java.lang.String asString(char ch)
Returns a new string that contains only the given character.

Parameters:
ch - The character to build the string from

areEqual

public boolean areEqual(java.lang.String[] strings1,
                        java.lang.String[] strings2)
Returns true if all elements of the first given array are in the second given array and the length of both arrays are equal.


areEqualIgnoreCase

public boolean areEqualIgnoreCase(java.lang.String[] strings1,
                                  java.lang.String[] strings2)
Returns true if all elements of the first given array are in the second given array and the length of both arrays are equal. The comparison of the strings will be case-insensitive.


setFileNameExtension

public java.lang.String setFileNameExtension(java.lang.String filename,
                                             java.lang.String extension,
                                             boolean replace)
Sets the given extension as filename extension to the given filename. If the filename already has an extension it depends on parameter replace whether or not it will be replaced by the new one. If the given extension is null or empty the filename will be returned unchanged.

Parameters:
filename - The filename to which the extension must be appended
extension - The extension to append without any leading dot (e.g. "pdf")
replace - If true any existing extension will be replaced
Returns:
A filename with the given extension at the end

toUpperCase

public void toUpperCase(java.lang.String[] strings)
Modifies the strings in the given array to be all upper case.


toLowerCase

public void toLowerCase(java.lang.String[] strings)
Modifies the strings in the given array to be all lower case.


copyUpperCase

public java.lang.String[] copyUpperCase(java.lang.String[] strings)
Returns a copy of the given string array where all elements are converted to upper case. This method does not modify the given input array.


copyLowerCase

public java.lang.String[] copyLowerCase(java.lang.String[] strings)
Returns a copy of the given string array where all elements are converted to lower case. This method does not modify the given input array.


getPackageName

public java.lang.String getPackageName(java.lang.String qualifiedClassName)
Returns the package name of the given full qualified class name.
Example: getPackageName("org.pf.text.StringUtil") -> "org.pf.text"

Parameters:
qualifiedClassName - The full qualified class name (must not be null)

getUnqualifiedClassName

public java.lang.String getUnqualifiedClassName(java.lang.String qualifiedClassName)
Returns the class name without the package name.
Example: getUnqualifiedClassName("org.pf.text.StringUtil") -> "StringUtil"

Parameters:
qualifiedClassName - The full qualified class name (must not be null)

translate

public java.lang.String translate(java.lang.String text,
                                  java.lang.String replacementChars,
                                  java.lang.String charsToReplace)
Returns a string of the same length as the given text parameter. This method operates on each character of text as follows: If a character in text is found in charsToReplace, the character in replacementChars that corresponds to that in charsToReplace is copied to the result; otherwise, the character in text is copied directly to the result. If charsToReplace contains duplicates, the leftmost occurrence is used. replacementChars is padded with blanks, or truncated, on the right to match the length of charsToReplace.

Parameters:
text - to be searched for possible translation of its characters. (must not be null)
replacementChars - containing the translation values of characters. (must not be null)
charsToReplace - containing the characters that are to be translated. (must not be null)
Throws:
java.lang.NullPointerException - if any of the three parameters is null

isTrue

public boolean isTrue(java.lang.String string)
Returns true if the given string represents a true setting. That is, its value is one of strings "true", "on", "yes", "1". In any other case (also for null) it returns false.


isFalse

public boolean isFalse(java.lang.String string)
Returns true if the given string represents a false setting. That is, its value is one of strings "false", "off", "no", "0". In any other case (also for null) it returns false.


isInteger

public boolean isInteger(java.lang.String value)
Returns true if the given value is a string containing only digits and optionally a leading minus ('-') and is in the range of a valid integer Integer.MIN_VALUE <= value <= Integer.MAX_VALUE.


isPositiveInteger

public boolean isPositiveInteger(java.lang.String value)
Returns true if the given string represents a valid positive integer.


isZeroOrPositiveInteger

public boolean isZeroOrPositiveInteger(java.lang.String value)
Returns true if the given string represents a valid positive or zero integer.


isLong

public boolean isLong(java.lang.String value)
Returns true if the given value is a string containing only digits and optionally a leading minus ('-') and is in the range of a valid long - Long.MIN_VALUE <= value <= Long.MAX_VALUE.


isPositiveLong

public boolean isPositiveLong(java.lang.String value)
Returns true if the given string represents a valid positive long.


isZeroOrPositiveLong

public boolean isZeroOrPositiveLong(java.lang.String value)
Returns true if the given string represents a valid positive or zero long.


asInteger

public int asInteger(java.lang.String value,
                     int defaultValue)
Converts the given string to an int or returns the given default value if the string does not represent a valid integer value. All leading and trailing whites paces are removed before the given string gets converted. If the string is null the defaultValue will be returned.


asLong

public long asLong(java.lang.String value,
                   long defaultValue)
Converts the given string to a long or returns the given default value if the string does not represent a valid long value. All leading and trailing white spaces are removed before the given string gets converted. If the string is null the defaultValue will be returned.


hexToBytes

public byte[] hexToBytes(java.lang.String hex)
Converts the given hex string to a byte array.

Parameters:
hex - The hex data to convert (must not be null and must have an even length).

hexToBytes

public byte[] hexToBytes(java.lang.String hex,
                         java.lang.String separator)
Converts the given hex string to a byte array.

Parameters:
separator - An optional separator used between the hex elements.
hex - The hex data to convert (must not be null and must have an even length).

bytesToHex

public java.lang.String bytesToHex(byte... bytes)
Converts the given bytes to a string with a hex representation for each byte.

Parameters:
bytes - The bytes to convert to a hex string.
Returns:
A hex string representation of the given bytes or null if the bytes were null.

bytesToHex

public java.lang.String bytesToHex(java.lang.String separator,
                                   byte... bytes)
Converts the given bytes to a string with a hex representation for each byte. If the given separator is not null it will be but between the hex values.

Parameters:
separator - An optional separator.
bytes - The bytes to convert to a hex string.
Returns:
A hex string representation of the given bytes or null if the bytes were null.

withLeadingChar

public java.lang.String withLeadingChar(java.lang.String string,
                                        char ch)
Returns the given string and ensures that it starts with the given character. So if the given string does not yet start with the character it will be prepended.

Parameters:
string - The string that should have the leading character (must not be null).
ch - The character to be at the start of the string.

withTrailingChar

public java.lang.String withTrailingChar(java.lang.String string,
                                         char ch)
Returns the given string and ensures that it ends with the given character. So if the given string does not yet end with the character it will be appended.

Parameters:
string - The string that should have the trailing character (must not be null).
ch - The character to be at the end of the string.

withoutLeadingChar

public java.lang.String withoutLeadingChar(java.lang.String string,
                                           char ch)
Returns the given string and ensures that it does not start with the given character. So if the given string starts with the character it will be removed - repeated as longs as the remaining string still starts with the character.

Parameters:
string - The string that should not have the leading character (must not be null).
ch - The character to be removed.

withoutTrailingChar

public java.lang.String withoutTrailingChar(java.lang.String string,
                                            char ch)
Returns the given string and ensures that it does not end with the given character. So if the given string ends with the character it will be removed - repeated as longs as the remaining string still ends with the character.

Parameters:
string - The string that should not have the trailing character (must not be null).
ch - The character to be removed.

truncate

public java.lang.String truncate(java.lang.String string,
                                 int len)
Returns a string that is shortened (chopped off the end) to the specified length. If the given string is null then null will be returned. If the specified length is negative or zero then an empty string will be returned. If the string is shorter that the given length then the whole string will be returned unchanged.

Parameters:
string - The string to be truncated.
len - The maximum length of the string to be returned.
Returns:
Either null or a string with length shorter or equal to the specified len.

removeAllChars

public java.lang.String removeAllChars(java.lang.String string,
                                       java.lang.String charsToRemove)
Returns a copy of the given string where all characters have been removed that also occurred in the second string. If the given string is null then null will be returned. If the charsToBeRemoved is null or empty then the string will be returned unchanged.

Parameters:
string - The string to remove characters from.
charsToRemove - A string containing all characters that must be removed.
Returns:
null or a copy of the given string with the specified characters removed.

removeChar

public java.lang.String removeChar(java.lang.String string,
                                   char charToRemove)
Returns a copy of the given string where the specified character has been removed.

Parameters:
string - The string to remove the character from.
charToRemove - The character to be removed from the string.
Returns:
null or a copy of the given string with the specified character removed.

trimSeparator

protected java.lang.String trimSeparator(java.lang.String input,
                                         java.lang.String separator)
Cuts off all leading and trailing occurrences of separator in text.


parts

protected java.lang.String[] parts(java.lang.String text,
                                   java.lang.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 split-up into substrings.
delimiters - All characters that should be recognized as a separator or substrings
all - If true, empty elements will be returned, otherwise they are skipped
Returns:
An array of substrings of the given text

collectParts

protected void collectParts(java.util.List<java.lang.String> list,
                            java.util.StringTokenizer tokenizer)

collectParts

protected void collectParts(java.util.List<java.lang.String> list,
                            java.util.StringTokenizer tokenizer,
                            java.lang.String delimiter)

substrings

protected java.lang.String[] substrings(java.lang.String text,
                                        java.lang.String separator,
                                        boolean all)
Returns the given text split up into an array of strings, at the occurrences 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:
parts(String, String, boolean)

padCh

protected java.lang.String padCh(java.lang.String str,
                                 int len,
                                 char ch,
                                 boolean left)

padCh

protected void padCh(java.lang.StringBuffer buffer,
                     java.lang.String str,
                     int len,
                     char ch,
                     boolean left)

prefix

protected java.lang.String prefix(java.lang.String str,
                                  java.lang.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

suffix

protected java.lang.String suffix(java.lang.String str,
                                  java.lang.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

removeFromStringArray

protected java.lang.String[] removeFromStringArray(java.lang.String[] strings,
                                                   java.lang.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.


quotedParts

protected java.lang.String[] quotedParts(java.lang.String str,
                                         java.lang.String separators,
                                         char[] quoteChars,
                                         boolean all)
Quotes are removed from all parts If str is null an empty array will be returned!

Parameters:
all - If true, empty elements will be returned, otherwise they are skipped

quotedParts

protected java.lang.String[] quotedParts(java.lang.String str,
                                         java.lang.String separators,
                                         org.pfsw.bif.text.IStringPair[] quotePairs,
                                         boolean all)

findInString1

protected org.pfsw.bif.text.IStringPair findInString1(org.pfsw.bif.text.IStringPair[] stringPairs,
                                                      char ch,
                                                      boolean ignoreCase)
Returns the string pair of the specified array that's first string starts with the specified character.

Parameters:
stringPairs - An array of string pairs
ch - The character to be looked for to be the initial character of string one of a string pair.
ignoreCase - If comparison should be case-insensitive
Returns:
The found string pair or null if not found

copyStrings

protected <T extends java.util.Collection<java.lang.String>> T copyStrings(java.lang.Class<T> collClass,
                                                                           java.lang.String[] strings,
                                                                           org.pfsw.bif.text.IStringFilter filter,
                                                                           boolean allMatching)

equals

protected boolean equals(java.lang.String[] strings1,
                         java.lang.String[] strings2,
                         boolean ignoreCase)
Returns true if all elements of the first array are in the second array and the length of both arrays are equal.


addAll

protected void addAll(java.util.Collection<java.lang.String> collection,
                      java.lang.String[] strings,
                      boolean justNew)
Adds all given strings to the specified collection. All null values in the string array will be skipped.

Parameters:
collection - The collection to which the strings are added.
strings - The strings to add to the collection.
justNew - If true only new strings are added to the collection.

trimLoop

protected java.lang.String trimLoop(int maxLoop,
                                    java.lang.String str,
                                    java.lang.String[] unwanted)
Returns a new string where all leading and trailing unwanted substrings are removed. If the given string is null then null will be returned. If the given array of unwanted substrings is empty the string will be stripped off its leading and trailing white spaces, see String.trim().


removeCharsFromString

protected java.lang.String removeCharsFromString(java.lang.String string,
                                                 java.lang.String charsToRemove)