de.umass.util
Class StringUtilities

java.lang.Object
  extended byde.umass.util.StringUtilities

public final class StringUtilities
extends Object

Utilitiy class with methods to calculate an md5 hash and to encode URLs.

Author:
Janni Kovacs

Constructor Summary
StringUtilities()
           
 
Method Summary
static String cleanUp(String s)
          Strips all characters from a String, that might be invalid to be used in file names.
static String convertFromBoolean(boolean value)
          Converts from a boolean to a Last.fm boolean result string.
static boolean convertToBoolean(String resultString)
          Converts a Last.fm boolean result string to a boolean.
static String decode(String s)
          Decodes an URL encoded String s using the UTF-8 character encoding.
static String encode(String s)
          URL Encodes the given String s using the UTF-8 character encoding.
static boolean isMbid(String nameOrMbid)
          Checks if the supplied String may be a Musicbrainz ID.
static boolean isMD5(String s)
          Tests if the given string might already be a 32-char md5 string.
static Map map(String[] strings)
          Creates a Map out of an array with Strings.
static String md5(String s)
          Returns a 32 chararacter hexadecimal representation of an MD5 hash of the given String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringUtilities

public StringUtilities()
Method Detail

md5

public static String md5(String s)
Returns a 32 chararacter hexadecimal representation of an MD5 hash of the given String.

Parameters:
s - the String to hash
Returns:
the md5 hash

encode

public static String encode(String s)
URL Encodes the given String s using the UTF-8 character encoding.

Parameters:
s - a String
Returns:
url encoded string

decode

public static String decode(String s)
Decodes an URL encoded String s using the UTF-8 character encoding.

Parameters:
s - an encoded String
Returns:
the decoded String

isMbid

public static boolean isMbid(String nameOrMbid)
Checks if the supplied String may be a Musicbrainz ID. This method returns true for Strings that are exactly 36 characters long and match the MBID pattern [0-9a-f]{8}\-[0-9a-f]{4}\-[0-9a-f]{4}\-[0-9a-f]{4}\-[0-9a-f]{12}.

Parameters:
nameOrMbid - a possible MBID
Returns:
true if this String may be a MBID

map

public static Map map(String[] strings)
Creates a Map out of an array with Strings.

Parameters:
strings - input strings, key-value alternating
Returns:
a parameter map

cleanUp

public static String cleanUp(String s)
Strips all characters from a String, that might be invalid to be used in file names. By default : / \ < > | ? " * are all replaced by -. Note that this is no guarantee that the returned name will be definately valid.

Parameters:
s - the String to clean up
Returns:
the cleaned up String

isMD5

public static boolean isMD5(String s)
Tests if the given string might already be a 32-char md5 string.

Parameters:
s - String to test
Returns:
true if the given String might be a md5 string

convertToBoolean

public static boolean convertToBoolean(String resultString)
Converts a Last.fm boolean result string to a boolean.

Parameters:
resultString - A Last.fm boolean result string.
Returns:
true if the given String represents a true, false otherwise.

convertFromBoolean

public static String convertFromBoolean(boolean value)
Converts from a boolean to a Last.fm boolean result string.

Parameters:
value - A boolean value.
Returns:
A string representing a Last.fm boolean.