Package org.aksw.commons.util.string
Class StringUtils
- java.lang.Object
-
- org.aksw.commons.util.string.StringUtils
-
public class StringUtils extends Object
-
-
Constructor Summary
Constructors Constructor Description StringUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static StringbytesToHexString(byte[] bytes)static <T> Tcoalesce(T... args)Returns first non-null argumentstatic StringcommonPrefix(String sa, String sb, boolean skipLast)Returns the common prefix of the given stringsstatic StringcropString(String str, int nMax, int nTolerance)Cuts a string after nMax bytes - unless the remaining bytes are less than tolerance.static intfindCharPos(String str, int line, int col)Convert line and column index to the char position line and column indexes are 1-based.static <T> Map<String,T>getAllPrefixedEntries(String prefix, boolean inclusive, NavigableMap<String,T> prefixMap)static <T> Map<String,T>getAllPrefixedEntries(String prefix, boolean inclusive, SortedMap<String,T> prefixMap)static <T> Map<String,T>getAllPrefixes(String lookup, boolean inclusive, NavigableMap<String,T> prefixMap)static <T> NavigableSet<String>getAllPrefixes(String lookup, boolean inclusive, NavigableSet<String> prefixMap)static <T> Map<String,T>getAllPrefixes(String lookup, boolean inclusive, SortedMap<String,T> prefixMap)static intgetEolCharCount(String str, int charPos)Return the number of end-of-line characters at the current position - if any.static <T> Map.Entry<String,T>getMatchBySuffix(String str, Map<String,T> map)static <T> StringitemPerLine(Iterable<T> iterable)static <T> StringitemPerLine(T[] array)static StringlcFirst(String str)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.static <T> StringlongestPrefixLookup(String lookup, boolean inclusive, NavigableSet<String> prefixes)static <T> Map.Entry<String,T>longestPrefixLookup(String lookup, boolean inclusive, SortedMap<String,T> prefixMap)static <T> Map.Entry<String,T>longestPrefixLookup(String lookup, NavigableMap<String,T> prefixMap)static <T> StringlongestPrefixLookup(String lookup, NavigableSet<String> prefixes)static Stringmd5Hash(byte[] bytes)calculate md5 hash of the stringstatic Stringmd5Hash(String string)static <V> Map.Entry<String,V>shortestMatchLookup(String prefix, boolean inclusive, NavigableMap<String,V> items)static StringshortestMatchLookup(String prefix, boolean inclusive, NavigableSet<String> items)static Stringstrip(String str, String... chars)Removes prefixes that are also suffixes from a given string e.g.static StringtoCamelCase(String s, boolean upper)static StringtoLowerCamelCase(String s)static StringtoUpperCamelCase(String s)static StringucFirst(String str)static StringurlDecode(String str)static StringurlEncode(String str)Helper functions to get rid of that exception.
-
-
-
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)
-
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:
-
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:
-
md5Hash
public static String md5Hash(byte[] bytes)
calculate md5 hash of the string- Parameters:
bytes-- Returns:
-
bytesToHexString
public static String bytesToHexString(byte[] bytes)
-
-