DataUtil { public static int[] getIntArray(Object object, int[] defValue) { if (object == null) { return defValue; } int[] result; if (object instanceof int[]) { result = (int[])object; } else if (object instanceof Number) { result = new int[]{getInt(object, 0)}; } else if (object instanceof Number[]) { Number[] array = (Number[])object; result = new int[array.length]; for (int i = 0; i < array.length; i++) { result[i] = array[i].intValue(); } } else if (object.getClass().isArray()) { int len = Array.getLength(object); result = new int[len]; for (int i = 0; i < len; i++) { result[i] = getInt(Array.get(object, i), 0); } } else if (object instanceof Boolean) { result = new int[]{getInt(object, 0)}; } else { result = defValue; } return result; }  static boolean getBoolean(Object value, boolean defValue); static Boolean doGetBoolean(Object value, Boolean defValue); static boolean toBoolean(String value, boolean defValue); static Boolean convertToBoolean(String value, Boolean defValue); static boolean toBoolean(String value); static int getInt(Object value, int defValue); static long getLong(Object value, long defValue); static double getDouble(Object value, double defValue); static String getString(Object value, String defValue); static String[] getStringArray(Object object, String[] defValue); static int[] getIntArray(Object object, int[] defValue); static List<String> getStringList(Object object);  }
@Test public void getIntArray() throws Exception { assertArrayEquals(DataUtil.getIntArray(null, defaultIntArray), defaultIntArray); assertArrayEquals(DataUtil.getIntArray(Boolean.TRUE, defaultIntArray), new int[] {1}); assertArrayEquals(DataUtil.getIntArray(Boolean.FALSE, defaultIntArray), new int[] {0}); assertArrayEquals(DataUtil.getIntArray("True", defaultIntArray), defaultIntArray); assertArrayEquals(DataUtil.getIntArray(new Integer[] {777, 888}, defaultIntArray), new int[] { 777, 888}); assertArrayEquals(DataUtil.getIntArray(new Object(), defaultIntArray), defaultIntArray); assertArrayEquals(DataUtil.getIntArray(888l, defaultIntArray), new int[] {888}); assertArrayEquals(DataUtil.getIntArray(new int[] { 777, 999}, defaultIntArray), new int[] {777, 999}); assertArrayEquals(DataUtil.getIntArray(new long[] { 777, 999}, defaultIntArray), new int[] {777, 999}); assertArrayEquals(DataUtil.getIntArray('a', defaultIntArray), defaultIntArray); assertArrayEquals(DataUtil.getIntArray(new int[] {345, 123} , defaultIntArray), new int[] {345, 123}); }