Java Utililty Methods Object to int

List of utility methods to do Object to int

Description

The list of methods to do Object to int are organized into topic(s).

Method

IntegercastInt(Object o)
cast Int
if (o == null) {
    return 0;
} else if (o instanceof Byte) {
    return (int) (Byte) o;
} else if (o instanceof Integer) {
    return (Integer) o;
} else if (o instanceof Double) {
    return (int) (double) (Double) o;
...
IntegercastInt(Object o)
Casts the given object to an integer if applicable.
if (o instanceof Number) {
    return ((Number) o).intValue();
return null;
int[]castToInt(double[] aDouble)
cast To Int
int[] aInt = new int[aDouble.length];
for (int i = 0; i < aInt.length; i++) {
    aInt[i] = (int) aDouble[i];
return aInt;
intcastToInt(final long value)
cast To Int
final int result = (int) value;
if (result != value) {
    throw new ArithmeticException("Out of range: " + value);
return result;
IntegercastToInt(Object value)
cast To Int
if (value == null) {
    return null;
if (value instanceof Integer) {
    return (Integer) value;
if (value instanceof Number) {
    return ((Number) value).intValue();
...
IntegercastToInteger(final String uid)
cast To Integer
try {
    return Integer.decode(uid);
} catch (NumberFormatException nfe) {
    return null;
IntegercastToInteger(Object object)
Sometimes ELP's version of cast is misbehaving
if (object != null) {
    if (object instanceof Integer)
        return (Integer) object;
    else
        return Integer.valueOf(object.toString());
return null;
IntegercastToInteger(Object value)
cast To Integer
return (Integer) value;
Integer[]castToIntegerArray(Object[] array)
EPL has embedded cast method, but it doesn't cover arrays
if (array != null) {
    Integer[] retArray = new Integer[array.length];
    int i = 0;
    for (Object element : array) {
        retArray[i] = element == null ? null : (Integer) element;
        i++;
    return retArray;
...
int[]castToInts(final double[] doubles)
cast To Ints
final int[] ints = new int[doubles.length];
for (int i = 0; i < doubles.length; ++i)
    ints[i] = (int) doubles[i];
return ints;