Anyframe Core

anyframe.common.util
Class StringUtil

java.lang.Object
  extended by anyframe.common.util.StringUtil

public abstract class StringUtil
extends Object

String Utility Class

Author:
SoYon Lim, JongHoon Kim

Method Summary
static boolean containsInvalidChars(String str, char[] invalidChars)
           Checks that the String contains certain characters.
static boolean containsInvalidChars(String str, String invalidChars)
           Checks that the String contains certain characters.
static boolean containsMaxSequence(String str, String maxSeqNumber)
          It returns true if string contains a sequence of the same character.
static String convertToCamelCase(String underScore)
          Convert a string that may contain underscores to camel case.
static String convertToCamelCase(String targetString, char posChar)
          This method convert "string_util" to "stringUtil"
static String convertToUnderScore(String camelCase)
          Convert a camel case string to underscore representation.
static String decodeString(String str)
          Decode a string using Base64 encoding.
static String encodePassword(String password, String algorithm)
          Encode a string using algorithm specified in web.xml and return the resulting encrypted password.
static String encodeString(String str)
          Encode a string using Base64 encoding.
static String fillString(String originalStr, char ch, int cipers)
          Make a new String that filled original to a special char as cipers
static String getLastString(String origStr, String strToken)
          Break a string into specific tokens and return a String of last location.
static String[] getStringArray(String str, String strToken)
          If original String has token, Break a string into specific tokens and change String Array.
static List getTokens(String lst)
          Return token list which is separated by ","
static List getTokens(String lst, String separator)
          Return token list
static String integer2string(int integer)
          It converts integer type to String ( 27 -> '27') StringUtil.integer2string(14) = '14'
static boolean isAlpha(String str)
           Checks if the String contains only unicode letters.
static boolean isAlphaNumeric(String str)
           Checks if the String contains only unicode letters or digits.
static boolean isEmpty(String str)
          If string is null or empty string, return true.
static boolean isEmptyTrimmed(String foo)
          Determine whether a (trimmed) string is empty
static boolean isNotEmpty(String str)
          If string is null or empty string, return false.
static boolean isNumeric(String str)
           Checks if the String contains only unicode digits.
static boolean isPatternMatching(String str, String pattern)
          It returns true if str matches the pattern string.
static String replace(String str, String replacedStr, String replaceStr)
          replace replaced string to specific string from original string.
static String reverse(String str)
           Reverses a String as per StringBuffer.reverse().
static int string2integer(String str)
          It converts the string representation of a number to integer type (eg
static String swapFirstLetterCase(String str)
          convert first letter to a big letter or a small letter.
static String trim(String origString, String trimString)
          If original String has a specific String, remove specific Strings from original String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

encodePassword

public static String encodePassword(String password,
                                    String algorithm)
Encode a string using algorithm specified in web.xml and return the resulting encrypted password. If exception, the plain credentials string is returned

Parameters:
password - Password or other credentials to use in authenticating this username
algorithm - Algorithm used to do the digest
Returns:
encypted password based on the algorithm.

encodeString

public static String encodeString(String str)
Encode a string using Base64 encoding. Used when storing passwords as cookies. This is weak encoding in that anyone can use the decodeString routine to reverse the encoding.

Parameters:
str - String to be encoded
Returns:
String encoding result

decodeString

public static String decodeString(String str)
Decode a string using Base64 encoding.

Parameters:
str - String to be decoded
Returns:
String decoding String

swapFirstLetterCase

public static String swapFirstLetterCase(String str)
convert first letter to a big letter or a small letter.
 StringUtil.trim('Password') = 'password'
 StringUtil.trim('password') = 'Password'
 

Parameters:
str - String to be swapped
Returns:
String converting result

trim

public static String trim(String origString,
                          String trimString)
If original String has a specific String, remove specific Strings from original String.
 StringUtil.trim('pass*word', '*') = 'password'
 

Parameters:
origString - original String
trimString - String to be trimmed
Returns:
converting result

getLastString

public static String getLastString(String origStr,
                                   String strToken)
Break a string into specific tokens and return a String of last location.
 StringUtil.getLastString('password*password*a*b*c', '*') = 'c'
 

Parameters:
origStr - original String
strToken - specific tokens
Returns:
String of last location

getStringArray

public static String[] getStringArray(String str,
                                      String strToken)
If original String has token, Break a string into specific tokens and change String Array. If not, return a String Array which has original String as it is.
 StringUtil.getStringArray('passwordabcpassword', 'abc')                = String[]{'password','password'}
 StringUtil.getStringArray('pasword*password', 'abc')           = String[]{'pasword*password'}
 

Parameters:
str - original String
strToken - specific String token
Returns:
String[]

isNotEmpty

public static boolean isNotEmpty(String str)
If string is null or empty string, return false.
If not, return true.
 StringUtil.isNotEmpty('')              = false
 StringUtil.isNotEmpty(null)            = false
 StringUtil.isNotEmpty('abc')   = true
 

Parameters:
str - original String
Returns:
which empty string or not.

isEmpty

public static boolean isEmpty(String str)
If string is null or empty string, return true.
If not, return false.
 StringUtil.isEmpty('')                 = true
 StringUtil.isEmpty(null)       = true
 StringUtil.isEmpty('abc')      = false
 

Parameters:
str - original String
Returns:
which empty string or not.

replace

public static String replace(String str,
                             String replacedStr,
                             String replaceStr)
replace replaced string to specific string from original string.
 StringUtil.replace('work$id', '$', '.')        = 'work.id'
 

Parameters:
str - original String
replacedStr - to be replaced String
replaceStr - replace String
Returns:
converting result

string2integer

public static int string2integer(String str)
It converts the string representation of a number to integer type (eg. '27' -> 27)
 StringUtil.string2integer('14')        = 14
 

Parameters:
str - string representation of a number
Returns:
integer integer type of string

integer2string

public static String integer2string(int integer)
It converts integer type to String ( 27 -> '27')
 StringUtil.integer2string(14)  = '14'
 

Parameters:
integer - integer type
Returns:
String string representation of a number

isPatternMatching

public static boolean isPatternMatching(String str,
                                        String pattern)
                                 throws Exception
It returns true if str matches the pattern string. It performs regular expression pattern matching.
 StringUtil.isPatternMatching('abc-def', '*-*')         = true
 StringUtil.isPatternMatching('abc', '*-*')     = false
 

Parameters:
str - original String
pattern - pattern String
Returns:
boolean which matches the pattern string or not.
Throws:
Exception - fail to check pattern matched

containsMaxSequence

public static boolean containsMaxSequence(String str,
                                          String maxSeqNumber)
It returns true if string contains a sequence of the same character.
 StringUtil.containsMaxSequence('password', '2')        = true
 StringUtil.containsMaxSequence('my000', '3')   = true
 StringUtil.containsMaxSequence('abbbbc', '5')  = false
 

Parameters:
str - original String
maxSeqNumber - a sequence of the same character
Returns:
which contains a sequence of the same character

containsInvalidChars

public static boolean containsInvalidChars(String str,
                                           char[] invalidChars)

Checks that the String contains certain characters.

A null String will return false. A null invalid character array will return false. An empty String ("") always returns false.

 StringUtil.containsInvalidChars(null, *)                               = false
 StringUtil.containsInvalidChars(*, null)                       = false
 StringUtil.containsInvalidChars("", *)         = false
 StringUtil.containsInvalidChars("ab", '')      = false
 StringUtil.containsInvalidChars("abab", 'xyz') = false
 StringUtil.containsInvalidChars("ab1", 'xyz')  = false
 StringUtil.containsInvalidChars("xbz", 'xyz')  = true
 

Parameters:
str - the String to check, may be null
invalidChars - an array of invalid chars, may be null
Returns:
false if it contains none of the invalid chars, or is null

containsInvalidChars

public static boolean containsInvalidChars(String str,
                                           String invalidChars)

Checks that the String contains certain characters.

A null String will return false. A null invalid character array will return false. An empty String ("") always returns false.

 StringUtil.containsInvalidChars(null, *)                               = false
 StringUtil.containsInvalidChars(*, null)                       = false
 StringUtil.containsInvalidChars("", *)         = false
 StringUtil.containsInvalidChars("ab", '')      = false
 StringUtil.containsInvalidChars("abab", 'xyz') = false
 StringUtil.containsInvalidChars("ab1", 'xyz')  = false
 StringUtil.containsInvalidChars("xbz", 'xyz')  = true
 

Parameters:
str - the String to check, may be null
invalidChars - a String of invalid chars, may be null
Returns:
false if it contains none of the invalid chars, or is null

isAlphaNumeric

public static boolean isAlphaNumeric(String str)

Checks if the String contains only unicode letters or digits.

null will return false. An empty String ("") will return false.

 StringUtil.isAlphaNumeric(null)                         = false
 StringUtil.isAlphaNumeric("")     = false
 StringUtil.isAlphaNumeric("  ")   = false
 StringUtil.isAlphaNumeric("abc")  = true
 StringUtil.isAlphaNumeric("ab c") = false
 StringUtil.isAlphaNumeric("ab2c") = true
 StringUtil.isAlphaNumeric("ab-c") = false
 

Parameters:
str - the String to check, may be null
Returns:
true if only contains letters or digits, and is non-null

isAlpha

public static boolean isAlpha(String str)

Checks if the String contains only unicode letters.

null will return false. An empty String ("") will return false.

 StringUtil.isAlpha(null)                       = false
 StringUtil.isAlpha("")     = false
 StringUtil.isAlpha("  ")   = false
 StringUtil.isAlpha("abc")  = true
 StringUtil.isAlpha("ab2c") = false
 StringUtil.isAlpha("ab-c") = false
 

Parameters:
str - the String to check, may be null
Returns:
true if only contains letters, and is non-null

isNumeric

public static boolean isNumeric(String str)

Checks if the String contains only unicode digits. A decimal point is not a unicode digit and returns false.

null will return false. An empty String ("") will return false.

 StringUtil.isNumeric(null)                = false
 StringUtil.isNumeric("")     = false
 StringUtil.isNumeric("  ")   = false
 StringUtil.isNumeric("123")  = true
 StringUtil.isNumeric("12 3") = false
 StringUtil.isNumeric("ab2c") = false
 StringUtil.isNumeric("12-3") = false
 StringUtil.isNumeric("12.3") = false
 

Parameters:
str - the String to check, may be null
Returns:
true if only contains digits, and is non-null

reverse

public static String reverse(String str)

Reverses a String as per StringBuffer.reverse().

null String returns null.

 StringUtil.reverse(null)                  = null
 StringUtil.reverse("")    = ""
 StringUtil.reverse("bat") = "tab"
 

Parameters:
str - the String to reverse, may be null
Returns:
the reversed String, null if null String input

fillString

public static String fillString(String originalStr,
                                char ch,
                                int cipers)
Make a new String that filled original to a special char as cipers

Parameters:
originalStr - original String
ch - a special char
cipers - cipers
Returns:
filled String

isEmptyTrimmed

public static final boolean isEmptyTrimmed(String foo)
Determine whether a (trimmed) string is empty

Parameters:
foo - The text to check.
Returns:
Whether empty.

getTokens

public static List getTokens(String lst,
                             String separator)
Return token list

Parameters:
lst -
separator -
Returns:

getTokens

public static List getTokens(String lst)
Return token list which is separated by ","

Parameters:
lst -
Returns:

convertToCamelCase

public static String convertToCamelCase(String targetString,
                                        char posChar)
This method convert "string_util" to "stringUtil"

Parameters:
String - targetString
char - posChar
Returns:
String result

convertToCamelCase

public static String convertToCamelCase(String underScore)
Convert a string that may contain underscores to camel case.

Parameters:
underScore - Underscore name.
Returns:
Camel case representation of the underscore string.

convertToUnderScore

public static String convertToUnderScore(String camelCase)
Convert a camel case string to underscore representation.

Parameters:
camelCase - Camel case name.
Returns:
Underscore representation of the camel case string.

Anyframe Core

Copyright © 2008-2009 Samsung SDS. All Rights Reserved.