public final class StringUtilities extends Object
Modifier and Type | Field and Description |
---|---|
private static MessageDigest |
digest |
private static Pattern |
MBID_PATTERN |
private static Pattern |
MD5_PATTERN |
Constructor and Description |
---|
StringUtilities() |
Modifier and Type | Method and Description |
---|---|
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<String,String> |
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.
|
private static MessageDigest digest
private static Pattern MBID_PATTERN
private static final Pattern MD5_PATTERN
public StringUtilities()
public static String md5(String s)
s
- the String to hashpublic static String encode(String s)
s
using the UTF-8 character encoding.s
- a Stringpublic static String decode(String s)
s
using the UTF-8 character encoding.s
- an encoded Stringpublic static boolean isMbid(String nameOrMbid)
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}
.nameOrMbid
- a possible MBIDtrue
if this String may be a MBIDpublic static Map<String,String> map(String... strings)
strings
- input strings, key-value alternatingpublic static String cleanUp(String s)
s
- the String to clean uppublic static boolean isMD5(String s)
s
- String to testtrue
if the given String might be a md5 stringpublic static boolean convertToBoolean(String resultString)
resultString
- A Last.fm boolean result string.true
if the given String represents a true, false
otherwise.public static String convertFromBoolean(boolean value)
value
- A boolean value.WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses