com.sibvisions.util.type
Class StringUtil

java.lang.Object
  extended by com.sibvisions.util.type.StringUtil

public final class StringUtil
extends Object

The StringUtil contains string dependent utility methods.


Method Summary
static String formatHumanReadable(String pName)
          Formats a text label with upper and lower case characters, e.g: first_nr -> First Nr The character _ will be replaced with space.
static String formatInitCap(String pName)
          Sets the first character in each word to uppercase and the rest to lowercase.
static String formatInitCap(String pName, boolean pRemoveSpaces)
          Sets the first character in each word to uppercase and the rest to lowercase.
static String formatMemberName(String pName)
          Formats a member name.
static String formatMethodName(String pPrefix, String pName)
          Formats a method name with a given property name and the method prefix.
static String getAlphaNumeric(String pText)
          Gets the alpha numeric characters from a string.
static int[] getQuotedBoundaries(String sText)
          Returns the boundaries of quoted strings.
static boolean like(String pSource, String pSearch)
          Fast like search in Strings with the wildcards are * and ?.
static int[] parseInteger(String pValues, String pDelimiter)
          Gets the int values from a string with delimiters.
static ArrayUtil<String> separateList(String pList, String pDelimiter, boolean pTrim)
          Separates a string of values with a configurable delimiter.
static String toString(Object pObject)
          Returns a string representation of the "deep contents" of the specified object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getQuotedBoundaries

public static int[] getQuotedBoundaries(String sText)
Returns the boundaries of quoted strings. Examples.:
 unitTest("Test", Application.class, " Application.class");
 unitTest("Test\", Application.class", Application.class");
 unitTest("Test", Application.class", Application.class);
 

Parameters:
sText - the text with our without quotes
Returns:
the boundaries as array [start, stop, start, stop] or an empty array

separateList

public static ArrayUtil<String> separateList(String pList,
                                             String pDelimiter,
                                             boolean pTrim)
Separates a string of values with a configurable delimiter.

Parameters:
pList - string with values
pDelimiter - delimiter to separate
pTrim - true to trim the separated values
Returns:
list of separated values

parseInteger

public static int[] parseInteger(String pValues,
                                 String pDelimiter)
Gets the int values from a string with delimiters.

Parameters:
pValues - the string with numbers and delimiters
pDelimiter - the delimiter
Returns:
the int values or null if the values are null or empty

like

public static boolean like(String pSource,
                           String pSearch)
Fast like search in Strings with the wildcards are * and ?.

Parameters:
pSource - any string
pSearch - search pattern with the wildcards are * and ?.
Returns:
true if, and only if, the string matches the pattern

formatHumanReadable

public static String formatHumanReadable(String pName)
Formats a text label with upper and lower case characters, e.g: first_nr -> First Nr The character _ will be replaced with space.

Parameters:
pName - the unformatted label
Returns:
the formatted label

formatInitCap

public static String formatInitCap(String pName)
Sets the first character in each word to uppercase and the rest to lowercase.

Parameters:
pName - the unformatted text
Returns:
the formatted test

formatInitCap

public static String formatInitCap(String pName,
                                   boolean pRemoveSpaces)
Sets the first character in each word to uppercase and the rest to lowercase.

Parameters:
pName - the unformatted text
pRemoveSpaces - true to remove whitespaces and '_' characters from the result
Returns:
the formatted test

formatMethodName

public static String formatMethodName(String pPrefix,
                                      String pName)
Formats a method name with a given property name and the method prefix.

Parameters:
pPrefix - the method prefix
pName - the property name
Returns:
the formated method name

formatMemberName

public static String formatMemberName(String pName)
Formats a member name. A member starts always with a lower case letter.

Parameters:
pName - the member name
Returns:
the formatted member name

getAlphaNumeric

public static String getAlphaNumeric(String pText)
Gets the alpha numeric characters from a string.

Parameters:
pText - any text
Returns:
the alpha numeric characters

toString

public static String toString(Object pObject)
Returns a string representation of the "deep contents" of the specified object. If the object contains other objects as elements, the string representation contains their contents and so on. This method is designed for converting multidimensional arrays, Collections and Maps to strings.

The string representation consists of a list of the object's elements, enclosed in brackets ("[]" or "{}"). Adjacent elements are separated by the characters ", " (a comma followed by a space).

To avoid infinite recursion, if the specified object contains itself as an element, or contains an indirect reference to itself through one or more levels of arrays, the self-reference is converted to the string "#REF#". For example, an array containing only a reference to itself would be rendered as "[#REF#]".

This method returns "null" if the specified object is null.

Parameters:
pObject - the object whose string representation to return
Returns:
a string representation of pObject


Copyright © 2009 SIB Visions GmbH. All Rights Reserved.