|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.knowgate.misc.Gadgets
public final class Gadgets
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 |
|---|
public static final char[] HEX_DIGITS
| Constructor Detail |
|---|
public Gadgets()
| Method Detail |
|---|
public static java.lang.String generateUUID()
public static java.lang.String generateRandomId(int iLength,
java.lang.String sCharset,
byte byCategory)
throws java.lang.StringIndexOutOfBoundsException
iLength - int Length of identifier to be generated /between 1 and 4096 characters)sCharset - String Character set to be used for generating the identifierbyCategory - 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
java.lang.StringIndexOutOfBoundsExceptionpublic 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;
text - String
public static java.lang.String HTMLEncode(java.lang.String text)
Return text enconded as HTML.
For example "Tom & Jerry" is encoded as "Tom & Jerry"
text - Text to encode
public static java.lang.String HTMLDencode(java.lang.String text)
public static java.lang.String URLEncode(java.lang.String sStr)
sStr - Text to encode
public static java.lang.String ASCIIEncode(java.lang.String sStrIn)
public static java.lang.String accentsToPosixRegEx(java.lang.String sText)
public static java.lang.String[] split2(java.lang.String sInputStr,
char cDelimiter)
throws java.lang.NullPointerException
sInputStr - String to splitcDelimiter - Single character to be used as delimiter,
the String will be splited on the first occurence of character.
java.lang.NullPointerException - If sInputStr is null
public static java.lang.String[] split2(java.lang.String sInputStr,
java.lang.String sDelimiter)
throws java.lang.NullPointerException
sInputStr - String to splitsDelimiter - String to be used as delimiter,
the String will be splited on the first occurence of sDelimiter.
java.lang.NullPointerException - If sInputStr is null
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.
sInputStr - String to splitcDelimiter - Character Delimiter
java.lang.NullPointerException - If sInputStr is null
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
aDelimiter - Character Delimiter Array
java.lang.NullPointerException - If sInputStr is null or aDelimiter is null
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.
sInputStr - String to splitsDelimiter - Substring Delimiter (no regular expressions allowed)
java.lang.NullPointerException - If sInputStr is null
public static java.lang.String join(java.util.Collection oList,
java.lang.String sDelimiter)
oList - Collection to joinsDelimiter - Delimiter for elements in resulting String
public static java.lang.String join(java.lang.String[] aList,
java.lang.String sDelimiter)
aList - Array to joinsDelimiter - Delimiter for elements in resulting String
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.
sInputStr - String to splitcDelimiter - Character Delimiter
java.lang.NullPointerException - If sInputStr is null
public static int search(java.lang.String[] aList,
java.lang.String sSought)
aList - Array of StringssSought - String sought
public static int search(int[] aList,
int iSought)
aList - Array of intiSought - Value sought
public static int indexOfIgnoreCase(java.lang.String sSource,
java.lang.String sSought,
int iStartAt)
sSource - String String to be scannedsSought - Substring to be soughtiStartAt - int Index to start searching from
public static int indexOfIgnoreCase(java.lang.String sSource,
java.lang.String sSought)
sSource - String String to be scannedsSought - Substring to be sought
public static java.lang.String fill(char c,
int len)
throws java.lang.IndexOutOfBoundsException
c - Character for fillinglen - Number of characters
java.lang.IndexOutOfBoundsException - if len<0
public static java.lang.String repeat(java.lang.String sSubStr,
int nTimes)
throws java.lang.IndexOutOfBoundsException
sSubStr - Substring to be repeatednTimes - Number of times to repeat
java.lang.IndexOutOfBoundsException - if nTimes<0
public static boolean matches(java.lang.String sSource,
java.lang.String sRegExp)
throws MalformedPatternException
sSource - String SourcesRegExp - String Regular Expression
MalformedPatternExceptionhttp://www.savarese.org/oro/docs/OROMatcher/Syntax.html
public static boolean contains(java.lang.String sSource,
java.lang.String sRegExp)
throws MalformedPatternException
sSource - String SourcesRegExp - String Regular Expression
MalformedPatternExceptionhttp://www.savarese.org/oro/docs/OROMatcher/Syntax.html
public static java.lang.String getFirstMatchSubStr(java.lang.String sSource,
java.lang.String sRegExp)
throws MalformedPatternException
sSource - String SourcesRegExp - String Regular Expression
MalformedPatternExceptionhttp://jakarta.apache.org/oro/api/org/apache/oro/text/regex/Perl5Matcher.html
public static java.lang.String replace(java.lang.String sSource,
char cSought,
java.lang.String sNewVal)
throws java.lang.NullPointerException
sSource - Source StringcSought - Character to be soughtsNewVal - New value for character,
if it is an empty string "" then the sought character
is just removed from the source string
java.lang.NullPointerException - if sNewVal is null
public static java.lang.String replace(java.lang.String sSource,
java.lang.String sRegExp,
java.lang.String sNewVal)
throws MalformedPatternException
sSource - Source StringsRegExp - Regular Expression to be matchedsNewVal - New value for replacement
MalformedPatternException
java.lang.NullPointerException - if either sRegExp or NewVal is nullhttp://www.savarese.org/oro/docs/OROMatcher/Syntax.html
public static java.lang.String replace(java.lang.String sSource,
java.lang.String sRegExp,
java.lang.String sNewVal,
int iOptions)
throws MalformedPatternException
sSource - Source StringsRegExp - Regular Expression to be matchedsNewVal - New value for replacementiOptions - 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.| CASE_INSENSITIVE_MASK | Compiled regular expression should be case insensitive | ||||||||
| DEFAULT_MASK | Use default mask for compile method | ||||||||
| EXTENDED_MASK | compiled regular expression should be treated as a Perl5 extended pattern (i.e., a pattern using the /x modifier) | ||||||||
| MULTILINE_MASK | Compiled regular expression should treat input as having multiple lines | ||||||||
| READ_ONLY_MASK | Resulting 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_MASK | Compiled regular expression should treat input as being a single line | ||||||||
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||