Class StringUtil


  • public final class StringUtil
    extends Object
    Utility methods for Strings.
    • Method Detail

      • toString

        public static String toString​(byte[] bytes)
        Create a string representation of a byte array.
        Parameters:
        bytes - the byte array to convert to a string representation
        Returns:
        the resulting string
      • toBytes

        public static byte[] toBytes​(String string)
        Create a byte array representation of a string.
        Parameters:
        string - the string to convert into a byte array representation
        Returns:
        the resulting byte array
      • escapeComma

        public static String escapeComma​(String str)
        Escapes the provided string so that it no longer contains the COMMA character.
        Parameters:
        str - the string to escape
        Returns:
        the escaped string
      • unescapeComma

        public static String unescapeComma​(String escapedStr)
        Unescapes the provided byte array - this should only be called on byte arrays that have been through the escape method.
        Parameters:
        escapedStr - the escaped string
        Returns:
        the unescaped string
      • toCsv

        public static byte[] toCsv​(Class<?>... classes)
        Create a CSV entry containing a list of class names (in byte array representation).
        Parameters:
        classes - the classes to write as a CSV entry
        Returns:
        the CSV entry, as a byte array
      • csvToClasses

        public static <T> Set<Class<? extends T>> csvToClasses​(byte[] bytes,
                                                               Class<? extends T> clazz)
        Convert a byte array containing a CSV entry of class names into a Set of Class objects.

        All the Class objects created are then cast to a subclass of the type T.

        Type Parameters:
        T - the base type to cast all of the Class instances to a subtype of
        Parameters:
        bytes - the CSV entry
        clazz - the Class instance to cast to
        Returns:
        a set of Class instances
      • nullIfEmpty

        public static String nullIfEmpty​(String string)
        Checks if a String is null or empty and returns null if true.
        Parameters:
        string - input String
        Returns:
        null if input String is null or empty otherwise returns the input String