Class StringUtils


  • public class StringUtils
    extends Object
    • Constructor Detail

      • StringUtils

        public StringUtils()
    • Method Detail

      • getEolCharCount

        public static int getEolCharCount​(String str,
                                          int charPos)
        Return the number of end-of-line characters at the current position - if any. For non-eol positions the result is 0
        Parameters:
        str -
        charPos -
        Returns:
      • findCharPos

        public static int findCharPos​(String str,
                                      int line,
                                      int col)
        Convert line and column index to the char position line and column indexes are 1-based. Using 0 for either argument yields -1
        Parameters:
        str -
        line -
        col - the column
        Returns:
        the char pos or -1 if there was none w.r.t. line and col
      • itemPerLine

        public static <T> String itemPerLine​(T[] array)
      • itemPerLine

        public static <T> String itemPerLine​(Iterable<T> iterable)
      • strip

        public static String strip​(String str,
                                   String... chars)
        Removes prefixes that are also suffixes from a given string e.g. strip('Hi', ') -> Hi
        Parameters:
        str -
        chars -
        Returns:
      • coalesce

        public static <T> T coalesce​(T... args)
        Returns first non-null argument
        Type Parameters:
        T -
        Parameters:
        args -
        Returns:
      • toLowerCamelCase

        public static String toLowerCamelCase​(String s)
      • toUpperCamelCase

        public static String toUpperCamelCase​(String s)
      • toCamelCase

        public static String toCamelCase​(String s,
                                         boolean upper)
      • cropString

        public static String cropString​(String str,
                                        int nMax,
                                        int nTolerance)
        Cuts a string after nMax bytes - unless the remaining bytes are less than tolerance. In case of a cut appends "... (# more bytes)". (# cannot be less than tolerance)
        Parameters:
        str -
        nMax -
        nTolerance -
        Returns:
      • commonPrefix

        public static String commonPrefix​(String sa,
                                          String sb,
                                          boolean skipLast)
        Returns the common prefix of the given strings
        Returns:
      • getAllPrefixedEntries

        public static <T> Map<String,​T> getAllPrefixedEntries​(String prefix,
                                                                    boolean inclusive,
                                                                    SortedMap<String,​T> prefixMap)
      • longestPrefixLookup

        public static <T> Map.Entry<String,​T> longestPrefixLookup​(String lookup,
                                                                        boolean inclusive,
                                                                        NavigableMap<String,​T> prefixMap)
        Looks up an element in the given map that is the longest prefix of the given lookup key.
        Parameters:
        lookup -
        prefixMap -
        Returns:
      • urlEncode

        public static String urlEncode​(String str)
        Helper functions to get rid of that exception. Afaik UTF8 en/de-coding cannot fail (read it somewhere, not confirmed)
        Parameters:
        str -
        Returns:
      • urlDecode

        public static String urlDecode​(String str)
      • md5Hash

        public static String md5Hash​(byte[] bytes)
        calculate md5 hash of the string
        Parameters:
        bytes -
        Returns:
      • bytesToHexString

        public static String bytesToHexString​(byte[] bytes)