ariba.util.core
Class StringUtil

java.lang.Object
  extended by ariba.util.core.StringUtil

public final class StringUtil
extends java.lang.Object

String Utilities. These are utilities for working with strings.


Nested Class Summary
static class StringUtil.SearchResult
          Small struct class that captures the result of search for a string within some other unidentified string or stream.
 
Method Summary
static java.lang.String bit(int pint)
          Create the appropriate bit string for use in a LIKE clause for a string bit mask.
static java.lang.String bitClear(java.lang.String value, int pos)
          Bit Clear - clear the bit with the given position in the given string Passing pos = 0 and value = "101" would yield "100".
static java.lang.String bitSet(java.lang.String value, int pos)
          Bit Set - sets the bit with the given position in the given string Passing pos = 0 and value = "100" would yield "101".
static boolean bitTest(java.lang.String value, int pos)
          Bit Test - test the bit for the given position in the given string Passing pos = 0 and value = "100" would yield false Passing pos = 1 and value = "100" would yield false Passing pos = 2 and value = "100" would yield true
static int calcTruncateSize(java.lang.String label, int maxSize, int numLines)
          Returns the ideal size to truncate based on the max number characters to display by trying to fit the most words / characters before truncation.
static java.lang.String capitalizeFirstChar(java.lang.String string)
          Returns string with the first character upper-cased.
static boolean charsEqualString(char[] chars, java.lang.String s)
          Compare a character array to a string without allocating a temporary string.
static java.lang.String compressSpaces(java.lang.String s)
          Replace all repeating instances of a space in a String with a single space.
static boolean contains(java.lang.String string, java.lang.String phrase)
          Case insensitive string search for a substring.
static long convertFromBase26(java.lang.String numberInBase26)
          Convenience method that converts a number in base 26 (as might have been constructed by convertToBase26(long)) back into an integer.
static java.lang.String convertToBase26(long value)
          Returns the Base26 representation of the provided integer; where 0 = a, 25 = z, 26 = ba, etc.
static java.lang.String[] delimitedStringToArray(java.lang.String str, char delimiter)
          Tokenize a String with a specified separator character and return an array.
static boolean endsWith(java.lang.CharSequence s, java.lang.CharSequence sub)
          Evaluates if the first CharSequence ends with the second.
static boolean endsWithAny(java.lang.CharSequence s, java.lang.CharSequence... subs)
          Evaluate if hte first CharSequence ends with any of the following CharSequences.
static boolean equalsIgnoreCase(java.lang.String one, java.lang.String two)
          Compares if two strings are equal or not.
static java.lang.String escapeRegEx(java.lang.String regex)
          Escapes metacharacters in a regex into literals.
static java.lang.String fastJoin(java.util.Collection collection, java.lang.String joinString)
          Joins collection of elements with a string between each pair of elements.
static java.lang.String fastJoin(java.util.List vector, java.lang.String joinString)
          Joins vector of elements with a string between each pair of elements.
static byte[] getBytesUTF8(java.lang.String string)
           
static java.lang.String getStringUTF8(byte[] bytes)
           
static int indexOf(java.lang.String string, java.lang.String[] substrings)
          Search for any of an array of substrings inside of the specified string.
static java.lang.String intern(java.lang.String source)
           
static boolean is7bitAscii(char c)
          Specifies whether the given character is a 7-ascii character
static boolean isAllDigits(java.lang.String string)
          Check if a String is composed entirely of digits using Character.isDigit
static boolean isJavaIdentifier(java.lang.String identifier)
          Check if a string is a legal java identifier.
static boolean isValidEmailLocalPart(java.lang.String string)
          Validate the local part of an email address per RFC-822
static boolean isValidURIPart(java.lang.String string, boolean allowForExtendedMarks)
          Specifies whether the given String is a valid URI part.
static java.lang.String join(java.util.List vector, java.lang.String joinString)
          Joins vector of elements with a string between each pair of elements.
static java.lang.String join(java.lang.Object[] objects, java.lang.String joinString)
          Joins array of elements with a string between each pair of elements.
static java.lang.String join(java.lang.Object[] objects, java.lang.String joinString, int index, int length)
          Joins a sub-array of the given objects array elements with a string between each pair of elements.
static boolean nullOrEmptyOrBlankString(java.lang.String string)
          Determine if a string is null or empty or entirely spaces.
static boolean nullOrEmptyString(java.lang.String string)
          Determine if a String is null or empty.
static int occurs(java.lang.String[] array, java.lang.String string)
          Count the number of occurrences of a string in an array of Strings.
static int occurs(java.lang.String str, char ch)
          Count the number of occurrences of a character in a string.
static int occurs(java.lang.String str, java.lang.String substr)
          Count the number of occurrences of a substring in a string.
static java.lang.String[] parseMatchingParentheses(java.lang.String str)
          Parse the input String into two components separated by matching left and right parentheses.
static java.lang.String printSecret(java.lang.String value)
           
static java.lang.String removeCarriageReturns(java.lang.String string)
          Removes the newlines and carriage returns from string and returns the resultant string.
static java.lang.String[] removeDuplicates(java.lang.String[] s)
          To remove duplicate elements from a String array s
static java.lang.String[] removeDuplicates(java.lang.String[] s, StringArray duplicateArray)
          To remove duplicate elements from a String array s
static java.lang.String removeLeadingSlashIfAny(java.lang.String path)
          Removes the leading slash from the given String.
static java.lang.String removeTrailingSlashIfAny(java.lang.String path)
          Removes the trailing slash from the given String.
static java.lang.String replaceCharByChar(java.lang.String string, char marker, char replace)
          Replace all occurrences of a character in a String with another character.
static java.lang.String replaceCharByString(java.lang.String string, char marker, java.lang.String replace)
          Replace all occurrences of a character in a String with a String.
static StringUtil.SearchResult search(java.lang.String toSearch, int fromIdx, java.util.Collection toFind)
          Searches for the first one of any of the supplied strings
static java.lang.String separateAtCapitalization(java.lang.String string)
           
static java.lang.String separateAtCapitalization(java.lang.String string, char separationChar)
           
static java.util.List splitWithQuotes(java.lang.String str, boolean keepQuotes)
          Splits a string up into chunks using a whitespace delimiter.
static boolean startsWithIgnoreCase(java.lang.String string, java.lang.String other)
          Check if a string starts with a specific substring in a case insensitive manner.
static java.lang.String strcat(java.lang.String[] elems)
           
static java.lang.String strcat(java.lang.String s1, java.lang.String s2)
           
static java.lang.String strcat(java.lang.String s1, java.lang.String s2, java.lang.String s3)
           
static java.lang.String strcat(java.lang.String s1, java.lang.String s2, java.lang.String s3, java.lang.String s4)
           
static java.lang.String strcat(java.lang.String s1, java.lang.String s2, java.lang.String s3, java.lang.String s4, java.lang.String s5)
           
static java.lang.String strcat(java.lang.String s1, java.lang.String s2, java.lang.String s3, java.lang.String s4, java.lang.String s5, java.lang.String s6)
           
static java.lang.String strcat(java.lang.String s1, java.lang.String s2, java.lang.String s3, java.lang.String s4, java.lang.String s5, java.lang.String s6, java.lang.String s7)
           
static java.lang.String strcat(java.lang.String s1, java.lang.String s2, java.lang.String s3, java.lang.String s4, java.lang.String s5, java.lang.String s6, java.lang.String s7, java.lang.String s8)
           
static java.lang.String strcat(java.lang.String s1, java.lang.String s2, java.lang.String s3, java.lang.String s4, java.lang.String s5, java.lang.String s6, java.lang.String s7, java.lang.String s8, java.lang.String s9)
           
static int stringArrayIndex(java.lang.String[] keys, java.lang.String key)
          Performs a binary search on a sorted string array.
static boolean stringMatchesPattern(java.lang.String str, java.lang.String pattern)
          Checks if a string matches a perl 5 pattern.
static java.util.List stringToStringsListUsingBreakChars(java.lang.String s, java.lang.String breakChars)
          Tokenize a string separated by any separator characters into a List.
static java.lang.String substring(java.lang.String string, int beginIndex, int endIndex)
          Returns the substring of string from beginIndex (inclusive) to endIndex, exclusive.
static java.lang.String trailing(java.lang.String string, int length)
          Returns the trailing part of string up to a max of length characters.
static java.lang.String truncate(java.lang.String string, int length)
          Returns this string truncated to a max of length characters.
static int unorderedStringArrayIndex(java.lang.String[] keys, java.lang.String key)
          Search an unsorted array of strings.
static int unorderedStringArrayIndexIdentical(java.lang.String[] keys, java.lang.String key)
          Search an unsorted array of strings.
static java.lang.String wrap(java.lang.String string, java.lang.String lineSeparator, int wrapLength)
          Return the string argument with the lineSeparator inserted every wrapLength- characters.
static java.lang.String wrapHTML(java.lang.String string, int wrapLength)
          Return the string argument with "
" tag inserted every wrapLength- characters.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

nullOrEmptyString

public static boolean nullOrEmptyString(java.lang.String string)
Determine if a String is null or empty.

Parameters:
string - a String object to check
Returns:
true if string is null or empty, false otherwise

nullOrEmptyOrBlankString

public static boolean nullOrEmptyOrBlankString(java.lang.String string)
Determine if a string is null or empty or entirely spaces.

Parameters:
string - a String object to check
Returns:
true if string is null, empty, or all spaces; false otherwise

capitalizeFirstChar

public static java.lang.String capitalizeFirstChar(java.lang.String string)
Returns string with the first character upper-cased. If string is already uppercased or if it is null or less than one in length, the passed-in value is returned.

Returns:
string with the first character upper-cased

separateAtCapitalization

public static java.lang.String separateAtCapitalization(java.lang.String string)

separateAtCapitalization

public static java.lang.String separateAtCapitalization(java.lang.String string,
                                                        char separationChar)

stringArrayIndex

public static final int stringArrayIndex(java.lang.String[] keys,
                                         java.lang.String key)
Performs a binary search on a sorted string array.

Parameters:
keys - a sorted array of string keys to search
key - a key to search for
Returns:
the index of the key in keys, or -1 if it's not found.

intern

public static java.lang.String intern(java.lang.String source)

stringMatchesPattern

public static boolean stringMatchesPattern(java.lang.String str,
                                           java.lang.String pattern)
Checks if a string matches a perl 5 pattern. See: org.apache.oro.text.perl.Perl5Util.match() example: stringMatchesPattern("foo", "/f.o/") returns true.


unorderedStringArrayIndexIdentical

public static final int unorderedStringArrayIndexIdentical(java.lang.String[] keys,
                                                           java.lang.String key)
Search an unsorted array of strings.

Parameters:
keys - an array of string keys to search
key - a key to search for using the == operator
Returns:
the index of the key in keys, or -1 if it's not found.

unorderedStringArrayIndex

public static final int unorderedStringArrayIndex(java.lang.String[] keys,
                                                  java.lang.String key)
Search an unsorted array of strings.

Parameters:
keys - an array of string keys to search
key - a key to search for using the equals() method
Returns:
the index of the key in keys, or -1 if it's not found.

delimitedStringToArray

public static java.lang.String[] delimitedStringToArray(java.lang.String str,
                                                        char delimiter)
Tokenize a String with a specified separator character and return an array.

Takes a string in the form "Description.Price.Amount" with a delimiter of '.' and turns it into an array of strings:

        path[0] = "Description"
        path[1] = "Price"
        path[2] = "Amount"
        

Parameters:
str - a string to tokenize
delimiter - the delimiter to use when tokenizing
Returns:
an array of Strings containing each substring but excluding the delimiter character
See Also:
ListUtil.delimitedStringToList(java.lang.String, char)

occurs

public static int occurs(java.lang.String str,
                         char ch)
Count the number of occurrences of a character in a string.

Parameters:
str - the String to count in
ch - the character to count the occurrences of
Returns:
the number of times the character ch occurs in the string str.

occurs

public static int occurs(java.lang.String str,
                         java.lang.String substr)
Count the number of occurrences of a substring in a string.

Parameters:
str - the String to count in
substr - the substring to count the occurrences of
Returns:
the number of times the String substr occurs in the string str. Throws a FatalAssertionException if substr is an empty string.

occurs

public static int occurs(java.lang.String[] array,
                         java.lang.String string)
Count the number of occurrences of a string in an array of Strings.

Parameters:
array - an array of Strings to search in. There may not be null elements in the array.
string - the String to match against
Returns:
the number of times the String string occurs in the String array array.

contains

public static boolean contains(java.lang.String string,
                               java.lang.String phrase)
Case insensitive string search for a substring.

Parameters:
string - the String to search in
phrase - the String to search for
Returns:
true if phrase is found anywhere within string, ignoring case; false otherwise. Returns true if phrase is empty.

indexOf

public static int indexOf(java.lang.String string,
                          java.lang.String[] substrings)
Search for any of an array of substrings inside of the specified string.

Parameters:
string - the String to search in
substrings - the strings to search for
Returns:
the index of the first substring that is found inside the string or -1 if the string is not found.

replaceCharByChar

public static java.lang.String replaceCharByChar(java.lang.String string,
                                                 char marker,
                                                 char replace)
Replace all occurrences of a character in a String with another character. Replaces each occurrence of marker in the string string with the character replace.

Parameters:
string - the string to do do the replacing on. If null or empty string, the string is simply returned.
marker - the character to remove
replace - the character to replace the removed character marker with
Returns:
a string with all occurrences of marker replaced by replace

replaceCharByString

public static java.lang.String replaceCharByString(java.lang.String string,
                                                   char marker,
                                                   java.lang.String replace)
Replace all occurrences of a character in a String with a String. Replaces each occurrence of marker in the string string with the String replace.

Parameters:
string - the string to do do the replacing on. If null or empty string, the string is simply returned.
marker - the character to remove
replace - the String that will replace the removed marker. If an empty string or null is passed, any occurrences of the marker are removed from the initial string.
Returns:
a string with all occurrences of marker replaced by replace

compressSpaces

public static java.lang.String compressSpaces(java.lang.String s)
Replace all repeating instances of a space in a String with a single space. Replaces each repeating occurrence of the space character in the string string with exactly one space character.

Parameters:
s - the string to be compressed
Returns:
a string with all repeating occurrences of the space character replaced with a single space

charsEqualString

public static boolean charsEqualString(char[] chars,
                                       java.lang.String s)
Compare a character array to a string without allocating a temporary string.

Parameters:
chars - the characters to check against the String
s - the string to compare to the characters
Returns:
true if the char[] array chars would be equal to the String s were the char[] array to be a String; false is returned otherwise

endsWith

public static boolean endsWith(java.lang.CharSequence s,
                               java.lang.CharSequence sub)
Evaluates if the first CharSequence ends with the second. If both strings are null, then the substring is considered to be a substring of the search string.

Parameters:
s - The search space.
sub - The substring to evaluate.
Returns:
True when s ends with sub or both values are null.

endsWithAny

public static boolean endsWithAny(java.lang.CharSequence s,
                                  java.lang.CharSequence... subs)
Evaluate if hte first CharSequence ends with any of the following CharSequences. The string null is considered to contain null.

Parameters:
s - The search space.
subs - The substrings to evaluate.
Returns:
True when s ends with at least one sub or both values are null.

stringToStringsListUsingBreakChars

public static java.util.List stringToStringsListUsingBreakChars(java.lang.String s,
                                                                java.lang.String breakChars)
Tokenize a string separated by any separator characters into a List. Breaks up the specified string s into lines, and returns all lines in a vector. Blank lines may be optionally ignored.

Parameters:
s - the String to tokenize
breakChars - a string containing all characters to use as separator characters for the tokenize
Returns:
a List of the substrings, excluding the breakChars.

substring

public static java.lang.String substring(java.lang.String string,
                                         int beginIndex,
                                         int endIndex)
Returns the substring of string from beginIndex (inclusive) to endIndex, exclusive.

This function is "safe" in the sense that it will bound beginIndex and endIndex appropriately so that no exceptions will be thrown. E.g. if beginIndex is less than zero, the zero index will be used for the substring instead.

Parameters:
string - the string to substring
beginIndex - the beginning index, inclusive
endIndex - the end index, exclusive
Returns:
the substring'ed string or null if string is null

truncate

public static java.lang.String truncate(java.lang.String string,
                                        int length)
Returns this string truncated to a max of length characters.

Parameters:
string - the string to truncate
length - the length of the truncated string
Returns:
the truncated string or null if string is null

trailing

public static java.lang.String trailing(java.lang.String string,
                                        int length)
Returns the trailing part of string up to a max of length characters.

Parameters:
string - the string to get the trailing part of
length - the length of the truncated string
Returns:
the truncated string or null if string is null

join

public static java.lang.String join(java.lang.Object[] objects,
                                    java.lang.String joinString)
Joins array of elements with a string between each pair of elements.

Parameters:
objects - an array of Objects each which will be toStringed.
joinString - a string to separate each pair of elements, if null the empty string is assumed
Returns:
a string, created by joining the contents of the object array, separated by the joinString

join

public static java.lang.String join(java.lang.Object[] objects,
                                    java.lang.String joinString,
                                    int index,
                                    int length)
                             throws java.lang.IndexOutOfBoundsException
Joins a sub-array of the given objects array elements with a string between each pair of elements. The sub-array is specified by the index offset and the length.

Range checking is delegated to the native access provided when accessing array elements.

Parameters:
objects - an array of Objects each which will be toStringed.
joinString - a string to separate each pair of elements, if null the empty string is assumed
index - the index within the array at which to begin the join of the elements; should be >= 0 and <= objects.length. (Note that if index == objects.length, length must equal 0 in order that an exception will not be thrown.)
length - the number of elements within the array to join together; should satisfy index + length <= objects.length
Returns:
a string, created by joining the contents of the object sub-array, separated by the joinString
Throws:
java.lang.IndexOutOfBoundsException - if bounds specified lead to access outside the bounds of the objects array

fastJoin

public static java.lang.String fastJoin(java.util.List vector,
                                        java.lang.String joinString)
Joins vector of elements with a string between each pair of elements.

Parameters:
vector - a vector of Objects each which will be toStringed.
joinString - a string to separate each pair of elements.
Returns:
a string, created by joining the contents of the List, separated by the joinString

fastJoin

public static java.lang.String fastJoin(java.util.Collection collection,
                                        java.lang.String joinString)
Joins collection of elements with a string between each pair of elements.

Parameters:
collection - a collection of Objects each which will be toStringed.
joinString - a string to separate each pair of elements.
Returns:
a string, created by joining the contents of the List, separated by the joinString

join

public static java.lang.String join(java.util.List vector,
                                    java.lang.String joinString)
Joins vector of elements with a string between each pair of elements. This will invoke formatters to format each object.

Parameters:
vector - a vector of Objects each which will be formatted using the formatters.
joinString - a string to separate each pair of elements.
Returns:
a string, created by joining the contents of the vector, separated by the joinString. The vector contents are formatted by the Formatter class.

isJavaIdentifier

public static boolean isJavaIdentifier(java.lang.String identifier)
Check if a string is a legal java identifier.

Parameters:
identifier - The string to check
Returns:
true if identifier is legal, false otherwise. If identifier is null or empty, it is considered invalid

startsWithIgnoreCase

public static boolean startsWithIgnoreCase(java.lang.String string,
                                           java.lang.String other)
Check if a string starts with a specific substring in a case insensitive manner. Similar to String.startsWith but ignores case.

Parameters:
string - the string to search in
other - the string to check for
Returns:
true if the first characters of string are equal to the string other in a case insensitive comparison; false otherwise. Returns true if other is an empty string.
See Also:
String.startsWith(java.lang.String, int), String.regionMatches(boolean, int, String, int, int)

isAllDigits

public static boolean isAllDigits(java.lang.String string)
Check if a String is composed entirely of digits using Character.isDigit

Parameters:
string - the String to check
Returns:
true if string is made entirely up of digits or is empty, false otherwise.
See Also:
Character.isDigit(char)

bitSet

public static final java.lang.String bitSet(java.lang.String value,
                                            int pos)
Bit Set - sets the bit with the given position in the given string Passing pos = 0 and value = "100" would yield "101".


bitClear

public static final java.lang.String bitClear(java.lang.String value,
                                              int pos)
Bit Clear - clear the bit with the given position in the given string Passing pos = 0 and value = "101" would yield "100".


bitTest

public static final boolean bitTest(java.lang.String value,
                                    int pos)
Bit Test - test the bit for the given position in the given string Passing pos = 0 and value = "100" would yield false Passing pos = 1 and value = "100" would yield false Passing pos = 2 and value = "100" would yield true


bit

public static final java.lang.String bit(int pint)
Create the appropriate bit string for use in a LIKE clause for a string bit mask.


strcat

public static java.lang.String strcat(java.lang.String s1,
                                      java.lang.String s2)

strcat

public static java.lang.String strcat(java.lang.String s1,
                                      java.lang.String s2,
                                      java.lang.String s3)

strcat

public static java.lang.String strcat(java.lang.String s1,
                                      java.lang.String s2,
                                      java.lang.String s3,
                                      java.lang.String s4)

strcat

public static java.lang.String strcat(java.lang.String s1,
                                      java.lang.String s2,
                                      java.lang.String s3,
                                      java.lang.String s4,
                                      java.lang.String s5)

strcat

public static java.lang.String strcat(java.lang.String s1,
                                      java.lang.String s2,
                                      java.lang.String s3,
                                      java.lang.String s4,
                                      java.lang.String s5,
                                      java.lang.String s6)

strcat

public static java.lang.String strcat(java.lang.String s1,
                                      java.lang.String s2,
                                      java.lang.String s3,
                                      java.lang.String s4,
                                      java.lang.String s5,
                                      java.lang.String s6,
                                      java.lang.String s7)

strcat

public static java.lang.String strcat(java.lang.String s1,
                                      java.lang.String s2,
                                      java.lang.String s3,
                                      java.lang.String s4,
                                      java.lang.String s5,
                                      java.lang.String s6,
                                      java.lang.String s7,
                                      java.lang.String s8)

strcat

public static java.lang.String strcat(java.lang.String s1,
                                      java.lang.String s2,
                                      java.lang.String s3,
                                      java.lang.String s4,
                                      java.lang.String s5,
                                      java.lang.String s6,
                                      java.lang.String s7,
                                      java.lang.String s8,
                                      java.lang.String s9)

strcat

public static java.lang.String strcat(java.lang.String[] elems)

removeDuplicates

public static java.lang.String[] removeDuplicates(java.lang.String[] s)
To remove duplicate elements from a String array s

Parameters:
s - a String array to unique
Returns:
a String array of unique elements

removeCarriageReturns

public static java.lang.String removeCarriageReturns(java.lang.String string)
Removes the newlines and carriage returns from string and returns the resultant string.

Parameters:
string - the string to remove the carriage returns from
Returns:
the string with carriage returns removed

removeDuplicates

public static java.lang.String[] removeDuplicates(java.lang.String[] s,
                                                  StringArray duplicateArray)
To remove duplicate elements from a String array s

Parameters:
s - a String array to unique
duplicateArray - a list of duplicate array elements found in String array s
Returns:
a String array of unique elements

removeTrailingSlashIfAny

public static java.lang.String removeTrailingSlashIfAny(java.lang.String path)
Removes the trailing slash from the given String. Note that only one trailing slash is removed. It is assumed that the given path contains at most one traling slash. Note that the slash is either forward or backward, based on the OS.

Parameters:
path - the given path String, must not be null.
Returns:
the string with the trailing slash removed, if any.

removeLeadingSlashIfAny

public static java.lang.String removeLeadingSlashIfAny(java.lang.String path)
Removes the leading slash from the given String. Note that only one leading slash is removed. It is assumed that the given path contains at most one leading slash. Note that the slash is either forward or backward, based on the OS.

Parameters:
path - the given path String, must not be null.
Returns:
the string with the leading slash removed, if any.

printSecret

public static java.lang.String printSecret(java.lang.String value)

is7bitAscii

public static boolean is7bitAscii(char c)
Specifies whether the given character is a 7-ascii character

Parameters:
c - the character to test
Returns:
true if the character c is a 7-ascii character

isValidURIPart

public static boolean isValidURIPart(java.lang.String string,
                                     boolean allowForExtendedMarks)
Specifies whether the given String is a valid URI part. According to the RFC 2396, a URI part is made of any alpha-numerical characters as well as some authorized marks ( '-' '_' '.' '!' '~' '*' ''' '(' ')' ). This returns true if all the characters part of the String follow the RFC speficication.

However because some of these marks can be troublesome, this method will return false if they are part of the String and allowForExtendedMarks is false.

Parameters:
string - the String to verify.
allowForExtendedMarks - if false the marks '!', '~', '*', ''', '(' and ')' will not be considered valid characters (although the RFC 2396 allows them.
Returns:
true when the String complies with RFC 2396

isValidEmailLocalPart

public static boolean isValidEmailLocalPart(java.lang.String string)
Validate the local part of an email address per RFC-822

Parameters:
string -
Returns:
boolean

splitWithQuotes

public static java.util.List splitWithQuotes(java.lang.String str,
                                             boolean keepQuotes)
Splits a string up into chunks using a whitespace delimiter. Quoted items are treated as a single chunk.

Parameters:
str - the string to split
keepQuotes - if true keep the quotes that encapsulate an element
Returns:
a List of String containing each seperated element

equalsIgnoreCase

public static boolean equalsIgnoreCase(java.lang.String one,
                                       java.lang.String two)
Compares if two strings are equal or not. It is different from equalsIgnoreCase method of java.lang.String in the sense that it makes a null check of each of the Strings to be compared.

Parameters:
one - the String to be compared
two - the String to be compared
Returns:
true if both are null or equalsIgnoreCase of java.lang.String returns true. False if one of them are null or equalsIgnoreCase of java.lang.String returns false.

wrapHTML

public static java.lang.String wrapHTML(java.lang.String string,
                                        int wrapLength)
Return the string argument with "
" tag inserted every wrapLength- characters. Doesn't break a word, correctly handles punctuation and hyphenated words.

Parameters:
string -
wrapLength -
Returns:
wrapped string

wrap

public static java.lang.String wrap(java.lang.String string,
                                    java.lang.String lineSeparator,
                                    int wrapLength)
Return the string argument with the lineSeparator inserted every wrapLength- characters. Doesn't break a word, correctly handles punctuation and hyphenated words.
 StringUtil.wrap("Hello World!, null, 9) = Hello
World! StringUtil.wrap("1234512345", "
", 5) = 1234512345 StringUtil.wrap("12345", 10) = 12345

Parameters:
string - The String
lineSeparator - Line break, "
" by default
wrapLength - The position to create a line break
Returns:
String

getBytesUTF8

public static byte[] getBytesUTF8(java.lang.String string)

getStringUTF8

public static java.lang.String getStringUTF8(byte[] bytes)

escapeRegEx

public static java.lang.String escapeRegEx(java.lang.String regex)
Escapes metacharacters in a regex into literals.


search

public static StringUtil.SearchResult search(java.lang.String toSearch,
                                             int fromIdx,
                                             java.util.Collection toFind)
Searches for the first one of any of the supplied strings

Parameters:
toSearch - the string to search
fromIdx - the index at which to begin the search
Returns:
the result of the search

parseMatchingParentheses

public static java.lang.String[] parseMatchingParentheses(java.lang.String str)
Parse the input String into two components separated by matching left and right parentheses. Only one pair is supported.

Returns:
an array containing two elements, the first one is the first component before the left parenthesis and the second one is the component wrapped between the left and right perentheses

calcTruncateSize

public static int calcTruncateSize(java.lang.String label,
                                   int maxSize,
                                   int numLines)
Returns the ideal size to truncate based on the max number characters to display by trying to fit the most words / characters before truncation. This method tries to truncate CJK characters as best as it can comparing to latin characters. Also it specifically truncates long words, such as in German, so that they can be displayed on the browser inside a fixed with div without causing layout problems.

Parameters:
label -
maxSize - max ideal length before truncation
numLines - number of lines to display the label in - only used when it's > 0
Returns:
number of characters to truncate

convertToBase26

public static java.lang.String convertToBase26(long value)
Returns the Base26 representation of the provided integer; where 0 = a, 25 = z, 26 = ba, etc. Right now, we don't support negative values. The reason for this is that we anticipate that if someone ever wants to use this, they would use it for generating a unique alphabetical-only string based on some incrementing number. It's not designed to fully support base 26 as a convenience for everyone (if you want this just use Integer.toString(i, 26).) To get upper case letters, just toUpper() the result.

Parameters:
positive - integer
Returns:
String

convertFromBase26

public static long convertFromBase26(java.lang.String numberInBase26)
Convenience method that converts a number in base 26 (as might have been constructed by convertToBase26(long)) back into an integer.

Parameters:
numberInBase26 -
Returns:


AribaWeb User Interface Development Framework
Copyright © 2000-2014 Ariba, Inc. All Rights Reserved.