Package org.jmxtrans.agent.util
Class StringUtils2
java.lang.Object
org.jmxtrans.agent.util.StringUtils2
public class StringUtils2
extends java.lang.Object
Yet another
StringUtils class.- Author:
- Cyrille Le Clerc
-
Method Summary
Modifier and Type Method Description static java.lang.Stringabbreviate(java.lang.String str, int max)Abbreviates a String using ellipses.static voidappendEscapedNonAlphaNumericChars(java.lang.String str, boolean escapeDot, java.lang.StringBuilder result)Escape all non 'a' to 'z','A' to 'Z', '0' to '9' and '-' with a '_'.static voidappendEscapedNonAlphaNumericChars(java.lang.String str, java.lang.StringBuilder result)Escape all non 'a' to 'z','A' to 'Z', '0' to '9' and '-' with a '_'.static java.util.List<java.lang.String>delimitedStringToList(java.lang.String delimitedString)Split given String.static booleanisNullOrEmpty(java.lang.String value)static java.lang.Stringjoin(java.util.List<java.lang.String> tokens, java.lang.String delimiter)Join giventokenswith givendelimiter.static java.lang.StringreverseTokens(java.lang.String str, java.lang.String delimiter)Reverse tokens of given tokenizedstr.static java.lang.StringtrimToEmpty(java.lang.String str)if the given string isnull, return"", else returnString.trim().Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Method Details
-
delimitedStringToList
public static java.util.List<java.lang.String> delimitedStringToList(@Nullable java.lang.String delimitedString)Split given String. Delimiters are",",";"and"\n".- Parameters:
delimitedString-- Returns:
- splitted string or
nullif givendelimitedStringisnull
-
join
public static java.lang.String join(@Nullable java.util.List<java.lang.String> tokens, @Nonnull java.lang.String delimiter)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
public static java.lang.String reverseTokens(@Nullable java.lang.String str, @Nonnull java.lang.String delimiter)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 java.lang.String str, boolean escapeDot, @Nonnull java.lang.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 java.lang.String str, @Nonnull java.lang.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
public static boolean isNullOrEmpty(@Nullable java.lang.String value) -
abbreviate
@Nonnull public static java.lang.String abbreviate(java.lang.String str, int max)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
@Nonnull public static java.lang.String trimToEmpty(@Nullable java.lang.String str)if the given string isnull, return"", else returnString.trim().- Parameters:
str- the string to trim- Returns:
- the trimmed string
-