org.opensubsystems.core.util
Class StringUtils

java.lang.Object
  extended by org.opensubsystems.core.util.StringUtils

public final class StringUtils
extends java.lang.Object

Utility methods for String manipulation.

Version:
$Id: StringUtils.java,v 1.14 2007/02/20 04:08:10 bastafidli Exp $
Author:
Peter Satury
Code reviewer:
Miro Halas
Code reviewed:
1.11 2006/04/29 00:24:18 jlegeny

Field Summary
static int CASE_ORIGINAL
          Keep the original case of the string;
static int CASE_TOLOWER
          Convert the string to lower case.
static int CASE_TOUPPER
          Convert the string to upper case.
static java.lang.String COMMA_STRING
          Constant for assigning
static java.lang.String EMPTY_STRING
          Constant for assigning
 
Method Summary
static java.lang.String concat(java.lang.String[] strings, java.lang.String separator, java.lang.String quote)
          Concat all the specified strings to a single one
static boolean contains(java.util.Collection container, java.lang.String strSearch)
          Test if given string contains any element in the container.
static boolean containsInSeparatedString(java.lang.String strSearchIn, java.lang.String strSearchFor, java.lang.String strSeparator)
          Method return boolean result if particular substring is contained within the list of substrings separated by a separator.
static int count(java.lang.String text, char lookup)
          Count number of occurences of lookup in text.
static boolean isContained(java.util.Collection container, java.lang.String strSearch)
          Test if any element in the container contains given string.
static java.lang.String limitStringLength(int limitLength, java.lang.String strValue)
          Method to limit String length for display and add '...' to the end
static java.lang.String parseCollectionToString(java.util.Collection colObjects, java.lang.String strDel)
          Parse collection of objects to String by calling toString on each element.
static double parseFraction(java.lang.String textToParse, double defaultValue, boolean bIgnoreRest)
          Parse textual representation of fraction to a floating point number
static java.lang.String parseIntArrayToString(int[] arrParse, java.lang.String strDel)
          Parse array of integers to String.
static java.lang.String[] parseQuotedStringToStringArray(java.lang.String strParse, java.lang.String strDel, boolean bAllowSingleQuote, boolean bAllowDoubleQuote)
          Parse String to array of Strings while treating quoted values as single element.
static java.util.Collection parseStringToCollection(java.lang.String strParse, java.lang.String strDel, boolean bTrim, int iConvertCase, java.util.Collection container)
          Parse String to ANY collection you specify and trim each item.
static int[] parseStringToIntArray(java.lang.String strParse, java.lang.String strDel)
          Parse String to array of integers.
static java.lang.Integer[] parseStringToIntegerArray(java.lang.String strParse, java.lang.String strDel)
          Parse String to array of Integers.
static java.util.List parseStringToList(java.lang.String strParse, java.lang.String strDel)
          Parse String to List.
static java.lang.String[] parseStringToStringArray(java.lang.String strParse, java.lang.String strDel)
          Parse String to array of Strings.
static java.lang.String removeComma(java.lang.String strToRemoveFrom)
          Method to remove comma from start and from end of the string for examples to use it as parameter to SQL IN operator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_STRING

public static final java.lang.String EMPTY_STRING
Constant for assigning

See Also:
Constant Field Values

COMMA_STRING

public static final java.lang.String COMMA_STRING
Constant for assigning

See Also:
Constant Field Values

CASE_ORIGINAL

public static final int CASE_ORIGINAL
Keep the original case of the string;

See Also:
Constant Field Values

CASE_TOUPPER

public static final int CASE_TOUPPER
Convert the string to upper case.

See Also:
Constant Field Values

CASE_TOLOWER

public static final int CASE_TOLOWER
Convert the string to lower case.

See Also:
Constant Field Values
Method Detail

count

public static int count(java.lang.String text,
                        char lookup)
Count number of occurences of lookup in text.

Parameters:
text - - text to search in for occurences of lookup
lookup - - character to count
Returns:
int - number of occurences of lookup in text.

parseFraction

public static double parseFraction(java.lang.String textToParse,
                                   double defaultValue,
                                   boolean bIgnoreRest)
Parse textual representation of fraction to a floating point number

Parameters:
textToParse - - in the form "any_text whole_part quotient/divisor any_text"
defaultValue - - if the test is unparsable, what default value to return
bIgnoreRest - - if true, this will ignore the rest of the string (any_other_text) after the fraction, if false then the whole string is considered
Returns:
double - number coresponding to the fraction

parseQuotedStringToStringArray

public static java.lang.String[] parseQuotedStringToStringArray(java.lang.String strParse,
                                                                java.lang.String strDel,
                                                                boolean bAllowSingleQuote,
                                                                boolean bAllowDoubleQuote)
                                                         throws OSSInvalidDataException
Parse String to array of Strings while treating quoted values as single element.

Parameters:
strParse - - String to parse
strDel - - String deliminer
bAllowSingleQuote - - single qoutes such as ' can be used to group value
bAllowDoubleQuote - - double quote such as " can be used to group value
Returns:
String[] - parsed list
Throws:
OSSInvalidDataException - - error during parsing

parseStringToIntArray

public static int[] parseStringToIntArray(java.lang.String strParse,
                                          java.lang.String strDel)
                                   throws OSSException
Parse String to array of integers.

Parameters:
strParse - - String to parse
strDel - - String deliminer
Returns:
int[] - parsed list
Throws:
OSSException - - error during parsing

parseStringToIntegerArray

public static java.lang.Integer[] parseStringToIntegerArray(java.lang.String strParse,
                                                            java.lang.String strDel)
                                                     throws OSSException
Parse String to array of Integers.

Parameters:
strParse - - String to parse
strDel - - String deliminer
Returns:
Integer[] - parsed list
Throws:
OSSException - - error during parsing

parseStringToStringArray

public static java.lang.String[] parseStringToStringArray(java.lang.String strParse,
                                                          java.lang.String strDel)
Parse String to array of Strings.

Parameters:
strParse - - String to parse
strDel - - String deliminer
Returns:
String[] - parsed list

parseIntArrayToString

public static java.lang.String parseIntArrayToString(int[] arrParse,
                                                     java.lang.String strDel)
Parse array of integers to String.

Parameters:
arrParse - - int array to parse
strDel - - String deliminer
Returns:
String - parsed array

parseCollectionToString

public static java.lang.String parseCollectionToString(java.util.Collection colObjects,
                                                       java.lang.String strDel)
Parse collection of objects to String by calling toString on each element.

Parameters:
colObjects - - collection of data objects to parse
strDel - - String deliminer
Returns:
String - parsed array

parseStringToList

public static java.util.List parseStringToList(java.lang.String strParse,
                                               java.lang.String strDel)
Parse String to List.

Parameters:
strParse - - String to parse
strDel - - String deliminer
Returns:
List - parsed list of items in the string delimtied by delimiter

parseStringToCollection

public static java.util.Collection parseStringToCollection(java.lang.String strParse,
                                                           java.lang.String strDel,
                                                           boolean bTrim,
                                                           int iConvertCase,
                                                           java.util.Collection container)
Parse String to ANY collection you specify and trim each item.

Parameters:
strParse - - String to parse
strDel - - String deliminer
container - - if specified then it will be filled with items (it WILL NOT be emptied first). If this is null, the default collection will be allocated. This allows you here to pass list or set so this method is more flexible.
bTrim - - should it be trimmed or not
iConvertCase - - how to convert the case of the string - one of the CASE_XXX costants
Returns:
Collection - parsed collection, if container was specified, the same object will be returned. If it was not specified default object will be returned. If strParse was not null, then this will be not null.

limitStringLength

public static java.lang.String limitStringLength(int limitLength,
                                                 java.lang.String strValue)
Method to limit String length for display and add '...' to the end

Parameters:
limitLength - - limit of length
strValue - - String to limit
Returns:
String - limited String

removeComma

public static java.lang.String removeComma(java.lang.String strToRemoveFrom)
Method to remove comma from start and from end of the string for examples to use it as parameter to SQL IN operator

Parameters:
strToRemoveFrom - - String to remove comma from
Returns:
String - string with removed commas from the start and end of the string

concat

public static java.lang.String concat(java.lang.String[] strings,
                                      java.lang.String separator,
                                      java.lang.String quote)
Concat all the specified strings to a single one

Parameters:
strings - - strings to concat, all null and empty ones will be ignored
separator - - separator to put in between the string elements
quote - - quote string to put around string elements, if null nothing will be put around them
Returns:
String with concatenated inputs

isContained

public static boolean isContained(java.util.Collection container,
                                  java.lang.String strSearch)
Test if any element in the container contains given string.

Parameters:
container - - container of which elements will be searched to see if they contains given text
strSearch - - text to search in the elements of specified container
Returns:
boolean - true if any of the elements in container contains given text

contains

public static boolean contains(java.util.Collection container,
                               java.lang.String strSearch)
Test if given string contains any element in the container.

Parameters:
container - - container of which elements will be searched to see if they are contained within given text
strSearch - - text to search in for the elements of specified container
Returns:
boolean - true if the search text contains any of the elements in container

containsInSeparatedString

public static boolean containsInSeparatedString(java.lang.String strSearchIn,
                                                java.lang.String strSearchFor,
                                                java.lang.String strSeparator)
Method return boolean result if particular substring is contained within the list of substrings separated by a separator.

Parameters:
strSearchIn - - string of all substrings separated by separator to search in
strSearchFor - - string that will be search for
strSeparator - - item separator
Returns:
boolean - true if it contains the ID, false otherwise


Copyright © 2003 - 2006 OpenSubsystems s.r.o.