Methods Summary |
---|
public static final boolean | arrayContains(java.lang.Object[] a, java.lang.Object o)
for (int i = 0, count = a.length; i < count; i++) {
if (a[i].equals(o)) {
return true;
}
}
return false;
|
public static java.lang.String | base64Decode(java.lang.String encoded)
if (encoded == null) {
return null;
}
byte[] decoded = new Base64().decode(encoded.getBytes());
return new String(decoded);
|
public static java.lang.String | base64Encode(java.lang.String s)
if (s == null) {
return s;
}
byte[] encoded = new Base64().encode(s.getBytes());
return new String(encoded);
|
public static java.lang.String | combine(java.lang.Object[] parts, char seperator)Combines the given array of Objects into a single string using the
seperator character and each Object's toString() method. between each
part.
if (parts == null) {
return null;
}
StringBuffer sb = new StringBuffer();
for (int i = 0; i < parts.length; i++) {
sb.append(parts[i].toString());
if (i < parts.length - 1) {
sb.append(seperator);
}
}
return sb.toString();
|
public static java.lang.String | fastUrlDecode(java.lang.String s)A fast version of URLDecoder.decode() that works only with UTF-8 and does only two
allocations. This version is around 3x as fast as the standard one and I'm using it
hundreds of times in places that slow down the UI, so it helps.
try {
byte[] bytes = s.getBytes("UTF-8");
byte ch;
int length = 0;
for (int i = 0, count = bytes.length; i < count; i++) {
ch = bytes[i];
if (ch == '%") {
int h = (bytes[i + 1] - '0");
int l = (bytes[i + 2] - '0");
if (h > 9) {
h -= 7;
}
if (l > 9) {
l -= 7;
}
bytes[length] = (byte) ((h << 4) | l);
i += 2;
}
else if (ch == '+") {
bytes[length] = ' ";
}
else {
bytes[length] = bytes[i];
}
length++;
}
return new String(bytes, 0, length, "UTF-8");
}
catch (UnsupportedEncodingException uee) {
return null;
}
|
public static java.lang.String | imapQuoted(java.lang.String s)Apply quoting rules per IMAP RFC,
quoted = DQUOTE *QUOTED-CHAR DQUOTE
QUOTED-CHAR = / "\" quoted-specials
quoted-specials = DQUOTE / "\"
This is used primarily for IMAP login, but might be useful elsewhere.
NOTE: Not very efficient - you may wish to preflight this, or perhaps it should check
for trouble chars before calling the replace functions.
// First, quote any backslashes by replacing \ with \\
// regex Pattern: \\ (Java string const = \\\\)
// Substitute: \\\\ (Java string const = \\\\\\\\)
String result = s.replaceAll("\\\\", "\\\\\\\\");
// Then, quote any double-quotes by replacing " with \"
// regex Pattern: " (Java string const = \")
// Substitute: \\" (Java string const = \\\\\")
result = result.replaceAll("\"", "\\\\\"");
// return string with quotes around it
return "\"" + result + "\"";
|
public static boolean | isDateToday(java.util.Date date)Returns true if the specified date is within today. Returns false otherwise.
// TODO But Calendar is so slowwwwwww....
Date today = new Date();
if (date.getYear() == today.getYear() &&
date.getMonth() == today.getMonth() &&
date.getDate() == today.getDate()) {
return true;
}
return false;
|
public static java.lang.String | quoteString(java.lang.String s)Ensures that the given string starts and ends with the double quote character. The string is not modified in any way except to add the
double quote character to start and end if it's not already there.
TODO: Rename this, because "quoteString()" can mean so many different things.
sample -> "sample"
"sample" -> "sample"
""sample"" -> "sample"
"sample"" -> "sample"
sa"mp"le -> "sa"mp"le"
"sa"mp"le" -> "sa"mp"le"
(empty string) -> ""
" -> ""
if (s == null) {
return null;
}
if (!s.matches("^\".*\"$")) {
return "\"" + s + "\"";
}
else {
return s;
}
|
public static final java.lang.String | readInputStream(java.io.InputStream in, java.lang.String encoding)
InputStreamReader reader = new InputStreamReader(in, encoding);
StringBuffer sb = new StringBuffer();
int count;
char[] buf = new char[512];
while ((count = reader.read(buf)) != -1) {
sb.append(buf, 0, count);
}
return sb.toString();
|
public static boolean | requiredFieldValid(android.widget.TextView view)
return view.getText() != null && view.getText().length() > 0;
|
public static boolean | requiredFieldValid(android.text.Editable s)
return s != null && s.length() > 0;
|
public static void | setCompoundDrawablesAlpha(android.widget.TextView view, int alpha)
// Drawable[] drawables = view.getCompoundDrawables();
// for (Drawable drawable : drawables) {
// if (drawable != null) {
// drawable.setAlpha(alpha);
// }
// }
|