Package org.identityconnectors.common
Class StringUtil
- java.lang.Object
-
- org.identityconnectors.common.StringUtil
-
public final class StringUtil extends Object
String Utilities.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanallNotNull(Object... values)static booleanendsWith(String str, char value)Determines if the string parameter 'str' ends with the character value.static intindexOf(String src, char[] ch)static intindexOf(String src, char[] ch, int idx)static intindexOfDigit(String str)Finds the index of the first digit.static intindexOfDigit(String str, int startidx)Finds the index of the first digit and starts from the index specified.static intindexOfIgnoreCase(String src, String cmp)Finds the start index of the comparison string regards of case.static intindexOfNonDigit(String str)Finds the index of the first non digit.static intindexOfNonDigit(String str, int startidx)Finds the index of the first non digit and starts from the index specified.static booleanisBlank(String val)Checks if a String is whitespace, empty ("") or null.static booleanisEmpty(String val)Determines if a string is empty.static booleanisNotBlank(String val)Checks if a String is not empty (""), not null and not whitespace only.static booleanisNotEmpty(String val)Determines if a string is not empty.static booleanisWhitespace(char ch)Determine if this is a white space character.static Stringjoin(Object[] array, char separator)static Stringjoin(Object[] array, char separator, int startIndex, int endIndex)static Stringjoin(Collection<String> collection, char separator)static List<String>parseLine(String line, char fsep, char tqul)Parses a line into a List of strings.static StringrandomString()Create a random Unicode string.static StringrandomString(Random r)Create a random length Unicode string based on theRandomobject passed in.static StringrandomString(Random r, int length)Create a random string of fixed length based on theRandomobject passed in.static StringreplaceVariable(String o, String var, String val)Simple variable replacement internally using regular expressions.static StringstripNewlines(String src)Removes newline characters (0x0a and 0x0d) from a string.static StringstripXmlAttribute(String src, String attrName)Removes the attribute from the source string and returns.static StringstripXmlComments(String src)Strip XML comments.static StringsubDigitString(String str)Return the string of digits from string.static StringsubDigitString(String str, int idx)Return the string of digits from string.static StringsubstringBetween(String str, String open, String close)static PropertiestoProperties(String value)Returns a properties object w/ the key/value pairs parsed from the string passed in.
-
-
-
Field Detail
-
EMPTY
public static final String EMPTY
Empty""string.- See Also:
- Constant Field Values
-
-
Method Detail
-
indexOfDigit
public static int indexOfDigit(String str, int startidx)
Finds the index of the first digit and starts from the index specified.- Parameters:
str- String to search for a digit.startidx- Starting index from which to search- Returns:
- -1 if not found otherwise the index.
-
indexOfDigit
public static int indexOfDigit(String str)
Finds the index of the first digit.- Parameters:
str- String to search for a digit.- Returns:
- -1 if not found otherwise the index.
-
indexOfNonDigit
public static int indexOfNonDigit(String str, int startidx)
Finds the index of the first non digit and starts from the index specified.- Parameters:
str- String to search for a non digit.startidx- Starting index from which to search.- Returns:
- -1 if not found otherwise the index.
-
indexOfNonDigit
public static int indexOfNonDigit(String str)
Finds the index of the first non digit.- Parameters:
str- String to search for a non digit.- Returns:
- -1 if not found otherwise the index.
-
subDigitString
public static String subDigitString(String str)
Return the string of digits from string.- Parameters:
str- Source string to search.
-
subDigitString
public static String subDigitString(String str, int idx)
Return the string of digits from string.- Parameters:
str- Source string to search.idx- Start index from which to search.
-
stripXmlAttribute
public static String stripXmlAttribute(String src, String attrName)
Removes the attribute from the source string and returns.
-
stripNewlines
public static String stripNewlines(String src)
Removes newline characters (0x0a and 0x0d) from a string.
-
indexOfIgnoreCase
public static int indexOfIgnoreCase(String src, String cmp)
Finds the start index of the comparison string regards of case.- Parameters:
src- String to search.cmp- Comparison string to find.- Returns:
- -1 if not found otherwise the index of the starting character.
-
indexOf
public static int indexOf(String src, char[] ch)
-
indexOf
public static int indexOf(String src, char[] ch, int idx)
-
isEmpty
public static boolean isEmpty(String val)
Determines if a string is empty. Empty is defined as null or empty string.StringUtil.isEmpty(null) = true StringUtil.isEmpty("") = true StringUtil.isEmpty(" ") = false StringUtil.isEmpty("bob") = false StringUtil.isEmpty(" bob ") = false- Parameters:
val- string to evaluate as empty.- Returns:
- true if the string is empty else false.
-
isNotEmpty
public static boolean isNotEmpty(String val)
Determines if a string is not empty. Its the exact opposite forisEmpty(String).- Parameters:
val- string to evaluate.- Returns:
- true if the string is not empty
-
isBlank
public static boolean isBlank(String val)
Checks if a String is whitespace, empty ("") or null.StringUtil.isBlank(null) = true StringUtil.isBlank("") = true StringUtil.isBlank(" ") = true StringUtil.isBlank("bob") = false StringUtil.isBlank(" bob ") = false- Parameters:
val- the String to check, may be null- Returns:
trueif the String is null, empty or whitespace
-
isNotBlank
public static boolean isNotBlank(String val)
Checks if a String is not empty (""), not null and not whitespace only.StringUtil.isBlank(null) = true StringUtil.isBlank("") = true StringUtil.isBlank(" ") = true StringUtil.isBlank("bob") = false StringUtil.isBlank(" bob ") = false- Parameters:
val- the String to check, may be null- Returns:
trueif the String is not empty and not null and not whitespace
-
toProperties
public static Properties toProperties(String value)
Returns a properties object w/ the key/value pairs parsed from the string passed in.
-
replaceVariable
public static String replaceVariable(String o, String var, String val)
Simple variable replacement internally using regular expressions.String o = "Some string with a ${variable} in it."; String n = replaceVariable(o, "variable", "something"); String r = "Some string with a something in it"; assert r.equals(n);- Parameters:
o- Original string to do the replacement on.var- String representation of the variable to replace.val- Value to replace the variable with.- Returns:
- String will all the variables replaced with the value.
- Throws:
IllegalArgumentException- if o is null, var is blank, or val is null.
-
endsWith
public static boolean endsWith(String str, char value)
Determines if the string parameter 'str' ends with the character value.- Parameters:
str- String to check for the character at the end.value- The character to look for at the end of the string.- Returns:
- true if character parameter is found at the end of the string parameter otherwise false.
-
parseLine
public static List<String> parseLine(String line, char fsep, char tqul)
Parses a line into a List of strings.- Parameters:
line- String to parse.fsep- field separatortqul- Text qualifier.- Returns:
- list of string separated by a delimiter passed in by 'fsep' and text is qualified by the parameter 'tqul'.
-
isWhitespace
public static boolean isWhitespace(char ch)
Determine if this is a white space character. Whitespace characters are defined as the character ' ' and the tab character.
-
randomString
public static String randomString()
Create a random Unicode string.
-
randomString
public static String randomString(Random r)
Create a random length Unicode string based on theRandomobject passed in.
-
randomString
public static String randomString(Random r, int length)
Create a random string of fixed length based on theRandomobject passed in. Insure that the string is built w/ Unicode characters.- Parameters:
r- used to get random unicode characters.length- fixed length of string.- Returns:
- a randomly generated string based on the parameters.
-
join
public static String join(Collection<String> collection, char separator)
- Parameters:
collection-separator-- Returns:
- Since:
- 1.3
-
join
public static String join(Object[] array, char separator)
- Parameters:
array-separator-- Returns:
- Since:
- 1.3
-
join
public static String join(Object[] array, char separator, int startIndex, int endIndex)
- Parameters:
array-separator-startIndex-endIndex-- Returns:
- Since:
- 1.3
-
allNotNull
public static boolean allNotNull(Object... values)
-
-