类 StringUtils
- java.lang.Object
-
- net.risedata.rpc.utils.StringUtils
-
public class StringUtils extends Object
Simple utility class for String operations useful across the framework.
Some methods in this class were copied from the Spring Framework so we didn't have to re-invent the wheel, and in these cases, we have retained all license, copyright and author information. shiro 中 url匹配源码
- 从以下版本开始:
- 0.9
-
-
字段概要
字段 修饰符和类型 字段 说明 static charDEFAULT_DELIMITER_CHARConstant representing the default delimiter character (comma), equal to','static charDEFAULT_QUOTE_CHARConstant representing the default quote character (double quote), equal to '"'static StringEMPTY_STRINGConstant representing the empty string, equal to ""
-
构造器概要
构造器 构造器 说明 StringUtils()
-
方法概要
所有方法 静态方法 具体方法 修饰符和类型 方法 说明 static Stringclean(String in)Returns a 'cleaned' representation of the specified argument.static booleanhasLength(String str)Check that the given String is neithernullnor of length 0.static booleanhasText(String str)Check whether the given String has actual text.static Stringjoin(Iterator<?> iterator, String separator)Joins the elements of the providedIteratorinto a single String containing the provided elements.static String[]split(String line)static String[]split(String line, char delimiter)static String[]split(String line, char delimiter, char quoteChar)static String[]split(String line, char delimiter, char beginQuoteChar, char endQuoteChar)static String[]split(String aLine, char delimiter, char beginQuoteChar, char endQuoteChar, boolean retainQuotes, boolean trimTokens)Splits the specified delimited String into tokens, supporting quoted tokens so that quoted strings themselves won't be tokenized.static String[]splitKeyValue(String aLine)static booleanstartsWithIgnoreCase(String str, String prefix)Test if the given String starts with the specified prefix, ignoring upper/lower case.static StringtoDelimitedString(Object[] array, String delimiter)Returns the array's contents as a string, with each element delimited by the specifieddelimiterargument.static StringtoDelimitedString(Collection c, String delimiter)Returns the collection's contents as a string, with each element delimited by the specifieddelimiterargument.static String[]tokenizeToStringArray(String str, String delimiters)Tokenize the given String into a String array via a StringTokenizer.static String[]tokenizeToStringArray(String str, String delimiters, boolean trimTokens, boolean ignoreEmptyTokens)Tokenize the given String into a String array via a StringTokenizer.static StringtoString(Object[] array)Returns the specified array as a comma-delimited (',') string.static String[]toStringArray(Collection collection)Copy the given Collection into a String array.static StringuppercaseFirstChar(String in)Returns the input argument, but ensures the first character is capitalized (if possible).
-
-
-
字段详细资料
-
EMPTY_STRING
public static final String EMPTY_STRING
Constant representing the empty string, equal to ""- 另请参阅:
- 常量字段值
-
DEFAULT_DELIMITER_CHAR
public static final char DEFAULT_DELIMITER_CHAR
Constant representing the default delimiter character (comma), equal to','- 另请参阅:
- 常量字段值
-
DEFAULT_QUOTE_CHAR
public static final char DEFAULT_QUOTE_CHAR
Constant representing the default quote character (double quote), equal to '"'- 另请参阅:
- 常量字段值
-
-
方法详细资料
-
hasText
public static boolean hasText(String str)
Check whether the given String has actual text. More specifically, returnstrueif the string notnull, its length is greater than 0, and it contains at least one non-whitespace character.StringUtils.hasText(null) == false
StringUtils.hasText("") == false
StringUtils.hasText(" ") == false
StringUtils.hasText("12345") == true
StringUtils.hasText(" 12345 ") == trueCopied from the Spring Framework while retaining all license, copyright and author information.
- 参数:
str- the String to check (may benull)- 返回:
trueif the String is notnull, its length is greater than 0, and it does not contain whitespace only- 另请参阅:
Character.isWhitespace(char)
-
hasLength
public static boolean hasLength(String str)
Check that the given String is neithernullnor of length 0. Note: Will returntruefor a String that purely consists of whitespace.StringUtils.hasLength(null) == falseCopied from the Spring Framework while retaining all license, copyright and author information.
StringUtils.hasLength("") == false
StringUtils.hasLength(" ") == true
StringUtils.hasLength("Hello") == true- 参数:
str- the String to check (may benull)- 返回:
trueif the String is not null and has length- 另请参阅:
hasText(String)
-
startsWithIgnoreCase
public static boolean startsWithIgnoreCase(String str, String prefix)
Test if the given String starts with the specified prefix, ignoring upper/lower case.Copied from the Spring Framework while retaining all license, copyright and author information.
- 参数:
str- the String to checkprefix- the prefix to look for- 返回:
truestarts with the specified prefix (ignoring case),falseif it does not.- 另请参阅:
String.startsWith(java.lang.String, int)
-
clean
public static String clean(String in)
Returns a 'cleaned' representation of the specified argument. 'Cleaned' is defined as the following:- If the specified
Stringisnull, returnnull - If not
null,trim()it. - If the trimmed string is equal to the empty String (i.e. ""), return
null - If the trimmed string is not the empty string, return the trimmed version .
nullis returned.- 参数:
in- the input String to clean.- 返回:
- a populated-but-trimmed String or
nullotherwise
- If the specified
-
toString
public static String toString(Object[] array)
Returns the specified array as a comma-delimited (',') string.- 参数:
array- the array whose contents will be converted to a string.- 返回:
- the array's contents as a comma-delimited (',') string.
- 从以下版本开始:
- 1.0
-
toDelimitedString
public static String toDelimitedString(Object[] array, String delimiter)
Returns the array's contents as a string, with each element delimited by the specifieddelimiterargument. Useful fortoString()implementations and log messages.- 参数:
array- the array whose contents will be converted to a stringdelimiter- the delimiter to use between each element- 返回:
- a single string, delimited by the specified
delimiter. - 从以下版本开始:
- 1.0
-
toDelimitedString
public static String toDelimitedString(Collection c, String delimiter)
Returns the collection's contents as a string, with each element delimited by the specifieddelimiterargument. Useful fortoString()implementations and log messages.- 参数:
c- the collection whose contents will be converted to a stringdelimiter- the delimiter to use between each element- 返回:
- a single string, delimited by the specified
delimiter. - 从以下版本开始:
- 1.2
-
tokenizeToStringArray
public static String[] tokenizeToStringArray(String str, String delimiters)
Tokenize the given String into a String array via a StringTokenizer. Trims tokens and omits empty tokens.The given delimiters string is supposed to consist of any number of delimiter characters. Each of those characters can be used to separate tokens. A delimiter is always a single character; for multi-character delimiters, consider using
delimitedListToStringArrayCopied from the Spring Framework while retaining all license, copyright and author information.
- 参数:
str- the String to tokenizedelimiters- the delimiter characters, assembled as String (each of those characters is individually considered as delimiter).- 返回:
- an array of the tokens
- 另请参阅:
StringTokenizer,String.trim()
-
tokenizeToStringArray
public static String[] tokenizeToStringArray(String str, String delimiters, boolean trimTokens, boolean ignoreEmptyTokens)
Tokenize the given String into a String array via a StringTokenizer.The given delimiters string is supposed to consist of any number of delimiter characters. Each of those characters can be used to separate tokens. A delimiter is always a single character; for multi-character delimiters, consider using
delimitedListToStringArrayCopied from the Spring Framework while retaining all license, copyright and author information.
- 参数:
str- the String to tokenizedelimiters- the delimiter characters, assembled as String (each of those characters is individually considered as delimiter)trimTokens- trim the tokens via String'strimignoreEmptyTokens- omit empty tokens from the result array (only applies to tokens that are empty after trimming; StringTokenizer will not consider subsequent delimiters as token in the first place).- 返回:
- an array of the tokens (
nullif the input String wasnull) - 另请参阅:
StringTokenizer,String.trim()
-
toStringArray
public static String[] toStringArray(Collection collection)
Copy the given Collection into a String array. The Collection must contain String elements only.Copied from the Spring Framework while retaining all license, copyright and author information.
- 参数:
collection- the Collection to copy- 返回:
- the String array (
nullif the passed-in Collection wasnull)
-
splitKeyValue
public static String[] splitKeyValue(String aLine) throws ParseException
- 抛出:
ParseException
-
split
public static String[] split(String line, char delimiter, char beginQuoteChar, char endQuoteChar)
-
split
public static String[] split(String aLine, char delimiter, char beginQuoteChar, char endQuoteChar, boolean retainQuotes, boolean trimTokens)
Splits the specified delimited String into tokens, supporting quoted tokens so that quoted strings themselves won't be tokenized. This method's implementation is very loosely based (with significant modifications) on Glen Smith's open-source CSVReader.java file. That file is Apache 2.0 licensed as well, making Glen's code a great starting point for us to modify to our needs.- 参数:
aLine- the String to parsedelimiter- the delimiter by which the line argument is to be splitbeginQuoteChar- the character signifying the start of quoted text (so the quoted text will not be split)endQuoteChar- the character signifying the end of quoted textretainQuotes- if the quotes themselves should be retained when constructing the corresponding tokentrimTokens- if leading and trailing whitespace should be trimmed from discovered tokens.- 返回:
- the tokens discovered from parsing the given delimited line.
-
join
public static String join(Iterator<?> iterator, String separator)
Joins the elements of the providedIteratorinto a single String containing the provided elements. No delimiter is added before or after the list. Anullseparator is the same as an empty String (""). Copied from Commons Lang, version 3 (r1138702).- 参数:
iterator- theIteratorof values to join together, may be nullseparator- the separator character to use, null treated as ""- 返回:
- the joined String,
nullif null iterator input - 从以下版本开始:
- 1.2
-
uppercaseFirstChar
public static String uppercaseFirstChar(String in)
Returns the input argument, but ensures the first character is capitalized (if possible).- 参数:
in- the string to uppercase the first character.- 返回:
- the input argument, but with the first character capitalized (if possible).
- 从以下版本开始:
- 1.2
-
-