public class StringUtils
extends java.lang.Object
Constructor and Description |
---|
StringUtils() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
checkNotNullOrEmpty(java.lang.String reference) |
static int |
countOccurrences(java.lang.String reference,
java.lang.String subString) |
static java.lang.String |
emptyToNull(java.lang.String input)
'
If input is empty or only contains whitespace, returns null.
|
static long |
getByteSize(java.lang.String value)
Gets the number of bytes in UTF-8 encoding.
|
static java.lang.String |
getCacheFileSuffix(android.content.Context context,
java.lang.String userId)
Gets a MD5 hash of the userId.
|
static java.lang.String |
getCacheFileSuffix(android.content.Context context,
java.lang.String userId,
java.lang.String apiKey)
There is the potential for having a too-long filename, but Android doesn't actually have anything about that in the docs.
|
static java.lang.String |
getMd5Hash(java.lang.String text)
Calculates the MD5 hash for some text.
|
static boolean |
isBlank(java.lang.String reference)
Checks if the string is empty or only contains whitespace characters.
|
static boolean |
isNullOrBlank(java.lang.String reference)
Checks if the string is null or only contains whitespace characters.
|
static boolean |
isNullOrEmpty(java.lang.String reference)
Checks if the string is null or has a length of 0.
|
static java.lang.String |
join(java.util.Collection<java.lang.String> strings,
java.lang.String sep) |
static java.lang.String |
join(java.lang.String[] strings,
java.lang.String sep) |
static java.util.HashSet<java.lang.String> |
jsonArrayToHashSet(org.json.JSONArray jsonArray) |
static java.lang.String |
stringArrayToJsonString(java.lang.String[] stringArray) |
static java.lang.String |
truncateToByteLength(java.lang.String input,
int byteLength)
Truncates and returns the input text to the desired number of UTF-8 bytes.
|
public static java.lang.String checkNotNullOrEmpty(java.lang.String reference)
public static java.lang.String join(java.util.Collection<java.lang.String> strings, java.lang.String sep)
public static java.lang.String join(java.lang.String[] strings, java.lang.String sep)
strings
- the list of strings to be joinedsep
- a string to be used as a separator between joined stringspublic static boolean isNullOrEmpty(java.lang.String reference)
public static boolean isNullOrBlank(java.lang.String reference)
String.trim()
to ascertain whether the string contains only whitespace.public static boolean isBlank(java.lang.String reference)
String.trim()
to ascertain whether the string contains only whitespace.public static java.lang.String emptyToNull(java.lang.String input)
public static int countOccurrences(java.lang.String reference, java.lang.String subString)
public static java.util.HashSet<java.lang.String> jsonArrayToHashSet(org.json.JSONArray jsonArray) throws org.json.JSONException
org.json.JSONException
public static java.lang.String stringArrayToJsonString(java.lang.String[] stringArray)
public static java.lang.String getCacheFileSuffix(android.content.Context context, java.lang.String userId, java.lang.String apiKey)
context
- The application context used to read from a saved-on-disk store of user id hashesuserId
- the user id used to generate a MD5 hash for the file name. If null, the string "null" gets used in its place before hashing.apiKey
- optional api keypublic static java.lang.String getCacheFileSuffix(android.content.Context context, java.lang.String userId)
public static java.lang.String getMd5Hash(java.lang.String text)
text
- the text to be hashedpublic static long getByteSize(java.lang.String value)
public static java.lang.String truncateToByteLength(java.lang.String input, int byteLength)
input
- The string to be truncated. May have multiple bytes per char.byteLength
- The desired length, in UTF-8 bytes, of the output string.