List of utility methods to do Integer Create
int | toInt(long l) Converts long value to int under the conditions that the long value is representable as an int. if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) { throw new IllegalArgumentException(l + " cannot be cast to int without changing its value."); return (int) l; |
int | toInt(long l) to Int if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) throw new ArithmeticException("Value (" + l + ") cannot fit into int"); return (int) l; |
int | toInt(long unsignedInt) Converts a long containing an unsigned int value to the corresponding signed int value and returns the result as an int if (unsignedInt < 0 || unsignedInt > MAX_INT) { throw new IllegalArgumentException(String.format( "Unsigned byte values should be in the range 0..%1$d, got: %2$d", MAX_INT, unsignedInt)); return (int) unsignedInt; |
int[] | toInt(long[] a) to Int int[] b = new int[a.length]; for (int i = 0; i < a.length; i++) { b[i] = (int) a[i]; return b; |
int | toInt(Number num) to Int if (num == null) { return 0; } else { return num.intValue(); |
int | toInt(Number value) to Int long valueLong = value.longValue(); if (valueLong < Integer.MIN_VALUE || valueLong > Integer.MAX_VALUE) { throw new IllegalArgumentException(valueLong + " Casting the long to an int will change its value"); return (int) valueLong; |
int | toInt(Number wrapped) to Int if (wrapped == null) { return -1; return wrapped.intValue(); |
int | toInt(Object bean, int defaultValue) to Int try { return (null != bean) ? Integer.parseInt(bean.toString()) : defaultValue; } catch (Exception e) { e.printStackTrace(); return defaultValue; |
int | toInt(Object num) to Int int x; if (num instanceof Long) { x = ((Long) num).intValue(); } else if (num instanceof Double) { x = ((Double) num).intValue(); } else if (num instanceof String) { x = Integer.getInteger((String) num); } else { ... |
int | toInt(Object num, int defValue) to Int if (num != null) { String value = String.valueOf(num); try { return Integer.parseInt(value); } catch (Exception e) { return defValue; ... |