Class StringUtils2

java.lang.Object
org.jmxtrans.embedded.util.StringUtils2

public class StringUtils2
extends Object
Yet another StringUtils class.
Author:
Cyrille Le Clerc
  • Method Details

    • delimitedStringToList

      public static List<String> delimitedStringToList​(@Nullable String delimitedString)
      Split given String. Delimiters are ",", ";" and "\n".
      Parameters:
      delimitedString -
      Returns:
      splitted string or null if given delimitedString is null
    • join

      public static String join​(@Nullable List<String> tokens, @Nonnull String delimiter)
      Join given tokens with given delimiter. Sample: tokens "com", "mycompany, "ecommerce", "server1" with delimiter "." returns "com.mycompany.ecommerce.server1".
      Parameters:
      tokens -
      delimiter -
      Returns:
      the joined tokens (null if given tokens is null
    • reverseTokens

      public static String reverseTokens​(@Nullable String str, @Nonnull 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 null if given string is null
    • isNullOrEmpty

      public static boolean isNullOrEmpty​(@Nullable String value)
    • abbreviate

      @Nonnull public static String abbreviate​(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 abbreviate
      max - the max number of chars of the abbreviated String
      Returns:
      the abbreviated string