Package org.jmxtrans.agent.util
Class StringUtils2
java.lang.Object
org.jmxtrans.agent.util.StringUtils2
public class StringUtils2 extends Object
Yet another
StringUtils class.- Author:
- Cyrille Le Clerc
-
Method Summary
Modifier and Type Method Description static Stringabbreviate(String str, int max)Abbreviates a String using ellipses.static voidappendEscapedNonAlphaNumericChars(String str, boolean escapeDot, StringBuilder result)Escape all non 'a' to 'z','A' to 'Z', '0' to '9' and '-' with a '_'.static voidappendEscapedNonAlphaNumericChars(String str, StringBuilder result)Escape all non 'a' to 'z','A' to 'Z', '0' to '9' and '-' with a '_'.static List<String>delimitedStringToList(String delimitedString)Split given String.static booleanisNullOrEmpty(String value)static Stringjoin(List<String> tokens, String delimiter)Join giventokenswith givendelimiter.static StringreverseTokens(String str, String delimiter)Reverse tokens of given tokenizedstr.static StringtrimToEmpty(String str)
-
Method Details
-
delimitedStringToList
Split given String. Delimiters are",",";"and"\n".- Parameters:
delimitedString-- Returns:
- splitted string or
nullif givendelimitedStringisnull
-
join
Join giventokenswith givendelimiter. Sample: tokens"com", "mycompany, "ecommerce", "server1"with delimiter"."returns"com.mycompany.ecommerce.server1".- Parameters:
tokens-delimiter-- Returns:
- the joined tokens (
nullif giventokensisnull
-
reverseTokens
Reverse tokens of given tokenized
str.Sample: "server1.ecommerce.mycompany.com" returns
"com.mycompany.ecommerce.server1".- Parameters:
str-delimiter-- Returns:
- reversed string or
nullif given string isnull
-
appendEscapedNonAlphaNumericChars
public static void appendEscapedNonAlphaNumericChars(@Nullable String str, boolean escapeDot, @Nonnull StringBuilder result)Escape all non 'a' to 'z','A' to 'Z', '0' to '9' and '-' with a '_'. '.' is escaped with a '_' ifescapeDotistrue.- Parameters:
str- the string to escapeescapeDot- indicates whether '.' should be escaped into '_' or not.result- the StringBuilder in which the escaped string is appended
-
appendEscapedNonAlphaNumericChars
public static void appendEscapedNonAlphaNumericChars(@Nonnull String str, @Nonnull StringBuilder result)Escape all non 'a' to 'z','A' to 'Z', '0' to '9' and '-' with a '_'.- Parameters:
str- the string to escaperesult- the StringBuilder in which the escaped string is appended
-
isNullOrEmpty
-
abbreviate
Abbreviates a String using ellipses. This will turn "Now is the time for all good men" into "Now is the time for..."- Parameters:
str- the String to abbreviatemax- the max number of chars of the abbreviated String- Returns:
- the abbreviated string
-
trimToEmpty
- Parameters:
str- the string to trim- Returns:
- the trimmed string
-