Methods Summary |
---|
static android.util.Range | alignRange(android.util.Range range, int align)
return range.intersect(
divUp(range.getLower(), align) * align,
(range.getUpper() / align) * align);
|
public static int | binarySearchDistinctRanges(android.util.Range[] ranges, T value)Returns the index of the range that contains a value in a sorted array of distinct ranges.
return Arrays.binarySearch(ranges, Range.create(value, value),
new Comparator<Range<T>>() {
@Override
public int compare(Range<T> lhs, Range<T> rhs) {
if (lhs.getUpper().compareTo(rhs.getLower()) < 0) {
return -1;
} else if (lhs.getLower().compareTo(rhs.getUpper()) > 0) {
return 1;
}
return 0;
}
});
|
static int | divUp(int num, int den)
return (num + den - 1) / den;
|
private static long | divUp(long num, long den)
return (num + den - 1) / den;
|
static android.util.Range | factorRange(android.util.Range range, int factor)Returns the equivalent factored range {@code newrange}, where for every
{@code e}: {@code newrange.contains(e)} implies that {@code range.contains(e * factor)},
and {@code !newrange.contains(e)} implies that {@code !range.contains(e * factor)}.
if (factor == 1) {
return range;
}
return Range.create(divUp(range.getLower(), factor), range.getUpper() / factor);
|
static android.util.Range | factorRange(android.util.Range range, long factor)Returns the equivalent factored range {@code newrange}, where for every
{@code e}: {@code newrange.contains(e)} implies that {@code range.contains(e * factor)},
and {@code !newrange.contains(e)} implies that {@code !range.contains(e * factor)}.
if (factor == 1) {
return range;
}
return Range.create(divUp(range.getLower(), factor), range.getUpper() / factor);
|
static int | gcd(int a, int b)Returns greatest common divisor
if (a == 0 && b == 0) {
return 1;
}
if (b < 0) {
b = -b;
}
if (a < 0) {
a = -a;
}
while (a != 0) {
int c = b % a;
b = a;
a = c;
}
return b;
|
static android.util.Range | intRangeFor(double v)
return Range.create((int)v, (int)Math.ceil(v));
|
public static android.util.Range[] | intersectSortedDistinctRanges(android.util.Range[] one, android.util.Range[] another)Returns the intersection of two sets of non-intersecting ranges
int ix = 0;
Vector<Range<T>> result = new Vector<Range<T>>();
for (Range<T> range: another) {
while (ix < one.length &&
one[ix].getUpper().compareTo(range.getLower()) < 0) {
++ix;
}
while (ix < one.length &&
one[ix].getUpper().compareTo(range.getUpper()) < 0) {
result.add(range.intersect(one[ix]));
++ix;
}
if (ix == one.length) {
break;
}
if (one[ix].getLower().compareTo(range.getUpper()) <= 0) {
result.add(range.intersect(one[ix]));
}
}
return result.toArray(new Range[result.size()]);
|
private static long | lcm(int a, int b)Returns least common multiple
if (a == 0 || b == 0) {
throw new IllegalArgumentException("lce is not defined for zero arguments");
}
return (long)a * b / gcd(a, b);
|
static android.util.Range | longRangeFor(double v)
return Range.create((long)v, (long)Math.ceil(v));
|
static android.util.Range | parseIntRange(java.lang.Object o, android.util.Range fallback)
try {
String s = (String)o;
int ix = s.indexOf('-");
if (ix >= 0) {
return Range.create(
Integer.parseInt(s.substring(0, ix), 10),
Integer.parseInt(s.substring(ix + 1), 10));
}
int value = Integer.parseInt(s);
return Range.create(value, value);
} catch (ClassCastException e) {
} catch (NumberFormatException e) {
} catch (NullPointerException e) {
return fallback;
} catch (IllegalArgumentException e) {
}
Log.w(TAG, "could not parse integer range '" + o + "'");
return fallback;
|
static int | parseIntSafely(java.lang.Object o, int fallback)
try {
String s = (String)o;
return Integer.parseInt(s);
} catch (ClassCastException e) {
} catch (NumberFormatException e) {
} catch (NullPointerException e) {
return fallback;
}
Log.w(TAG, "could not parse integer '" + o + "'");
return fallback;
|
static android.util.Range | parseLongRange(java.lang.Object o, android.util.Range fallback)
try {
String s = (String)o;
int ix = s.indexOf('-");
if (ix >= 0) {
return Range.create(
Long.parseLong(s.substring(0, ix), 10),
Long.parseLong(s.substring(ix + 1), 10));
}
long value = Long.parseLong(s);
return Range.create(value, value);
} catch (ClassCastException e) {
} catch (NumberFormatException e) {
} catch (NullPointerException e) {
return fallback;
} catch (IllegalArgumentException e) {
}
Log.w(TAG, "could not parse long range '" + o + "'");
return fallback;
|
static android.util.Range | parseRationalRange(java.lang.Object o, android.util.Range fallback)
try {
String s = (String)o;
int ix = s.indexOf('-");
if (ix >= 0) {
return Range.create(
Rational.parseRational(s.substring(0, ix)),
Rational.parseRational(s.substring(ix + 1)));
}
Rational value = Rational.parseRational(s);
return Range.create(value, value);
} catch (ClassCastException e) {
} catch (NumberFormatException e) {
} catch (NullPointerException e) {
return fallback;
} catch (IllegalArgumentException e) {
}
Log.w(TAG, "could not parse rational range '" + o + "'");
return fallback;
|
static android.util.Size | parseSize(java.lang.Object o, android.util.Size fallback)
try {
return Size.parseSize((String) o);
} catch (ClassCastException e) {
} catch (NumberFormatException e) {
} catch (NullPointerException e) {
return fallback;
}
Log.w(TAG, "could not parse size '" + o + "'");
return fallback;
|
static android.util.Pair | parseSizeRange(java.lang.Object o)
try {
String s = (String)o;
int ix = s.indexOf('-");
if (ix >= 0) {
return Pair.create(
Size.parseSize(s.substring(0, ix)),
Size.parseSize(s.substring(ix + 1)));
}
Size value = Size.parseSize(s);
return Pair.create(value, value);
} catch (ClassCastException e) {
} catch (NumberFormatException e) {
} catch (NullPointerException e) {
return null;
} catch (IllegalArgumentException e) {
}
Log.w(TAG, "could not parse size range '" + o + "'");
return null;
|
static android.util.Range | scaleRange(android.util.Range range, int num, int den)
if (num == den) {
return range;
}
return Range.create(
scaleRatio(range.getLower(), num, den),
scaleRatio(range.getUpper(), num, den));
|
private static android.util.Rational | scaleRatio(android.util.Rational ratio, int num, int den)
int common = gcd(num, den);
num /= common;
den /= common;
return new Rational(
(int)(ratio.getNumerator() * (double)num), // saturate to int
(int)(ratio.getDenominator() * (double)den)); // saturate to int
|
public static void | sortDistinctRanges(android.util.Range[] ranges)Sorts distinct (non-intersecting) range array in ascending order.
Arrays.sort(ranges, new Comparator<Range<T>>() {
@Override
public int compare(Range<T> lhs, Range<T> rhs) {
if (lhs.getUpper().compareTo(rhs.getLower()) < 0) {
return -1;
} else if (lhs.getLower().compareTo(rhs.getUpper()) > 0) {
return 1;
}
throw new IllegalArgumentException(
"sample rate ranges must be distinct (" + lhs + " and " + rhs + ")");
}
});
|