| java.lang.Object com.knowgate.misc.Gadgets
Gadgets | final public class Gadgets (Code) | | Miscellaneous functions and utilities.
author: Sergio Montoro Ten version: 2.1 |
Field Summary | |
final public static char[] | HEX_DIGITS |
Constructor Summary | |
public | Gadgets() |
Method Summary | |
public static String | ASCIIEncode(String sStrIn) | public static String | HTMLDencode(String text) | public static String | HTMLEncode(String text) | public static String | URLEncode(String sStr) Return text enconded as an URL. | public static String | XHTMLEncode(String text) | public static boolean | checkEMail(String sEMailAddr) Check that an e-mail address is syntactically valid. | public static String | chomp(String sSource, char cEndsWith) Ensure that a String ends with a given character
Parameters: sSource - Input String Parameters: cEndsWith - Character that the String must end with. | public static String | chomp(String sSource, String sEndsWith) Ensure that a String ends with a given substring
Parameters: sSource - Input String Parameters: sEndsWith - Substring that the String must end with. | public static boolean | contains(String sSource, String sRegExp) | public static int | countOccurrences(String sSource, String sSubStr, int iOptions) | public static String | dechomp(String sSource, String sEndsWith) Ensure that a String does not end with a given substring
Parameters: sSource - Input String Parameters: sEndsWith - Substring that the String must not end with. | public static String | dechomp(String sSource, char cEndsWith) Ensure that a String does not end with a given character
Parameters: sSource - Input String Parameters: cEndsWith - Character that the String must not end with. | public static String | fill(char c, int len) | public static String | formatCurrency(BigDecimal oDec, String sCurrency, String sLanguage, String sCountry) | public static String | formatCurrency(BigDecimal oDec, String sCurrency, String sLanguage) | public static String | formatCurrency(BigDecimal oDec, String sCurrency, Locale oLocale) | public static String | generateUUID() | public static String | getFirstMatchSubStr(String sSource, String sRegExp) | public static int | indexOfIgnoreCase(String sSource, String sSought, int iStartAt) | public static int | indexOfIgnoreCase(String sSource, String sSought) | public String | join(Collection oList, String sDelimiter) | public String | join(String[] aList, String sDelimiter) | public static String | left(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 Parameters: nChars - Number of characters to the left of String to get. | public static String | leftPad(String sSource, char cPad, int nChars) Add padding characters to the left. | public static void | main(String[] argv) | public static boolean | matches(String sSource, String sRegExp) | public static String | removeChar(String sInput, char cRemove) | public static String | removeChars(String sInput, String sRemove) | public static String | replace(String sSource, String sRegExp, String sNewVal) | public static String | replace(String sSource, String sRegExp, String sNewVal, int iOptions) Replace a given pattern on a string with a fixed value
Parameters: sSource - Source String Parameters: sRegExp - Regular Expression to be matched Parameters: sNewVal - New value for replacement Parameters: iOptions - A set of flags giving the compiler instructions on how totreat the regular expression. | public static BigDecimal | round2(BigDecimal oDec) | public static String[] | split(String sInputStr, char cDelimiter) | public static String[] | split(String sInputStr, char[] aDelimiter) | public static String[] | split(String sInputStr, String sDelimiter) | public static String[] | split2(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.
Parameters: sInputStr - String to split Parameters: cDelimiter - Single character to be used as delimiter,the String will be splited on the first occurence of character. | public static String[] | split2(String sInputStr, 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.
Parameters: sInputStr - String to split Parameters: sDelimiter - String to be used as delimiter,the String will be splited on the first occurence of sDelimiter. | public static Collection | splitAsCollection(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. | public static void | toHexChars(int val, char dst, int dstIndex, int size) | public static String | toHexString(int val, int size) | public static String | toHexString(byte[] src, int srcIndex, int size) | public static String | toHexString(byte[] src) | public static String[] | tokenizeCmdLine(String sSource) Take an input string and tokenize each command on it
Parameters: sSource - String to be parsed. Tokens are separated by spaces. |
HEX_DIGITS | final public static char[] HEX_DIGITS(Code) | | |
ASCIIEncode | public static String ASCIIEncode(String sStrIn)(Code) | | Convert an ASCII-8 String to an ASCII-7 String
|
HTMLEncode | public static String HTMLEncode(String text)(Code) | | Return text enconded as HTML.
For example "Tom & Jerry" is encoded as "Tom & Jerry"
Parameters: text - Text to encode HTML-encoded text |
URLEncode | public static String URLEncode(String sStr)(Code) | | Return text enconded as an URL.
For example, "Tom's Bookmarks" is encodes as "Tom%27s%20Bookmarks"
Parameters: sStr - Text to encode URL-encoded text |
XHTMLEncode | public static String XHTMLEncode(String text)(Code) | | Return text enconded as XHTML.
ASCII-7 character are returned as they are,any other character is returned as code;
Parameters: text - String String |
checkEMail | public static boolean checkEMail(String sEMailAddr)(Code) | | Check that an e-mail address is syntactically valid.
Parameters: sEMailAddr - e-mail address to check true if e-mail address is syntactically valid. |
chomp | public static String chomp(String sSource, char cEndsWith)(Code) | | Ensure that a String ends with a given character
Parameters: sSource - Input String Parameters: cEndsWith - Character that the String must end with. If sSource ends with cEndsWith then sSource is returned,else sSource+cEndsWith is returned. |
chomp | public static String chomp(String sSource, String sEndsWith)(Code) | | Ensure that a String ends with a given substring
Parameters: sSource - Input String Parameters: sEndsWith - Substring that the String must end with. If sSource ends with sEndsWith then sSource is returned,else sSource+sEndsWith is returned. |
contains | public static boolean contains(String sSource, String sRegExp) throws MalformedPatternException(Code) | | Check whether or not a String contains a regular expression
Parameters: sSource - String Source Parameters: sRegExp - String Regular Expression 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 |
countOccurrences | public static int countOccurrences(String sSource, String sSubStr, int iOptions) throws MalformedPatternException(Code) | | Count occurrences of a given substring
Parameters: sSource - String Source Parameters: sSubStr - Substring to be searched (no wildcards) Parameters: iOptions - int org.apache.oro.text.regex.Perl5Compiler.CASE_INSENSITIVE_MASK for case insensitive search 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. |
dechomp | public static String dechomp(String sSource, String sEndsWith)(Code) | | Ensure that a String does not end with a given substring
Parameters: sSource - Input String Parameters: sEndsWith - Substring that the String must not end with. If sSource does not end with sEndsWith then sSource is returned,else sSource-sEndsWith is returned. |
dechomp | public static String dechomp(String sSource, char cEndsWith)(Code) | | Ensure that a String does not end with a given character
Parameters: sSource - Input String Parameters: cEndsWith - Character that the String must not end with. If sSource does not end with sEndsWith then sSource is returned,else sSource-cEndsWith is returned. |
formatCurrency | public static String formatCurrency(BigDecimal oDec, String sCurrency, String sLanguage)(Code) | | Format a BigDecimal as a String following the rules for an specific locale
Parameters: oDec - BigDecimal to be formatted Parameters: sCurrency - String ISO 4217 currency code (EUR, USD, GBP, BRL, CNY, etc.) Parameters: sLanguage - String lowercase two-letter ISO-639 code String See Also: ISO 4217 currency code list See Also: ISO 639 language codes |
formatCurrency | public static String formatCurrency(BigDecimal oDec, String sCurrency, Locale oLocale)(Code) | | Format a BigDecimal as a String following the rules for an specific locale
Parameters: oDec - BigDecimal to be formatted Parameters: sCurrency - String ISO 4217 currency code (EUR, USD, GBP, BRL, CNY, etc.) Parameters: oLocale - Locale used for formatting String See Also: java.util.Locale |
generateUUID | public static String generateUUID()(Code) | | Generate an universal unique identifier
An hexadecimal string of 32 characters,created using the machine IP address, current system date, a randon numberand a sequence. |
getFirstMatchSubStr | public static String getFirstMatchSubStr(String sSource, String sRegExp) throws MalformedPatternException(Code) | | Get the first substring that matches the given regular expression
Parameters: sSource - String Source Parameters: sRegExp - String Regular Expression 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 |
indexOfIgnoreCase | public static int indexOfIgnoreCase(String sSource, String sSought, int iStartAt)(Code) | | Get index of a substring inside another string
Parameters: sSource - String String to be scanned Parameters: sSought - Substring to be sought Parameters: iStartAt - int Index to start searching from int Start index of substring or -1 if not found |
indexOfIgnoreCase | public static int indexOfIgnoreCase(String sSource, String sSought)(Code) | | Get index of a substring inside another string
Parameters: sSource - String String to be scanned Parameters: sSought - Substring to be sought int Start index of substring or -1 if not found |
join | public String join(Collection oList, String sDelimiter)(Code) | | Join a Collection into a String
Parameters: oList - Collection to join Parameters: sDelimiter - Delimiter for elements in resulting String List joined as a String |
join | public String join(String[] aList, String sDelimiter)(Code) | | Join an Array into a String
Parameters: aList - Array to join Parameters: sDelimiter - Delimiter for elements in resulting String List joined as a String since: v3.0 |
left | public static String left(String sSource, int nChars)(Code) | | 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 Parameters: nChars - Number of characters to the left of String to get. Left characters of sSource String or null if sSource is null. |
leftPad | public static String leftPad(String sSource, char cPad, int nChars)(Code) | | Add padding characters to the left.
Parameters: sSource - Input String Parameters: cPad - Padding character Parameters: nChars - Final length of the padded string Padded String |
matches | public static boolean matches(String sSource, String sRegExp) throws MalformedPatternException(Code) | | Check whether or not a String matches a regular expression
Parameters: sSource - String Source Parameters: sRegExp - String Regular Expression 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 |
removeChar | public static String removeChar(String sInput, char cRemove)(Code) | | Remove a character from a String
Parameters: sInput - Input String Parameters: cRemove - Character to be removed The input String without all the occurences of the given character |
removeChars | public static String removeChars(String sInput, String sRemove)(Code) | | Remove a character set from a String
Parameters: sInput - Input String Parameters: sRemove - A String containing all the characters to be removed from input String The input String without all the characters of sRemove |
replace | public static String replace(String sSource, String sRegExp, String sNewVal) throws MalformedPatternException(Code) | | Replace a given pattern on a string with a fixed value
Parameters: sSource - Source String Parameters: sRegExp - Regular Expression to be matched Parameters: sNewVal - New value for replacement throws: MalformedPatternException - See Also: http://www.savarese.org/oro/docs/OROMatcher/Syntax.html |
replace | public static String replace(String sSource, String sRegExp, String sNewVal, int iOptions) throws MalformedPatternException(Code) | | Replace a given pattern on a string with a fixed value
Parameters: sSource - Source String Parameters: sRegExp - Regular Expression to be matched Parameters: sNewVal - New value for replacement Parameters: iOptions - A set of flags giving the compiler instructions on how totreat the regular expression. The flags are a logical OR of any number ofthe 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 | throws: MalformedPatternException - See Also: http://www.savarese.org/oro/docs/OROMatcher/Syntax.html
round2 | public static BigDecimal round2(BigDecimal oDec)(Code) | | Rounds a BigDecimal value to two decimals
Parameters: oDec - BigDecimal to be rounded BigDecimal If oDec is null then round2 returns null |
split | public static String[] split(String sInputStr, char cDelimiter) throws NullPointerException(Code) | | 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 Parameters: cDelimiter - Character Delimiter An array with the splitted substrings throws: NullPointerException - If sInputStr is null |
split | public static String[] split(String sInputStr, char[] aDelimiter) throws NullPointerException(Code) | | Split a String using any of the given characters as delimiter
Parameters: aDelimiter - Character Delimiter Array An array with the splitted substrings throws: NullPointerException - If sInputStr is null or aDelimiter is null |
split | public static String[] split(String sInputStr, String sDelimiter) throws NullPointerException(Code) | | 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 Parameters: sDelimiter - Substring Delimiter (no regular expressions allowed) An array with the splitted substrings throws: NullPointerException - If sInputStr is null |
split2 | public static String[] split2(String sInputStr, char cDelimiter) throws NullPointerException(Code) | | 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 Parameters: cDelimiter - Single character to be used as delimiter,the String will be splited on the first occurence of character. If cDelimiter is not found, or cDelimiter if found as the firstcharacter of sInputStr or cDelimiter if found as the last character ofsInputStr then an array with a single String element is returned. IfcDelimiter is found somewhere in the middle of sInputStr then an arraywith 2 elements is returned. throws: NullPointerException - If sInputStr is null |
split2 | public static String[] split2(String sInputStr, String sDelimiter) throws NullPointerException(Code) | | 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 Parameters: sDelimiter - String to be used as delimiter,the String will be splited on the first occurence of sDelimiter. If sDelimiter is not found, or sInputStr starts with sDelimiter orsInputStr ends with sDelimiter then an array with a single String elementis returned. If sDelimiter is found somewhere in the middle of sInputStrthen an array with 2 elements is returned. throws: NullPointerException - If sInputStr is null |
splitAsCollection | public static Collection splitAsCollection(String sInputStr, char cDelimiter) throws NullPointerException(Code) | | 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 Parameters: cDelimiter - Character Delimiter A LinkedList splitted substrings throws: NullPointerException - If sInputStr is null |
toHexChars | public static void toHexChars(int val, char dst, int dstIndex, int size)(Code) | | |
toHexString | public static String toHexString(int val, int size)(Code) | | |
toHexString | public static String toHexString(byte[] src, int srcIndex, int size)(Code) | | Convert a byte array into its corresponding Hexadecimal String representation
Parameters: src - Input array Parameters: srcIndex - Begin Index Parameters: size - Number of bytes to be readed A String with two hexadecimal upper case digits per byte on the input array |
toHexString | public static String toHexString(byte[] src)(Code) | | Convert a byte array into its corresponding Hexadecimal String representation
Parameters: src - Input array A String with two hexadecimal upper case digits per byte on the input array |
tokenizeCmdLine | public static String[] tokenizeCmdLine(String sSource) throws StringIndexOutOfBoundsException(Code) | | 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. 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: StringIndexOutOfBoundsException - |
|
|
|