Methods Summary |
---|
public static void | assertTrue(boolean cond)
// Throws AssertionError if the input is false.
if (!cond) {
throw new AssertionError();
}
|
public static int | ceilLog2(float value)
int i;
for (i = 0; i < 31; i++) {
if ((1 << i) >= value) break;
}
return i;
|
public static T | checkNotNull(T object)
if (object == null) throw new NullPointerException();
return object;
|
public static int | clamp(int x, int min, int max)
if (x > max) return max;
if (x < min) return min;
return x;
|
public static float | clamp(float x, float min, float max)
if (x > max) return max;
if (x < min) return min;
return x;
|
public static long | clamp(long x, long min, long max)
if (x > max) return max;
if (x < min) return min;
return x;
|
public static void | closeSilently(java.io.Closeable c)
if (c == null) return;
try {
c.close();
} catch (IOException t) {
Log.w(TAG, "close fail ", t);
}
|
public static void | closeSilently(android.os.ParcelFileDescriptor fd)
try {
if (fd != null) fd.close();
} catch (Throwable t) {
Log.w(TAG, "fail to close", t);
}
|
public static void | closeSilently(android.database.Cursor cursor)
try {
if (cursor != null) cursor.close();
} catch (Throwable t) {
Log.w(TAG, "fail to close", t);
}
|
public static int | compare(long a, long b)
return a < b ? -1 : a == b ? 0 : 1;
|
public static java.lang.String[] | copyOf(java.lang.String[] source, int newSize)
String[] result = new String[newSize];
newSize = Math.min(source.length, newSize);
System.arraycopy(source, 0, result, 0, newSize);
return result;
|
public static final long | crc64Long(java.lang.String in)A function thats returns a 64-bit crc for string
if (in == null || in.length() == 0) {
return 0;
}
return crc64Long(getBytes(in));
|
public static final long | crc64Long(byte[] buffer)
// http://bioinf.cs.ucl.ac.uk/downloads/crc64/crc64.c
long part;
for (int i = 0; i < 256; i++) {
part = i;
for (int j = 0; j < 8; j++) {
long x = ((int) part & 1) != 0 ? POLY64REV : 0;
part = (part >> 1) ^ x;
}
sCrcTable[i] = part;
}
long crc = INITIALCRC;
for (int k = 0, n = buffer.length; k < n; ++k) {
crc = sCrcTable[(((int) crc) ^ buffer[k]) & 0xff] ^ (crc >> 8);
}
return crc;
|
public static void | debug(java.lang.String message, java.lang.Object args)
Log.v(DEBUG_TAG, String.format(message, args));
|
public static java.lang.String | ensureNotNull(java.lang.String value)
return value == null ? "" : value;
|
public static boolean | equals(java.lang.Object a, java.lang.Object b)
return (a == b) || (a == null ? false : a.equals(b));
|
public static java.lang.String | escapeXml(java.lang.String s)
StringBuilder sb = new StringBuilder();
for (int i = 0, len = s.length(); i < len; ++i) {
char c = s.charAt(i);
switch (c) {
case '<": sb.append("<"); break;
case '>": sb.append(">"); break;
case '\"": sb.append("""); break;
case '\'": sb.append("'"); break;
case '&": sb.append("&"); break;
default: sb.append(c);
}
}
return sb.toString();
|
public static void | fail(java.lang.String message, java.lang.Object args)
throw new AssertionError(
args.length == 0 ? message : String.format(message, args));
|
public static int | floorLog2(float value)
int i;
for (i = 0; i < 31; i++) {
if ((1 << i) > value) break;
}
return i - 1;
|
public static byte[] | getBytes(java.lang.String in)
byte[] result = new byte[in.length() * 2];
int output = 0;
for (char ch : in.toCharArray()) {
result[output++] = (byte) (ch & 0xFF);
result[output++] = (byte) (ch >> 8);
}
return result;
|
public static java.lang.String | getUserAgent(android.content.Context context)
PackageInfo packageInfo;
try {
packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
} catch (NameNotFoundException e) {
throw new IllegalStateException("getPackageInfo failed");
}
return String.format("%s/%s; %s/%s/%s/%s; %s/%s/%s",
packageInfo.packageName,
packageInfo.versionName,
Build.BRAND,
Build.DEVICE,
Build.MODEL,
Build.ID,
Build.VERSION.SDK_INT,
Build.VERSION.RELEASE,
Build.VERSION.INCREMENTAL);
|
public static boolean | handleInterrruptedException(java.lang.Throwable e)
// A helper to deal with the interrupt exception
// If an interrupt detected, we will setup the bit again.
if (e instanceof InterruptedIOException
|| e instanceof InterruptedException) {
Thread.currentThread().interrupt();
return true;
}
return false;
|
public static float | interpolateAngle(float source, float target, float progress)
// interpolate the angle from source to target
// We make the difference in the range of [-179, 180], this is the
// shortest path to change source to target.
float diff = target - source;
if (diff < 0) diff += 360f;
if (diff > 180) diff -= 360f;
float result = source + diff * progress;
return result < 0 ? result + 360f : result;
|
public static float | interpolateScale(float source, float target, float progress)
return source + progress * (target - source);
|
public static boolean | isNullOrEmpty(java.lang.String exifMake)
return TextUtils.isEmpty(exifMake);
|
public static boolean | isOpaque(int color)
return color >>> 24 == 0xFF;
|
public static java.lang.String | maskDebugInfo(java.lang.Object info)
if (info == null) return null;
String s = info.toString();
int length = Math.min(s.length(), MASK_STRING.length());
return IS_DEBUG_BUILD ? s : MASK_STRING.substring(0, length);
|
public static int | nextPowerOf2(int n)
if (n <= 0 || n > (1 << 30)) throw new IllegalArgumentException("n is invalid: " + n);
n -= 1;
n |= n >> 16;
n |= n >> 8;
n |= n >> 4;
n |= n >> 2;
n |= n >> 1;
return n + 1;
|
public static float | parseFloatSafely(java.lang.String content, float defaultValue)
if (content == null) return defaultValue;
try {
return Float.parseFloat(content);
} catch (NumberFormatException e) {
return defaultValue;
}
|
public static int | parseIntSafely(java.lang.String content, int defaultValue)
if (content == null) return defaultValue;
try {
return Integer.parseInt(content);
} catch (NumberFormatException e) {
return defaultValue;
}
|
public static int | prevPowerOf2(int n)
if (n <= 0) throw new IllegalArgumentException();
return Integer.highestOneBit(n);
|
public static void | swap(int[] array, int i, int j)
int temp = array[i];
array[i] = array[j];
array[j] = temp;
|
public static void | waitWithoutInterrupt(java.lang.Object object)
try {
object.wait();
} catch (InterruptedException e) {
Log.w(TAG, "unexpected interrupt: " + object);
}
|