com.knowgate.misc
Class Gadgets

java.lang.Object
  extended by com.knowgate.misc.Gadgets

public final class Gadgets
extends java.lang.Object

Miscellaneous functions and utilities.


Field Summary
static char[] HEX_DIGITS
           
 
Constructor Summary
Gadgets()
           
 
Method Summary
static java.lang.String accentsToPosixRegEx(java.lang.String sText)
          Replace any vowel by a POSIX Regular Expression representing all its accentuated variants
static java.lang.String ASCIIEncode(java.lang.String sStrIn)
          Convert an ASCII-8 String to an ASCII-7 String
static boolean checkEMail(java.lang.String sEMailAddr)
          Check that an e-mail address is syntactically valid.
static java.lang.String chomp(java.lang.String sSource, char cEndsWith)
          Ensure that a String ends with a given character
static java.lang.String chomp(java.lang.String sSource, java.lang.String sEndsWith)
          Ensure that a String ends with a given substring
static boolean contains(java.lang.String sSource, java.lang.String sRegExp)
          Check whether or not a String contains a regular expression
static int countOccurrences(java.lang.String sSource, java.lang.String sSubStr, int iOptions)
          Count occurrences of a given substring
static java.lang.String dechomp(java.lang.String sSource, char cEndsWith)
          Ensure that a String does not end with a given character
static java.lang.String dechomp(java.lang.String sSource, java.lang.String sEndsWith)
          Ensure that a String does not end with a given substring
static java.lang.String escapeChars(java.lang.String sInput, java.lang.String sSpecialSet, char cEsc)
          Preffixes a set of special characters with an escape character
static java.lang.String fill(char c, int len)
          Fill String with a given character
static java.lang.String formatCurrency(java.math.BigDecimal oDec, java.lang.String sCurrency, java.util.Locale oLocale)
          Format a BigDecimal as a String following the rules for an specific locale
static java.lang.String formatCurrency(java.math.BigDecimal oDec, java.lang.String sCurrency, java.lang.String sLanguage)
          Format a BigDecimal as a String following the rules for an specific locale
static java.lang.String formatCurrency(java.math.BigDecimal oDec, java.lang.String sCurrency, java.lang.String sLanguage, java.lang.String sCountry)
          Format a BigDecimal as a String following the rules for an specific locale
static java.lang.String generateRandomId(int iLength, java.lang.String sCharset, byte byCategory)
          Generate a random identifier of a given length
static java.lang.String generateUUID()
          Generate an universal unique identifier
static java.lang.String getFirstMatchSubStr(java.lang.String sSource, java.lang.String sRegExp)
          Get the first substring that matches the given regular expression
static int getLevenshteinDistance(java.lang.String s, java.lang.String t)
          Calculate Levenshtein distance between two strings The Levenshtein distance is defined as the minimal number of characters you have to replace, insert or delete to transform str1 into str2.
static java.lang.String HTMLDencode(java.lang.String text)
           
static java.lang.String HTMLEncode(java.lang.String text)
          Return text enconded as HTML.
static int indexOfIgnoreCase(java.lang.String sSource, java.lang.String sSought)
          Get index of a substring inside another string
static int indexOfIgnoreCase(java.lang.String sSource, java.lang.String sSought, int iStartAt)
          Get index of a substring inside another string
static java.lang.String join(java.util.Collection oList, java.lang.String sDelimiter)
          Join a Collection into a String
static java.lang.String join(java.lang.String[] aList, java.lang.String sDelimiter)
          Join an Array into a String
static java.lang.String left(java.lang.String sSource, int nChars)
          Return left portion of a string.
static java.lang.String leftPad(java.lang.String sSource, char cPad, int nChars)
          Add padding characters to the left.
static void main(java.lang.String[] argv)
           
static java.util.TreeMap mapCmdLine(java.lang.String sSource)
          Take an input string and return a map of commands
static boolean matches(java.lang.String sSource, java.lang.String sRegExp)
          Check whether or not a String matches a regular expression
static java.lang.String removeChar(java.lang.String sInput, char cRemove)
          Remove a character from a String
static java.lang.String removeChars(java.lang.String sInput, java.lang.String sRemove)
          Remove a character set from a String
static java.lang.String repeat(java.lang.String sSubStr, int nTimes)
          Repeat a substring n times
static java.lang.String replace(java.lang.String sSource, char cSought, java.lang.String sNewVal)
          Replace a single character with one or more other characters
static java.lang.String replace(java.lang.String sSource, java.lang.String sRegExp, java.lang.String sNewVal)
          Replace a given pattern on a string with a fixed value
static java.lang.String replace(java.lang.String sSource, java.lang.String sRegExp, java.lang.String sNewVal, int iOptions)
          Replace a given pattern on a string with a fixed value
static java.lang.String rightPad(java.lang.String sSource, char cPad, int nChars)
          Add padding characters to the right.
static java.math.BigDecimal round2(java.math.BigDecimal oDec)
          Rounds a BigDecimal value to two decimals
static int search(int[] aList, int iSought)
          Perform brute force search of an int into an Array
static int search(java.lang.String[] aList, java.lang.String sSought)
          Perform case sensitive brute force search of a String into an Array
static java.lang.String[] split(java.lang.String sInputStr, char cDelimiter)
          Split a String using a character delimiter Contiguous delimiters with nothing in the middle will delimit empty substrings.
static java.lang.String[] split(java.lang.String sInputStr, char[] aDelimiter)
          Split a String using any of the given characters as delimiter
static java.lang.String[] split(java.lang.String sInputStr, java.lang.String sDelimiter)
          Split a String using a substring delimiter Contiguous delimiters with nothing in the middle will be considered has a single delimiter.
static java.lang.String[] split2(java.lang.String sInputStr, char cDelimiter)
          Split a String in two parts This method is a special case optimization of split() to be used when the input string is to be splitted by a single character delimiter and there at most one occurrence of that delimiter.
static java.lang.String[] split2(java.lang.String sInputStr, java.lang.String sDelimiter)
          Split a String in two parts This method is a special case optimization of split() to be used when the input string is to be splitted by a variable length delimiter and there at most one occurrence of that delimiter.
static java.util.Collection splitAsCollection(java.lang.String sInputStr, char cDelimiter)
          Split a String into a Collection using a character delimiter Contiguous delimiters with nothing in the middle will delimit empty substrings.
static java.lang.String substrAfter(java.lang.String sSource, int iFromIndex, java.lang.String sSought)
          Get substring after a given character sequence
static java.lang.String substrBetween(java.lang.String sSource, java.lang.String sLowerBound, java.lang.String sUpperBound)
          Get substring between two given character sequence
static java.lang.String substrUpTo(java.lang.String sSource, int iFromIndex, char cSought)
          Get substring from an index up to next given character
static java.lang.String substrUpTo(java.lang.String sSource, int iFromIndex, java.lang.String sSought)
          Get substring from an index up to next given character sequence
static void toHexChars(int val, char[] dst, int dstIndex, int size)
           
static java.lang.String toHexString(byte[] src)
          Convert a byte array into its corresponding Hexadecimal String representation
static java.lang.String toHexString(byte[] src, int srcIndex, int size)
          Convert a byte array into its corresponding Hexadecimal String representation
static java.lang.String toHexString(int val, int size)
           
static java.lang.String[] tokenizeCmdLine(java.lang.String sSource)
          Take an input string and tokenize each command on it
static java.lang.String URLEncode(java.lang.String sStr)
          Return text enconded as an URL.
static java.lang.String XHTMLEncode(java.lang.String text)
          Return text enconded as XHTML.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HEX_DIGITS

public static final char[] HEX_DIGITS
Constructor Detail

Gadgets

public Gadgets()
Method Detail

generateUUID

public static java.lang.String generateUUID()
Generate an universal unique identifier

Returns:
An hexadecimal string of 32 characters, created using the machine IP address, current system date, a randon number and a sequence.

generateRandomId

public static java.lang.String generateRandomId(int iLength,
                                                java.lang.String sCharset,
                                                byte byCategory)
                                         throws java.lang.StringIndexOutOfBoundsException
Generate a random identifier of a given length

Parameters:
iLength - int Length of identifier to be generated /between 1 and 4096 characters)
sCharset - String Character set to be used for generating the identifier
byCategory - byte Character category, must be one of Character.UNASSIGNED, Character.UPPERCASE_LETTER or Character.LOWERCASE_LETTER If sCharset is null then it is "abcdefghjkmnpqrstuvwxyz23456789" by default
Returns:
Identifier of given length composed using the designated character set created using the machine IP address, current system date, a randon number and a sequence.
Throws:
java.lang.StringIndexOutOfBoundsException

XHTMLEncode

public static java.lang.String XHTMLEncode(java.lang.String text)

Return text enconded as XHTML.

ASCII-7 characters [0..127] are returned as they are, any other character is returned as &#code;

Parameters:
text - String
Returns:
String

HTMLEncode

public static java.lang.String HTMLEncode(java.lang.String text)

Return text enconded as HTML.

For example "Tom & Jerry" is encoded as "Tom & Jerry"

Parameters:
text - Text to encode
Returns:
HTML-encoded text

HTMLDencode

public static java.lang.String HTMLDencode(java.lang.String text)

URLEncode

public static java.lang.String URLEncode(java.lang.String sStr)
Return text enconded as an URL. For example, "Tom's Bookmarks" is encodes as "Tom%27s%20Bookmarks"

Parameters:
sStr - Text to encode
Returns:
URL-encoded text

ASCIIEncode

public static java.lang.String ASCIIEncode(java.lang.String sStrIn)
Convert an ASCII-8 String to an ASCII-7 String


accentsToPosixRegEx

public static java.lang.String accentsToPosixRegEx(java.lang.String sText)
Replace any vowel by a POSIX Regular Expression representing all its accentuated variants

Returns:
If Input String is Andrés Lozäno the returned value will be something like [AÁÀÄÂAÅAAAÃ]ndr[eéàëêeeeee]s L[oóòöôoooøõo]z[aáàäâaåaaaã]n[oóòöôoooøõo]

split2

public static java.lang.String[] split2(java.lang.String sInputStr,
                                        char cDelimiter)
                                 throws java.lang.NullPointerException
Split a String in two parts This method is a special case optimization of split() to be used when the input string is to be splitted by a single character delimiter and there at most one occurrence of that delimiter.

Parameters:
sInputStr - String to split
cDelimiter - Single character to be used as delimiter, the String will be splited on the first occurence of character.
Returns:
If cDelimiter is not found, or cDelimiter if found as the first character of sInputStr or cDelimiter if found as the last character of sInputStr then an array with a single String element is returned. If cDelimiter is found somewhere in the middle of sInputStr then an array with 2 elements is returned.
Throws:
java.lang.NullPointerException - If sInputStr is null

split2

public static java.lang.String[] split2(java.lang.String sInputStr,
                                        java.lang.String sDelimiter)
                                 throws java.lang.NullPointerException
Split a String in two parts This method is a special case optimization of split() to be used when the input string is to be splitted by a variable length delimiter and there at most one occurrence of that delimiter.

Parameters:
sInputStr - String to split
sDelimiter - String to be used as delimiter, the String will be splited on the first occurence of sDelimiter.
Returns:
If sDelimiter is not found, or sInputStr starts with sDelimiter or sInputStr ends with sDelimiter then an array with a single String element is returned. If sDelimiter is found somewhere in the middle of sInputStr then an array with 2 elements is returned.
Throws:
java.lang.NullPointerException - If sInputStr is null

split

public static java.lang.String[] split(java.lang.String sInputStr,
                                       char cDelimiter)
                                throws java.lang.NullPointerException

Split a String using a character delimiter

Contiguous delimiters with nothing in the middle will delimit empty substrings.
This is an important behaviour difference between Gadgets.split(String,String) and Gadgets.split(String,char).
Gadgets.split("1;;3;;5;6,";") will return String[4] but Gadgets.split("1;;3;;5;6,';') will return String[6]

Parameters:
sInputStr - String to split
cDelimiter - Character Delimiter
Returns:
An array with the splitted substrings
Throws:
java.lang.NullPointerException - If sInputStr is null

split

public static java.lang.String[] split(java.lang.String sInputStr,
                                       char[] aDelimiter)
                                throws java.lang.NullPointerException

Split a String using any of the given characters as delimiter

Parameters:
aDelimiter - Character Delimiter Array
Returns:
An array with the splitted substrings
Throws:
java.lang.NullPointerException - If sInputStr is null or aDelimiter is null

split

public static java.lang.String[] split(java.lang.String sInputStr,
                                       java.lang.String sDelimiter)
                                throws java.lang.NullPointerException

Split a String using a substring delimiter

Contiguous delimiters with nothing in the middle will be considered has a single delimiter.
This is an important behaviour difference between Gadgets.split(String,String) and Gadgets.split(String,char).
Gadgets.split("1;;3;;5;6,";") will return String[4] but Gadgets.split("1;;3;;5;6,';') will return String[6]

Parameters:
sInputStr - String to split
sDelimiter - Substring Delimiter (no regular expressions allowed)
Returns:
An array with the splitted substrings
Throws:
java.lang.NullPointerException - If sInputStr is null

join

public static java.lang.String join(java.util.Collection oList,
                                    java.lang.String sDelimiter)
Join a Collection into a String

Parameters:
oList - Collection to join
sDelimiter - Delimiter for elements in resulting String
Returns:
List joined as a String

join

public static java.lang.String join(java.lang.String[] aList,
                                    java.lang.String sDelimiter)
Join an Array into a String

Parameters:
aList - Array to join
sDelimiter - Delimiter for elements in resulting String
Returns:
List joined as a String
Since:
v3.0

splitAsCollection

public static java.util.Collection splitAsCollection(java.lang.String sInputStr,
                                                     char cDelimiter)
                                              throws java.lang.NullPointerException

Split a String into a Collection using a character delimiter

Contiguous delimiters with nothing in the middle will delimit empty substrings.

Parameters:
sInputStr - String to split
cDelimiter - Character Delimiter
Returns:
A LinkedList splitted substrings
Throws:
java.lang.NullPointerException - If sInputStr is null

search

public static int search(java.lang.String[] aList,
                         java.lang.String sSought)
Perform case sensitive brute force search of a String into an Array

Parameters:
aList - Array of Strings
sSought - String sought
Returns:
String index into Array or -1 if not found or sSought is null
Since:
v5.0

search

public static int search(int[] aList,
                         int iSought)
Perform brute force search of an int into an Array

Parameters:
aList - Array of int
iSought - Value sought
Returns:
Index into Array or -1 if not found
Since:
v5.5

indexOfIgnoreCase

public static int indexOfIgnoreCase(java.lang.String sSource,
                                    java.lang.String sSought,
                                    int iStartAt)
Get index of a substring inside another string

Parameters:
sSource - String String to be scanned
sSought - Substring to be sought
iStartAt - int Index to start searching from
Returns:
int Start index of substring or -1 if not found

indexOfIgnoreCase

public static int indexOfIgnoreCase(java.lang.String sSource,
                                    java.lang.String sSought)
Get index of a substring inside another string

Parameters:
sSource - String String to be scanned
sSought - Substring to be sought
Returns:
int Start index of substring or -1 if not found

fill

public static java.lang.String fill(char c,
                                    int len)
                             throws java.lang.IndexOutOfBoundsException
Fill String with a given character

Parameters:
c - Character for filling
len - Number of characters
Returns:
A String with given numbers of characters
Throws:
java.lang.IndexOutOfBoundsException - if len<0

repeat

public static java.lang.String repeat(java.lang.String sSubStr,
                                      int nTimes)
                               throws java.lang.IndexOutOfBoundsException
Repeat a substring n times

Parameters:
sSubStr - Substring to be repeated
nTimes - Number of times to repeat
Returns:
String with n repetitions of sSubStr, if nTimes is zero the empty string "" is returned, if sSubStr is null the null is returned
Throws:
java.lang.IndexOutOfBoundsException - if nTimes<0
Since:
4.0

matches

public static boolean matches(java.lang.String sSource,
                              java.lang.String sRegExp)
                       throws MalformedPatternException
Check whether or not a String matches a regular expression

Parameters:
sSource - String Source
sRegExp - String Regular Expression
Returns:
boolean false if either sSource or sRegExp are null
Throws:
MalformedPatternException
Since:
v3.0
See Also:
http://www.savarese.org/oro/docs/OROMatcher/Syntax.html

contains

public static boolean contains(java.lang.String sSource,
                               java.lang.String sRegExp)
                        throws MalformedPatternException
Check whether or not a String contains a regular expression

Parameters:
sSource - String Source
sRegExp - String Regular Expression
Returns:
boolean false if either sSource or sRegExp are null
Throws:
MalformedPatternException
Since:
v3.0
See Also:
http://www.savarese.org/oro/docs/OROMatcher/Syntax.html

getFirstMatchSubStr

public static java.lang.String getFirstMatchSubStr(java.lang.String sSource,
                                                   java.lang.String sRegExp)
                                            throws MalformedPatternException
Get the first substring that matches the given regular expression

Parameters:
sSource - String Source
sRegExp - String Regular Expression
Returns:
String if no substring matches the regular expression then null is returned
Throws:
MalformedPatternException
Since:
v3.0
See Also:
http://jakarta.apache.org/oro/api/org/apache/oro/text/regex/Perl5Matcher.html

replace

public static java.lang.String replace(java.lang.String sSource,
                                       char cSought,
                                       java.lang.String sNewVal)
                                throws java.lang.NullPointerException
Replace a single character with one or more other characters

Parameters:
sSource - Source String
cSought - Character to be sought
sNewVal - New value for character, if it is an empty string "" then the sought character is just removed from the source string
Returns:
Replaced string or null if sSource if null
Throws:
java.lang.NullPointerException - if sNewVal is null
Since:
4.0

replace

public static java.lang.String replace(java.lang.String sSource,
                                       java.lang.String sRegExp,
                                       java.lang.String sNewVal)
                                throws MalformedPatternException
Replace a given pattern on a string with a fixed value

Parameters:
sSource - Source String
sRegExp - Regular Expression to be matched
sNewVal - New value for replacement
Throws:
MalformedPatternException
java.lang.NullPointerException - if either sRegExp or NewVal is null
See Also:
http://www.savarese.org/oro/docs/OROMatcher/Syntax.html

replace

public static java.lang.String replace(java.lang.String sSource,
                                       java.lang.String sRegExp,
                                       java.lang.String sNewVal,
                                       int iOptions)
                                throws MalformedPatternException
Replace a given pattern on a string with a fixed value

Parameters:
sSource - Source String
sRegExp - Regular Expression to be matched
sNewVal - New value for replacement
iOptions - A set of flags giving the compiler instructions on how to treat the regular expression. The flags are a logical OR of any number of the five org.apache.oro.text.regex.Perl5Compiler MASK constants.
Throws:
MalformedPatternException
See Also:
http://www.savarese.org/oro/docs/OROMatcher/Syntax.html

countOccurrences

public static int countOccurrences(java.lang.String sSource,
                                   java.lang.String sSubStr,
                                   int iOptions)
                            throws MalformedPatternException
Count occurrences of a given substring

Parameters:
sSource - String Source
sSubStr - Substring to be searched (no wildcards)
iOptions - int org.apache.oro.text.regex.Perl5Compiler.CASE_INSENSITIVE_MASK for case insensitive search
Returns:
int Number of occurrences of sSubStr at sSource. If sSource is null or sSubStr is null then the number of occurrences is zero. If sSource is empty or sSubStr is empty then the number of occurrences is zero.
Throws:
MalformedPatternException

left

public static java.lang.String left(java.lang.String sSource,
                                    int nChars)
Return left portion of a string. This function is similar to substring(sSource, nChars) but it does not raise any exception if sSource.length()>nChars but just return the full sSource input String.

Parameters:
sSource - Source String
nChars - Number of characters to the left of String to get.
Returns:
Left characters of sSource String or null if sSource is null.

leftPad

public static java.lang.String leftPad(java.lang.String sSource,
                                       char cPad,
                                       int nChars)
Add padding characters to the left.

Parameters:
sSource - Input String
cPad - Padding character
nChars - Final length of the padded string
Returns:
Padded String

rightPad

public static java.lang.String rightPad(java.lang.String sSource,
                                        char cPad,
                                        int nChars)
Add padding characters to the right.

Parameters:
sSource - Input String
cPad - Padding character
nChars - Final length of the padded string
Returns:
Padded String
Since:
4.0

chomp

public static java.lang.String chomp(java.lang.String sSource,
                                     char cEndsWith)
Ensure that a String ends with a given character

Parameters:
sSource - Input String
cEndsWith - Character that the String must end with.
Returns:
If sSource ends with cEndsWith then sSource is returned, else sSource+cEndsWith is returned.

chomp

public static java.lang.String chomp(java.lang.String sSource,
                                     java.lang.String sEndsWith)
Ensure that a String ends with a given substring

Parameters:
sSource - Input String
sEndsWith - Substring that the String must end with.
Returns:
If sSource ends with sEndsWith then sSource is returned, else sSource+sEndsWith is returned.

dechomp

public static java.lang.String dechomp(java.lang.String sSource,
                                       java.lang.String sEndsWith)
Ensure that a String does not end with a given substring

Parameters:
sSource - Input String
sEndsWith - Substring that the String must not end with.
Returns:
If sSource does not end with sEndsWith then sSource is returned, else sSource-sEndsWith is returned.

dechomp

public static java.lang.String dechomp(java.lang.String sSource,
                                       char cEndsWith)
Ensure that a String does not end with a given character

Parameters:
sSource - Input String
cEndsWith - Character that the String must not end with.
Returns:
If sSource does not end with sEndsWith then sSource is returned, else sSource-cEndsWith is returned.

substrBetween

public static java.lang.String substrBetween(java.lang.String sSource,
                                             java.lang.String sLowerBound,
                                             java.lang.String sUpperBound)
                                      throws java.lang.StringIndexOutOfBoundsException,
                                             java.lang.NullPointerException
Get substring between two given character sequence

Parameters:
sSource - Source String
sLowerBound - Lower bound character sequence
sUpperBound - Upper bound character sequence
Returns:
Subtring between sLowerBound and sUpperBound or null if either sLowerBound or sUpperBound are not found at sSource
Throws:
java.lang.StringIndexOutOfBoundsException
java.lang.NullPointerException
Since:
4.0

substrAfter

public static java.lang.String substrAfter(java.lang.String sSource,
                                           int iFromIndex,
                                           java.lang.String sSought)
                                    throws java.lang.StringIndexOutOfBoundsException,
                                           java.lang.NullPointerException
Get substring after a given character sequence

Parameters:
sSource - Source String
iFromIndex - Index top start searching character sequence from
sSought - Character sequence sought
Returns:
Substring after sSought character sequence. If source string is empty then return value is always an empty string. If sought substring is empty then return value is the whole source string. If sought substring is not found then return value is null
Throws:
java.lang.StringIndexOutOfBoundsException
java.lang.NullPointerException - is source or sought string is null
Since:
4.0

substrUpTo

public static java.lang.String substrUpTo(java.lang.String sSource,
                                          int iFromIndex,
                                          char cSought)
                                   throws java.lang.StringIndexOutOfBoundsException
Get substring from an index up to next given character

Parameters:
sSource - Source String
iFromIndex - Index top start searching character from
cSought - Character sought
Returns:
Substring between iFromIndex and cSought character
Throws:
java.lang.StringIndexOutOfBoundsException - if cSought character is not found at sSource
Since:
4.0

substrUpTo

public static java.lang.String substrUpTo(java.lang.String sSource,
                                          int iFromIndex,
                                          java.lang.String sSought)
                                   throws java.lang.StringIndexOutOfBoundsException
Get substring from an index up to next given character sequence

Parameters:
sSource - Source String
iFromIndex - Index top start searching character from
sSought - Character sequence sought
Returns:
Substring between iFromIndex and sSought
Throws:
java.lang.StringIndexOutOfBoundsException - if sSought sequence is not found at sSource
Since:
4.0

tokenizeCmdLine

public static java.lang.String[] tokenizeCmdLine(java.lang.String sSource)
                                          throws java.lang.StringIndexOutOfBoundsException

Take an input string and tokenize each command on it

Parameters:
sSource - String to be parsed.
Tokens are separated by spaces. Single or double quotes are allowed for qualifying string literals.
Returns:
String[] Array of tokens. If sSource is null then the return value is null, if sSource is empty then the return value is an array with a single element being it null.
Throws:
java.lang.StringIndexOutOfBoundsException

mapCmdLine

public static java.util.TreeMap mapCmdLine(java.lang.String sSource)
                                    throws java.lang.StringIndexOutOfBoundsException

Take an input string and return a map of commands

Parameters:
sSource - String to be parsed.
The String must be of the form parameter1="value1" parameter2="value2" parameter3="value3"
Map keys will be parameter1,parameter2,parameter3 and map values value1,value2,value3
Returns:
TreeMap A case insensitive map
Throws:
java.lang.StringIndexOutOfBoundsException
Since:
4.0

checkEMail

public static boolean checkEMail(java.lang.String sEMailAddr)
Check that an e-mail address is syntactically valid.

Parameters:
sEMailAddr - e-mail address to check
Returns:
true if e-mail address is syntactically valid.

toHexChars

public static void toHexChars(int val,
                              char[] dst,
                              int dstIndex,
                              int size)

toHexString

public static java.lang.String toHexString(int val,
                                           int size)

toHexString

public static java.lang.String toHexString(byte[] src,
                                           int srcIndex,
                                           int size)
Convert a byte array into its corresponding Hexadecimal String representation

Parameters:
src - Input array
srcIndex - Begin Index
size - Number of bytes to be readed
Returns:
A String with two hexadecimal upper case digits per byte on the input array

toHexString

public static java.lang.String toHexString(byte[] src)
Convert a byte array into its corresponding Hexadecimal String representation

Parameters:
src - Input array
Returns:
A String with two hexadecimal upper case digits per byte on the input array

removeChar

public static java.lang.String removeChar(java.lang.String sInput,
                                          char cRemove)
Remove a character from a String

Parameters:
sInput - Input String
cRemove - Character to be removed
Returns:
The input String without all the occurences of the given character

removeChars

public static java.lang.String removeChars(java.lang.String sInput,
                                           java.lang.String sRemove)
Remove a character set from a String

Parameters:
sInput - Input String
sRemove - A String containing all the characters to be removed from input String
Returns:
The input String without all the characters of sRemove

escapeChars

public static java.lang.String escapeChars(java.lang.String sInput,
                                           java.lang.String sSpecialSet,
                                           char cEsc)
                                    throws java.lang.NullPointerException
Preffixes a set of special characters with an escape character

Parameters:
sInput - String
sSpecialSet - Set of special characters
cEsc - Escape character to be used
Returns:
The input String without all special characters preceded by the escape character for example: if input is "Chicken & ~Egg",the special set is "&~" and escape is '¬' then returned value is "Chicken ¬& ¬~Egg"
Throws:
java.lang.NullPointerException - if sSpecialSet is null
Since:
4.0

round2

public static java.math.BigDecimal round2(java.math.BigDecimal oDec)
Rounds a BigDecimal value to two decimals

Parameters:
oDec - BigDecimal to be rounded
Returns:
BigDecimal If oDec is null then round2 returns null

formatCurrency

public static java.lang.String formatCurrency(java.math.BigDecimal oDec,
                                              java.lang.String sCurrency,
                                              java.lang.String sLanguage,
                                              java.lang.String sCountry)
Format a BigDecimal as a String following the rules for an specific locale

Parameters:
oDec - BigDecimal to be formatted
sCurrency - String ISO 4217 currency code (EUR, USD, GBP, BRL, CNY, etc.)
sLanguage - String lowercase two-letter ISO-639 code
sLocale2 - String uppercase two-letter ISO-3166 code
Returns:
String
See Also:
BSI Currency Code Service (ISO 4217 Maintenance Agency), ISO 4217 currency code list, ISO 639 language codes, ISO 3166 country codes

formatCurrency

public static java.lang.String formatCurrency(java.math.BigDecimal oDec,
                                              java.lang.String sCurrency,
                                              java.lang.String sLanguage)
Format a BigDecimal as a String following the rules for an specific locale

Parameters:
oDec - BigDecimal to be formatted
sCurrency - String ISO 4217 currency code (EUR, USD, GBP, BRL, CNY, etc.)
sLanguage - String lowercase two-letter ISO-639 code
Returns:
String
See Also:
ISO 4217 currency code list, ISO 639 language codes

formatCurrency

public static java.lang.String formatCurrency(java.math.BigDecimal oDec,
                                              java.lang.String sCurrency,
                                              java.util.Locale oLocale)
Format a BigDecimal as a String following the rules for an specific locale

Parameters:
oDec - BigDecimal to be formatted
sCurrency - String ISO 4217 currency code (EUR, USD, GBP, BRL, CNY, etc.)
oLocale - Locale used for formatting
Returns:
String
See Also:
java.util.Locale

getLevenshteinDistance

public static int getLevenshteinDistance(java.lang.String s,
                                         java.lang.String t)

Calculate Levenshtein distance between two strings

The Levenshtein distance is defined as the minimal number of characters you have to replace, insert or delete to transform str1 into str2. The complexity of the algorithm is O(m*n), where n and m are the length of str1 and str2.

Returns:
Levenshtein distance between str1 and str2
Throws:
java.lang.IllegalArgumentException - if either str1 or str2 is null
Since:
4.0
See Also:
http://www.merriampark.com/ldjava.htm

main

public static void main(java.lang.String[] argv)

CASE_INSENSITIVE_MASKCompiled regular expression should be case insensitive
DEFAULT_MASKUse default mask for compile method
EXTENDED_MASKcompiled regular expression should be treated as a Perl5 extended pattern (i.e., a pattern using the /x modifier)
MULTILINE_MASKCompiled regular expression should treat input as having multiple lines
READ_ONLY_MASKResulting Perl5Pattern should be treated as a read only data structure by Perl5Matcher, making it safe to share a single Perl5Pattern instance among multiple threads without needing synchronization
SINGLELINE_MASKCompiled regular expression should treat input as being a single line