org.aksw.commons.util.strings
Class StringUtils

java.lang.Object
  extended by org.aksw.commons.util.strings.StringUtils

public class StringUtils
extends Object


Constructor Summary
StringUtils()
           
 
Method Summary
static String bytesToHexString(byte[] bytes)
           
static
<T> T
coalesce(T... args)
          Returns first non-null argument
static String commonPrefix(String sa, String sb, boolean skipLast)
          Returns the common prefix of the given strings
static String cropString(String str, int nMax, int nTolerance)
          Cuts a string after nMax bytes - unless the remaining bytes are less than tolerance.
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
<T> Map.Entry<String,T>
getMatchBySuffix(String str, Map<String,T> map)
           
static String lcFirst(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> String
longestPrefixLookup(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> String
longestPrefixLookup(String lookup, NavigableSet<String> prefixes)
           
static String md5Hash(byte[] bytes)
          calculate md5 hash of the string
static String md5Hash(String string)
           
static
<V> Map.Entry<String,V>
shortestMatchLookup(String prefix, boolean inclusive, NavigableMap<String,V> items)
           
static String shortestMatchLookup(String prefix, boolean inclusive, NavigableSet<String> items)
           
static String strip(String str, String... chars)
          Removes prefixes that are also suffixes from a given string e.g.
static String toCamelCase(String s, boolean upper)
           
static String toLowerCamelCase(String s)
           
static String toUpperCamelCase(String s)
           
static String ucFirst(String str)
           
static String urlDecode(String str)
           
static String urlEncode(String str)
          Helper functions to get rid of that exception.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringUtils

public StringUtils()
Method Detail

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)


Copyright © 2012. All Rights Reserved.