com.webmethods.caf.common
Class StringTools

java.lang.Object
  extended by com.webmethods.caf.common.StringTools

public class StringTools
extends Object

Various string utility functions and operations


Field Summary
static String BOOLEAN_FALSE
          String variable 'false'
static String BOOLEAN_NO
          String variable 'on'
static String BOOLEAN_OFF
          String variable 'off'
static String BOOLEAN_ON
          String variable 'on'
static String BOOLEAN_TRUE
          String variable 'true'
static String BOOLEAN_YES
          String variable 'yes'
static char CHR_BACK_SLASH
          Standard char back slash
static char CHR_DOT
          Standard char dot
static char CHR_FORWARD_SLASH
          Standard char forward slash
static char CHR_TAB
          Standard char tab
static String LINE_SEPARATOR
          Cached line separator to concatenate strings
static int NO_ACTION
          Values used in StringTools.truncateArray(java.lang.Object[], int[]) to specify that no truncation should be made
static String STR_AND
          Standard string ampersand
static String STR_COMMA
          Standard string comma
static String STR_EQUALS
          Standard string equals
static String STR_FAILED
          Standard string for failed
static String STR_QUESTION
          Standard string question mark
static String STR_SEMICOLON
          Standard string semicolon
static String STR_SPACE
          Standard string space
static String STR_SUCCESSFUL
          Standard string for successful
static String SYSTEM_ENCODING
          Standard system encoding (UTF-8)
 
Constructor Summary
StringTools()
           
 
Method Summary
static String capitalizeName(String name)
          Capitalizes name string
static String change(String s, String oldp, String newp)
          Changes occurrences of a specified pattern to a replacement string.
static String change(String s, String oldp, String newp, boolean ignoreCase)
          Changes occurrences of a specified pattern to a replacement string.
static String change(String s, String oldp, String newp, int start)
          Changes occurrences of a specified pattern to a replacement string.
static String change(String s, String oldp, String newp, int start, boolean ignoreCase)
          Changes occurrences of a specified pattern to a replacement string.
static String change(String s, String oldp, String newp, int start, int maxChanges)
          Changes occurrences of a specified pattern to a replacement string.
static String change(String s, String oldp, String newp, int start, int maxChanges, boolean ignoreCase)
          Changes occurrences of a specified pattern to a replacement string.
static String charStr(char character, int count)
          Creates a string consisting of the given character
static String concat(String s1, String s2)
          Fast 2 string concatenation using StringBuffer.
static String concat(String s1, String s2, String s3)
          Fast 3 strings concatenation using StringBuffer
static String concat(String s1, String s2, String s3, String s4)
          Fast 4 string concatenation using StringBuffer
static Set csvToSet(String csvLine)
          Convert comma-separated line to Set of strings.
static String ensureLeading(String value, String prefix)
          Ensures that string starts with specified symbol
static String ensureTrailing(String value, String suffix)
          Ensures that string ends with specified symbol
static boolean equals(char c1, char c2, boolean ignoreCase)
          Checks if two characters are equal.
static boolean equals(String s1, String s2, boolean ignoreCase)
          Checks if two strings are equal.
static long fastParseLong(String str)
          Fast implementation of Long.parseLong(java.lang.String, int) It assumes that it parses decimal radix number It doesn't not check Long constraints It doesn't handle unicode string
static String[] getArrayFromCsvString(String csv)
          Parses comma (",") delimited string to string array.
static boolean[] getBooleanArrayFromCsv(String data)
          Parses csv string and returns array of boolean as a result of parsing.
static byte[] getByteArrayFromCsv(String data)
          Parses csv string and returns array of boolean as a result of parsing.
static String getCsvFromList(List list)
          Constructs string from list of values
static ArrayList getDelimitedList(String value, String delims)
          Get ArrayList of tokens from delimited original string
static ArrayList getDelimitedList(String value, String delims, boolean includeDelim)
          Get ArrayList of tokens from delimited original string
static double[] getDoubleArrayFromCsv(String data)
          Parses csv string and returns array of double as a result of parsing.
static String getFirstSegment(String value, String separator)
          Get first string segment separated by passed separator
static float[] getFloatArrayFromCsv(String data)
          Parses csv string and returns array of float as a result of parsing.
static int[] getIntArrayFromCsv(String data)
          Parses csv string and returns array of ints as a result of parsing.
static int[] getIntArrayFromDelimitedString(String data, String delimiter)
          Parses string with the specified delimiter and returns array of ints as a result of parsing.
static String getLastSegment(String value, String separator)
          Get last string segment separated by passed separator
static String getLastSegment(String value, String separator, boolean includeSeperator)
          Get last string segment separated by passed separator
static List getListFromCsv(String value)
          Parses comma delimited string to List of String instances
static List getListFromCsv(String value, boolean allowDups)
          Parses comma delimited string to List of String instances
static List getListFromDelimitedString(String data, String delimiter)
          Parses data with the specified delimiter
static long[] getLongArrayFromCsv(String data)
          Parses csv string and returns array of long as a result of parsing.
static List getLongsListFromCsv(String value)
          Parses comma delimited string to List of Long instances
static String getSegment(String str, String separator, int segment)
          Returns the segment, null if not found, first segment is segment 0
static short[] getShortArrayFromCsv(String data)
          Parses csv string and returns array of short as a result of parsing.
static String getStackTrace(Throwable t)
          Utility function to recieve exception stack trace as a string
static String hasSuccess(Object instance)
          Checks instance to be not null, and returns either success or failed string
static String humanizeName(String name)
          Converts identifiers like "myJavaCompliantName123" into "My Java Compliant Name 123"
static int indexOf(String s, String c, int start, boolean ignoreCase)
          Returns the index of the first ocurrence of the specified string.
static String intToHex(int value, boolean padding)
          Convert integer to hex, optionally padding with 0s
static boolean isEmpty(String str)
          Verifies whether passed string is empty or not.
static boolean isEmpty(String s1, String s2)
          Checks whether one of the 2 strings is empty
static boolean isFloat(String value)
          Checks whether specified value convertable to float
static boolean isFormatCharsOnly(String value)
          Verifies that string contains only formatting characters
static String loadStringfromStream(InputStream input)
          Loads and return string from an InputStream
static String lowerCaseFirstChar(String s)
          Lower cases first character of a string
static boolean notEmpty(String str)
          Checks that string is not empty.
static boolean notEmpty(String s1, String s2)
          Checks that 2 strings are not empty
static boolean notNulls(String value1, String value2)
          Checks that 2 strings are not nulls
static int occurrencesOf(String s, int ch, int start)
          counts characters in string, case sensitive
static int occurrencesOf(String s, String c, int start, boolean ignoreCase)
          Returns the number of occurrences of the specified string.
static boolean parseBooleanDef(String s, boolean def)
          Parses string and returns converted boolean value.
static int parseIntDef(String s, int def)
          Parses string and returns converted integer value.
static long parseLongDef(String s, long def)
          Parses string and returns converted boolean value.
static void parseParameters(String url, int start, Map parameters)
          Adds parameters from url query string to specified map.
static String removeChars(String orig, String chars)
          Replaces all chars with the replacement char
static String removeCR(String s)
          Replaces all CR(\n) symbols in string via " "(space) character
static String replaceChars(String orig, String chars, char replace)
          Replaces all chars with the replacement char
static String replaceChars(String orig, String chars, String replace)
          Replaces all chars with the replacement char
static String replaceHiAsciChars(String orig, char replacementChar)
          Strips out the hi ascii chars (>127) and replaces them with a replacement char
static String replaceParams(String source, String[] params)
          Replace placeholders, or parameters, in a string that are of the format %[number].
static String smallIntToHex(int value, boolean padding)
          Convert small int to hex, optionally padding with 0s
static String stripFirstSegment(String value, String separator)
          Strips string first segment, defined by separator and returns stripped string
static String stripLastSegment(String value, String separator)
          Strips string last segment, defined by separator and returns stripped string
static String substituteBatch(String source, Map valuesMap)
          Replace all patterns in the string with the ones given in the given HashMap instance.
static String tabStr(int count)
          Return string containing the specified quantity of '\t' character
static boolean toBoolean(String value)
          Converts string to boolean.
static String toCsv(boolean[] array)
          Convert array of boolean to comma-separated string
static String toCsv(byte[] array)
          Convert array of byte to comma-separated string
static String toCsv(double[] array)
          Convert array of double to comma-separated string
static String toCsv(float[] array)
          Convert array of float to comma-separated string
static String toCsv(int[] array)
          Convert array of int to comma-separated string
static String toCsv(List strings)
          Convert List of strings to comma-separated string
static String toCsv(long[] array)
          Convert array of long to comma-separated string
static String toCsv(Object[] array)
          Convert array of objects to comma-separated string using the toString() method to retrieve the value for each entry.
static String toCsv(short[] array)
          Convert array of short to comma-separated string
static String toCsv(String[] array)
          Convert array of strings to comma-separated string
static String toString(Collection collection, String lineSeperator)
          Convert Collection of object to single string for debugging purposes
static String toString(InputStream stream)
          Loads stream contents to the stream
static String toString(Map map)
          Prints out a map with key value pairs combined with '=' separated by ',' and surrounded by { and }
static String toString(Object object)
          ToString object
static String toString(Object[] array)
          To string an array of objects separated by ',' and surrounded by '[' and ']'.
static String toString(String[] array)
          Convert array to single string presentation for debugging purposes
static String toString(String[] array, String lineSeparator)
          Convert array of strings to single string presentation for debug purposes
static String trimString(String s, String charsToTrim)
          Trims specified characters from the beginning and end of the string
static String truncate(String value, int maxLength)
          Truncates input string to the specified size
static void truncateArray(Object[] values, int[] actions)
          Truncate array of strings using specified list of lengths (actions).
static String unwrap(String value, String prefix, String postfix)
          Unwraps string using selected prefix and postfix
static String upperCaseFirstChar(String s)
          Capilizes first character of a string
static String wrap(String value, String prefix, String postfix)
          Wrap string value with prefix and postfix.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STR_SUCCESSFUL

public static final String STR_SUCCESSFUL
Standard string for successful

See Also:
Constant Field Values

STR_FAILED

public static final String STR_FAILED
Standard string for failed

See Also:
Constant Field Values

SYSTEM_ENCODING

public static final String SYSTEM_ENCODING
Standard system encoding (UTF-8)

See Also:
Constant Field Values

BOOLEAN_ON

public static final String BOOLEAN_ON
String variable 'on'

See Also:
Constant Field Values

BOOLEAN_OFF

public static final String BOOLEAN_OFF
String variable 'off'

See Also:
Constant Field Values

BOOLEAN_YES

public static final String BOOLEAN_YES
String variable 'yes'

See Also:
Constant Field Values

BOOLEAN_NO

public static final String BOOLEAN_NO
String variable 'on'

See Also:
Constant Field Values

BOOLEAN_FALSE

public static final String BOOLEAN_FALSE
String variable 'false'

See Also:
Constant Field Values

BOOLEAN_TRUE

public static final String BOOLEAN_TRUE
String variable 'true'

See Also:
Constant Field Values

STR_COMMA

public static final String STR_COMMA
Standard string comma

See Also:
Constant Field Values

STR_SEMICOLON

public static final String STR_SEMICOLON
Standard string semicolon

See Also:
Constant Field Values

STR_QUESTION

public static final String STR_QUESTION
Standard string question mark

See Also:
Constant Field Values

STR_EQUALS

public static final String STR_EQUALS
Standard string equals

See Also:
Constant Field Values

STR_AND

public static final String STR_AND
Standard string ampersand

See Also:
Constant Field Values

STR_SPACE

public static final String STR_SPACE
Standard string space

See Also:
Constant Field Values

CHR_DOT

public static final char CHR_DOT
Standard char dot

See Also:
Constant Field Values

CHR_FORWARD_SLASH

public static final char CHR_FORWARD_SLASH
Standard char forward slash

See Also:
Constant Field Values

CHR_BACK_SLASH

public static final char CHR_BACK_SLASH
Standard char back slash

See Also:
Constant Field Values

CHR_TAB

public static final char CHR_TAB
Standard char tab

See Also:
Constant Field Values

LINE_SEPARATOR

public static String LINE_SEPARATOR
Cached line separator to concatenate strings


NO_ACTION

public static final int NO_ACTION
Values used in StringTools.truncateArray(java.lang.Object[], int[]) to specify that no truncation should be made

See Also:
Constant Field Values
Constructor Detail

StringTools

public StringTools()
Method Detail

hasSuccess

public static String hasSuccess(Object instance)
Checks instance to be not null, and returns either success or failed string

Parameters:
instance - object instance to check

getListFromDelimitedString

public static List getListFromDelimitedString(String data,
                                              String delimiter)
Parses data with the specified delimiter

Parameters:
data - Original data to parse
delimiter - Delimiter to use for data parsing
Returns:
LinkedList of tokens parsed, delimiters are not returned

getIntArrayFromDelimitedString

public static int[] getIntArrayFromDelimitedString(String data,
                                                   String delimiter)
Parses string with the specified delimiter and returns array of ints as a result of parsing. Of course this appliable only when you do know that string contains integers

Parameters:
data - Original data to parse
delimiter - Delimiter to use for data parsing
Returns:
array of integers

getArrayFromCsvString

public static String[] getArrayFromCsvString(String csv)
Parses comma (",") delimited string to string array. No quotes (") supported

Parameters:
csv - Comma separated values
Returns:
array of String extracted from line

getListFromCsv

public static List getListFromCsv(String value)
Parses comma delimited string to List of String instances

Parameters:
value - Comma delimited string to parse
Returns:
List of Strings extractecd from comma-separated line

getListFromCsv

public static List getListFromCsv(String value,
                                  boolean allowDups)
Parses comma delimited string to List of String instances

Parameters:
value - Comma delimited string to parse
allowDups - true to allow duplicates within the list
Returns:
List of Strings extractecd from comma-separated line

getLongsListFromCsv

public static List getLongsListFromCsv(String value)
Parses comma delimited string to List of Long instances

Parameters:
value - Comma delimited string to parse
Returns:
List of Longs

getCsvFromList

public static String getCsvFromList(List list)
Constructs string from list of values

Parameters:
list - source list of values
Returns:
Comma-separated string as a result of values concatenation

getFirstSegment

public static String getFirstSegment(String value,
                                     String separator)
Get first string segment separated by passed separator

Parameters:
value - initial string
separator - is separator string
Returns:
stripped segment or null

getLastSegment

public static String getLastSegment(String value,
                                    String separator)
Get last string segment separated by passed separator

Parameters:
value - initial string
separator - is separator string
Returns:
stripped segment or null

getLastSegment

public static String getLastSegment(String value,
                                    String separator,
                                    boolean includeSeperator)
Get last string segment separated by passed separator

Parameters:
value - initial string
separator - is separator string
includeSeperator - true to include the seperator character in the result, false otherwise
Returns:
stripped segment or null

getSegment

public static String getSegment(String str,
                                String separator,
                                int segment)
Returns the segment, null if not found, first segment is segment 0

Parameters:
str - Source string
separator - Parsing separator
segment - String segment number
Returns:
Specified segment of the string extracted

stripFirstSegment

public static String stripFirstSegment(String value,
                                       String separator)
Strips string first segment, defined by separator and returns stripped string

Parameters:
value - initial string
separator - is separator string
Returns:
stripped value string

stripLastSegment

public static String stripLastSegment(String value,
                                      String separator)
Strips string last segment, defined by separator and returns stripped string

Parameters:
value - initial string
separator - is separator string
Returns:
stripped value string

isEmpty

public static boolean isEmpty(String str)
Verifies whether passed string is empty or not.

Parameters:
str - Source string to analyze
Returns:
True, if string is empty, False - otherwise

notEmpty

public static boolean notEmpty(String str)
Checks that string is not empty. Can be opposed to usage of StringTools.isEmpty(java.lang.String)

Parameters:
str - String value to analyze
Returns:
true, if string is empty, false otherwise
See Also:
StringTools.isEmpty(java.lang.String)

removeCR

public static String removeCR(String s)
Replaces all CR(\n) symbols in string via " "(space) character

Parameters:
s - Source string
Returns:
String with all CR(\n) chars replaced with space(" ")

parseIntDef

public static int parseIntDef(String s,
                              int def)
Parses string and returns converted integer value. If parsing failes the default value is taken.

Parameters:
s - string to parse
def - default int value, if string is unparsable
Returns:
int as a result string to int conversion

parseBooleanDef

public static boolean parseBooleanDef(String s,
                                      boolean def)
Parses string and returns converted boolean value. If parsing fails the default value is taken.

Parameters:
s - String to parse
def - Default boolean value
Returns:
boolean value that is parsed from the string

parseLongDef

public static long parseLongDef(String s,
                                long def)
Parses string and returns converted boolean value. If parsing fails the default value is taken.

Parameters:
s - String to parse
def - Default boolean value
Returns:
boolean value that is parsed from the string

parseParameters

public static void parseParameters(String url,
                                   int start,
                                   Map parameters)
Adds parameters from url query string to specified map.

Parameters:
url - Url with query string.
start - Index at which to start parse (ie url.indexOf('?')).
parameters - Map into which to put parsed param name=value pairs.

change

public static String change(String s,
                            String oldp,
                            String newp,
                            int start,
                            int maxChanges,
                            boolean ignoreCase)
Changes occurrences of a specified pattern to a replacement string. The maximum number of changes and a starting position can be specified. You can specify that case should be ignored.

Parameters:
s - the input string
oldp - the pattern to be replaced
newp - the replacement string
start - the starting position for the search
maxChanges - the maximum number of changes
ignoreCase - if true case is ignored when comparing characters
Returns:
a string with the specified patterns changed.

change

public static String change(String s,
                            String oldp,
                            String newp,
                            int start,
                            boolean ignoreCase)
Changes occurrences of a specified pattern to a replacement string. The starting position can be specified. You can specify that case should be ignored.

Parameters:
s - the input string
oldp - the pattern to be replaced
newp - the replacement string
start - the starting position for the search
ignoreCase - if true case is ignored when comparing characters
Returns:
a string with the specified patterns changed.

change

public static String change(String s,
                            String oldp,
                            String newp,
                            int start,
                            int maxChanges)
Changes occurrences of a specified pattern to a replacement string. The maximum number of changes and a starting position can be specified.

Parameters:
s - the input string
oldp - the pattern to be replaced
newp - the replacement string
start - the starting position for the search
maxChanges - the maximum number of changes
Returns:
a string with the specified patterns changed.

change

public static String change(String s,
                            String oldp,
                            String newp,
                            int start)
Changes occurrences of a specified pattern to a replacement string. A starting position can be specified.

Parameters:
s - the input string
oldp - the pattern to be replaced
newp - the replacement string
start - the starting position for the search
Returns:
a string with the specified patterns changed.

change

public static String change(String s,
                            String oldp,
                            String newp,
                            boolean ignoreCase)
Changes occurrences of a specified pattern to a replacement string. You can specify that case should be ignored.

Parameters:
s - the input string
oldp - the pattern to be replaced
newp - the replacement string
ignoreCase - if true case is ignored when comparing characters
Returns:
a string with the specified patterns changed.

change

public static String change(String s,
                            String oldp,
                            String newp)
Changes occurrences of a specified pattern to a replacement string.

Parameters:
s - the input string
oldp - the pattern to be replaced
newp - the replacement string
Returns:
a string with the specified patterns changed.

occurrencesOf

public static int occurrencesOf(String s,
                                String c,
                                int start,
                                boolean ignoreCase)
Returns the number of occurrences of the specified string. You can specify that case should be ignored.

Parameters:
s - the string to be inspected
c - the string to search for
start - the starting position for the search
ignoreCase - if true case is ignored when comparing characters
Returns:
the number of occurrences of the specified string. If the string is not found -1 is returned.

occurrencesOf

public static int occurrencesOf(String s,
                                int ch,
                                int start)
counts characters in string, case sensitive

Parameters:
s - string to analyze
ch - character we are looking for
start - start offset inside the string
Returns:
quantity of character occurrences inside the specified string

indexOf

public static int indexOf(String s,
                          String c,
                          int start,
                          boolean ignoreCase)
Returns the index of the first ocurrence of the specified string. You can specify that case should be ignored.

Parameters:
s - the string to be inspected
c - the string to be searched for
start - the starting position for the search
ignoreCase - if true case is ignored when comparing characters
Returns:
the index of the first ocurrence of the specified string.
See Also:
String.indexOf(String, int)

equals

public static boolean equals(char c1,
                             char c2,
                             boolean ignoreCase)
Checks if two characters are equal. You can specify that case should be ignored.

Parameters:
c1 - first character
c2 - second character
ignoreCase - if true case is ignored when comparing characters
Returns:
true if the characters are equal, false otherwise
See Also:
String.equalsIgnoreCase(String)

equals

public static boolean equals(String s1,
                             String s2,
                             boolean ignoreCase)
Checks if two strings are equal. You can specify that case should be ignored.

Parameters:
s1 - first string
s2 - second string
ignoreCase - if true case is ignored when comparing string
Returns:
true if the characters are equal, false otherwise, true if they are both null
See Also:
String.equalsIgnoreCase(String)

substituteBatch

public static String substituteBatch(String source,
                                     Map valuesMap)
Replace all patterns in the string with the ones given in the given HashMap instance. Example:
 // This string is obtained on run-time. For example, template inner text
 String toChangeIn = "<H1> ${SomeVarName} </H1>\r\n<td>${AnotherVarName}</td>";
 
 hashMap.put("${SomeVarName}", SomeRunTimeVarValue);
 hashMap.put("${AnotherVarName}", AnotherVarRuntime);
 
 String changedString = StringTools.substituteBatch(toChangeIn, hashMap);
 


intToHex

public static String intToHex(int value,
                              boolean padding)
Convert integer to hex, optionally padding with 0s

Parameters:
value - int value to convert
padding - do we want to pad int with 0's
Returns:
String hexadecimal presentation of the specified value (optionally padded)

smallIntToHex

public static String smallIntToHex(int value,
                                   boolean padding)
Convert small int to hex, optionally padding with 0s

Parameters:
value - small int value to convert
padding - do we want to pad int with 0's
Returns:
String hexadecimal presentation of the specified value (optionally padded)

ensureTrailing

public static String ensureTrailing(String value,
                                    String suffix)
Ensures that string ends with specified symbol

Parameters:
value - string value to ensure
suffix - suffex to append (if not yet)
Returns:
String with guaranteed suffix

ensureLeading

public static String ensureLeading(String value,
                                   String prefix)
Ensures that string starts with specified symbol

Parameters:
value - string value to ensure
prefix - prefix to append (if not yet)
Returns:
String with guaranteed prefix

toString

public static String toString(InputStream stream)
                       throws IOException
Loads stream contents to the stream

Parameters:
stream - InputStream to load
Returns:
String presentation of the input stream
Throws:
IOException

toString

public static String toString(Map map)
Prints out a map with key value pairs combined with '=' separated by ',' and surrounded by { and }

Parameters:
map - map to be printed
Returns:
String representation of map

toString

public static String toString(Object[] array)
To string an array of objects separated by ',' and surrounded by '[' and ']'.

Parameters:
array - array to be printed
Returns:
String representation of object array

toString

public static String toString(Object object)
ToString object

Parameters:
object - object to be printed
Returns:
string representation of object

toString

public static String toString(String[] array)
Convert array to single string presentation for debugging purposes

Parameters:
array - Source string array
Returns:
String presentation of the array

toString

public static String toString(Collection collection,
                              String lineSeperator)
Convert Collection of object to single string for debugging purposes

Parameters:
collection - Source data collection
lineSeperator - Line separator to use
Returns:
Single string presentation of the specified Collection

toString

public static String toString(String[] array,
                              String lineSeparator)
Convert array of strings to single string presentation for debug purposes

Parameters:
array - Source array of strings
lineSeparator - Line separator to delimit items
Returns:
Single string array presentation

replaceHiAsciChars

public static String replaceHiAsciChars(String orig,
                                        char replacementChar)
Strips out the hi ascii chars (>127) and replaces them with a replacement char

Parameters:
orig - Original string
replacementChar - Replacement character to use
Returns:
Original string with all chars higher than 127 replaced with replacement char

replaceChars

public static String replaceChars(String orig,
                                  String chars,
                                  char replace)
Replaces all chars with the replacement char

Parameters:
orig - Original string
chars - Characters we want to replace
replace - Replacement character
Returns:
Modified original string with all chars replaced with replacement character

replaceChars

public static String replaceChars(String orig,
                                  String chars,
                                  String replace)
Replaces all chars with the replacement char

Parameters:
orig - Original string
chars - Characters we want to replace
replace - Replacement character
Returns:
Modified original string with all chars replaced with replacement character

toBoolean

public static boolean toBoolean(String value)
Converts string to boolean. The difference is that is understands "on" and "off" values as true and false respectively

Parameters:
value - Source string value to convert
Returns:
true or false depending on string content. If string is empty - false is returned

wrap

public static String wrap(String value,
                          String prefix,
                          String postfix)
Wrap string value with prefix and postfix. Result looks as follows:
  result := prefix + value + postfix
 

Parameters:
value - Source string value to wrap
prefix - Prefix to use
postfix - Postfix to use
Returns:
Original string with specified prefix and postfix

unwrap

public static String unwrap(String value,
                            String prefix,
                            String postfix)
Unwraps string using selected prefix and postfix

Parameters:
value - Previously wrapped string
prefix - Prefix to use
postfix - Postfix to use
Returns:
Original value used inside StringTools.wrap(java.lang.String, java.lang.String, java.lang.String) call
See Also:
StringTools.wrap(java.lang.String, java.lang.String, java.lang.String)

truncate

public static String truncate(String value,
                              int maxLength)
Truncates input string to the specified size

Parameters:
value - Source string to analyze
maxLength - Maximum string length
Returns:
Source string truncated using specified size

truncateArray

public static void truncateArray(Object[] values,
                                 int[] actions)
Truncate array of strings using specified list of lengths (actions). Sample usage:
  String[] values = new String[] {
       "one",
       "Some reallllllllllllllllllllly big value",
       "Anotherrrrrrrrrrrrrrrrrrrrrrrrrrrr big value"
  };
 
  int[] actions = new int[] {
       NO_ACTION  // See StringTools.NO_ACTION
       20,
       20
  };
 
  StringTools.truncateArray(values, actions);
 
In this sample 1st element of the values will be left unchanged, but all others will be truncated using 20 as a string length limit

Parameters:
values - Original array of strings
actions - Lengths(actions) to be taken over string values
See Also:
StringTools.NO_ACTION

isFloat

public static boolean isFloat(String value)
Checks whether specified value convertable to float

Parameters:
value -
Returns:
True if value converts and False otherwise

toCsv

public static String toCsv(List strings)
Convert List of strings to comma-separated string

Parameters:
strings - Original strings container
Returns:
Comma-separated list of values taken from original container

toCsv

public static String toCsv(String[] array)
Convert array of strings to comma-separated string

Parameters:
array - Original strings container
Returns:
Comma-separated list of values

toCsv

public static String toCsv(Object[] array)
Convert array of objects to comma-separated string using the toString() method to retrieve the value for each entry.

Parameters:
array - Original strings container
Returns:
Comma-separated list of values

toCsv

public static String toCsv(int[] array)
Convert array of int to comma-separated string

Parameters:
array - Original int container
Returns:
Comma-separated list of values

toCsv

public static String toCsv(short[] array)
Convert array of short to comma-separated string

Parameters:
array - Original short container
Returns:
Comma-separated list of values

toCsv

public static String toCsv(long[] array)
Convert array of long to comma-separated string

Parameters:
array - Original long container
Returns:
Comma-separated list of values

toCsv

public static String toCsv(boolean[] array)
Convert array of boolean to comma-separated string

Parameters:
array - Original boolean container
Returns:
Comma-separated list of values

toCsv

public static String toCsv(float[] array)
Convert array of float to comma-separated string

Parameters:
array - Original float container
Returns:
Comma-separated list of values

toCsv

public static String toCsv(double[] array)
Convert array of double to comma-separated string

Parameters:
array - Original double container
Returns:
Comma-separated list of values

toCsv

public static String toCsv(byte[] array)
Convert array of byte to comma-separated string

Parameters:
array - Original byte container
Returns:
Comma-separated list of values

getIntArrayFromCsv

public static int[] getIntArrayFromCsv(String data)
Parses csv string and returns array of ints as a result of parsing. Of course this appliable only when you do know that string contains integers

Parameters:
data - Original data to parse
Returns:
array of integers

getShortArrayFromCsv

public static short[] getShortArrayFromCsv(String data)
Parses csv string and returns array of short as a result of parsing. Of course this appliable only when you do know that string contains shorts

Parameters:
data - Original data to parse
Returns:
array of integers

getLongArrayFromCsv

public static long[] getLongArrayFromCsv(String data)
Parses csv string and returns array of long as a result of parsing. Of course this appliable only when you do know that string contains longs

Parameters:
data - Original data to parse
Returns:
array of integers

getFloatArrayFromCsv

public static float[] getFloatArrayFromCsv(String data)
Parses csv string and returns array of float as a result of parsing. Of course this appliable only when you do know that string contains floats

Parameters:
data - Original data to parse
Returns:
array of integers

getDoubleArrayFromCsv

public static double[] getDoubleArrayFromCsv(String data)
Parses csv string and returns array of double as a result of parsing. Of course this appliable only when you do know that string contains doubles

Parameters:
data - Original data to parse
Returns:
array of integers

getBooleanArrayFromCsv

public static boolean[] getBooleanArrayFromCsv(String data)
Parses csv string and returns array of boolean as a result of parsing. Of course this appliable only when you do know that string contains booleans

Parameters:
data - Original data to parse
Returns:
array of integers

getByteArrayFromCsv

public static byte[] getByteArrayFromCsv(String data)
Parses csv string and returns array of boolean as a result of parsing. Of course this appliable only when you do know that string contains booleans

Parameters:
data - Original data to parse
Returns:
array of integers

csvToSet

public static Set csvToSet(String csvLine)
Convert comma-separated line to Set of strings. This is especially useful when you do know that line can convert duplicates and you don't want to deal with them.

Parameters:
csvLine - Original comma-separated line
Returns:
Set of values represented in the comma-separated line

concat

public static String concat(String s1,
                            String s2)
Fast 2 string concatenation using StringBuffer.

Parameters:
s1 - source string #1
s2 - source string #2
Returns:
2 strings concatenated

concat

public static String concat(String s1,
                            String s2,
                            String s3)
Fast 3 strings concatenation using StringBuffer

Parameters:
s1 - source string #1
s2 - source string #2
s3 - source string #3
Returns:
3 strings concatenated

concat

public static String concat(String s1,
                            String s2,
                            String s3,
                            String s4)
Fast 4 string concatenation using StringBuffer

Parameters:
s1 - source string #1
s2 - source string #2
s3 - source string #3
s4 - source string #4
Returns:
4 strings concatenated

fastParseLong

public static long fastParseLong(String str)
                          throws NumberFormatException
Fast implementation of Long.parseLong(java.lang.String, int)

Parameters:
str - string to convert
Returns:
long value obtained as a result of string conversion
Throws:
NumberFormatException

getDelimitedList

public static ArrayList getDelimitedList(String value,
                                         String delims,
                                         boolean includeDelim)
Get ArrayList of tokens from delimited original string

Parameters:
value - Original string value
delims - Delimiters used to make tokens
Returns:
list of tokens produced as a result of string parsing

getDelimitedList

public static ArrayList getDelimitedList(String value,
                                         String delims)
Get ArrayList of tokens from delimited original string

Parameters:
value - Original string value
delims - Delimiters used to make tokens
Returns:
list of tokens produced as a result of string parsing

charStr

public static String charStr(char character,
                             int count)
Creates a string consisting of the given character

Parameters:
character - original character
count - length of the string to construct
Returns:
String containing count characters

tabStr

public static String tabStr(int count)
Return string containing the specified quantity of '\t' character

Parameters:
count - Quantity of tabs you want to recieve
Returns:
String containing the given quantity of TAB characters
See Also:
StringTools.charStr(char, int)

isEmpty

public static boolean isEmpty(String s1,
                              String s2)
Checks whether one of the 2 strings is empty

Parameters:
s1 - source string #1
s2 - source string #2
Returns:
True, if one of the strings are empty, False - otherwise

notEmpty

public static boolean notEmpty(String s1,
                               String s2)
Checks that 2 strings are not empty

Parameters:
s1 - string to check #1
s2 - string to check #2
Returns:
True, if both strings are not empty, False - otherwise

notNulls

public static boolean notNulls(String value1,
                               String value2)
Checks that 2 strings are not nulls

Parameters:
value1 - source string #1
value2 - source string #2
Returns:
True, if both strings are not nulls, False - otherwise

removeChars

public static String removeChars(String orig,
                                 String chars)
Replaces all chars with the replacement char

Parameters:
orig - Original string
chars - Chars to remove
Returns:
Original string with all specified characters removed

isFormatCharsOnly

public static boolean isFormatCharsOnly(String value)
Verifies that string contains only formatting characters

Parameters:
value - Original string
Returns:
True, if string contains only '\t\n' characters, False otherwise

replaceParams

public static String replaceParams(String source,
                                   String[] params)
Replace placeholders, or parameters, in a string that are of the format %[number].
   Example: Calling on string "Error locating resource %0 for user %1" with array {"root", "admin"}
            would result in "Error locating resource root for user admin"
 

Parameters:
source - a string with parameters, starting with 0
params - the values for the parameters, the index corresponding to the parameter value + 1
Returns:
the string with the values in place

trimString

public static String trimString(String s,
                                String charsToTrim)
Trims specified characters from the beginning and end of the string

Parameters:
s -
charsToTrim -

capitalizeName

public static String capitalizeName(String name)
Capitalizes name string


humanizeName

public static String humanizeName(String name)
Converts identifiers like "myJavaCompliantName123" into "My Java Compliant Name 123"

Parameters:
name - the value to humanize
Returns:
the humanized value

lowerCaseFirstChar

public static String lowerCaseFirstChar(String s)
Lower cases first character of a string

Parameters:
s - null or String
Returns:
s with lowercase first character

upperCaseFirstChar

public static String upperCaseFirstChar(String s)
Capilizes first character of a string

Parameters:
s - null or String
Returns:
s with a capital first character

getStackTrace

public static String getStackTrace(Throwable t)
Utility function to recieve exception stack trace as a string

Parameters:
t - Throwable to work with
Returns:
Throwable stack trace as a String

loadStringfromStream

public static String loadStringfromStream(InputStream input)
                                   throws IOException
Loads and return string from an InputStream

Returns:
All contents of the file as one string
Throws:
IOException - in case of any I/O error