Class StringUtils

java.lang.Object
org.aksw.commons.util.string.StringUtils

public class StringUtils extends Object
  • Constructor Details

    • StringUtils

      public StringUtils()
  • Method Details

    • 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:
    • ucFirst

      public static String ucFirst(String str)
    • lcFirst

      public static String lcFirst(String str)
    • 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:
    • longestPrefixLookup

      public static <T> String longestPrefixLookup(String lookup, NavigableSet<String> prefixes)
    • longestPrefixLookup

      public static <T> String longestPrefixLookup(String lookup, boolean inclusive, NavigableSet<String> prefixes)
    • longestPrefixLookup

      public static <T> Map.Entry<String,T> longestPrefixLookup(String lookup, NavigableMap<String,T> prefixMap)
    • getAllPrefixes

      public static <T> Map<String,T> getAllPrefixes(String lookup, boolean inclusive, NavigableMap<String,T> prefixMap)
    • getAllPrefixes

      public static <T> NavigableSet<String> getAllPrefixes(String lookup, boolean inclusive, NavigableSet<String> prefixMap)
    • getAllPrefixes

      public static <T> Map<String,T> getAllPrefixes(String lookup, boolean inclusive, SortedMap<String,T> prefixMap)
    • getAllPrefixedEntries

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

      public static <T> Map<String,T> getAllPrefixedEntries(String prefix, boolean inclusive, NavigableMap<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:
    • longestPrefixLookup

      public static <T> Map.Entry<String,T> longestPrefixLookup(String lookup, boolean inclusive, SortedMap<String,T> prefixMap)
    • shortestMatchLookup

      public static <V> Map.Entry<String,V> shortestMatchLookup(String prefix, boolean inclusive, NavigableMap<String,V> items)
    • shortestMatchLookup

      public static String shortestMatchLookup(String prefix, boolean inclusive, NavigableSet<String> items)
    • getMatchBySuffix

      public static <T> Map.Entry<String,T> getMatchBySuffix(String str, Map<String,T> map)
    • 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)
    • md5Hash

      public static String md5Hash(String string)
    • numberSuffix

      public static String numberSuffix(String base)
      Return the substring of a string that only consists of digits.

      Examples:

         "abc123" -> "123"
         "abc" -> ""
         "abc123.456" -> "456"
       
    • allocateName

      public static String allocateName(String base, boolean forceNumberSuffix, Predicate<String> skip)