List of utility methods to do Long to Int
int | longToInt(Long l) Converts a Long to an int with special attention to overflow issues. if (l != null) { if (new Long(Integer.MAX_VALUE).compareTo(l) == -1) { return Integer.MAX_VALUE; } else if (new Long(Integer.MIN_VALUE).compareTo(l) == 1) { return Integer.MIN_VALUE; return l.intValue(); return 0; |
int | longToInt(Long l) long To Int if (l != null) { if (new Long(Integer.MAX_VALUE).compareTo(l) == -1) { return Integer.MAX_VALUE; } else if (new Long(Integer.MIN_VALUE).compareTo(l) == 1) { return Integer.MIN_VALUE; return l.intValue(); return 0; |
int | longToInt(long value) Checked conversion from long to int if (value > Integer.MAX_VALUE || value < Integer.MIN_VALUE) { throw new IllegalArgumentException(value + " is out of Integer's bound"); return (int) value; |
int[] | longToInt(long[] values) long To Int if (values == null) { return null; int[] results = new int[values.length]; for (int i = 0; i < values.length; i++) { results[i] = (int) values[i]; return results; ... |
int[] | longToIntArr(long[] longArr) long To Int Arr int[] intArr = new int[longArr.length]; for (int i = 0; i < longArr.length; i++) { intArr[i] = (int) longArr[i]; return intArr; |
int[] | longToIntArray(long value) long To Int Array int[] digits = Long.toString(value).chars().map(c -> c -= '0').toArray(); return digits; |
int | longToIntBounds(long value) casts a long to an int, but if the long is outside the int-range, it will mapped to the end of the range if (value > Integer.MAX_VALUE) return Integer.MAX_VALUE; else if (value < Integer.MIN_VALUE) return Integer.MIN_VALUE; else return (int) value; |
byte[] | longToIntBytes(long a) Convert a long value to a 4-byte array. byte[] returnByteArray = new byte[4]; returnByteArray[0] = (byte) ((a & 0xff000000) >> 24); returnByteArray[1] = (byte) ((a & 0x00ff0000) >> 16); returnByteArray[2] = (byte) ((a & 0x0000ff00) >> 8); returnByteArray[3] = (byte) ((a & 0x000000ff)); return returnByteArray; |
int | longToIntClip(final long value) long To Int Clip final int intValue = (int) value; if (value == intValue) { return intValue; } else if (value >= Integer.MAX_VALUE) { return Integer.MAX_VALUE; } else { return Integer.MIN_VALUE; |
Integer | longToInteger(final long value) long To Integer return (int) value; |