Java Code Examples for java.lang.Integer#MIN_VALUE

The following examples show how to use java.lang.Integer#MIN_VALUE . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@VisibleForTesting static int computeArrayListCapacity(int arraySize) {
  Preconditions.checkArgument(arraySize >= 0);
  long desiredSize = 5L + arraySize + (arraySize / 10);

  if (desiredSize > Integer.MAX_VALUE) {
    return Integer.MAX_VALUE;
  }
  if (desiredSize < Integer.MIN_VALUE) {
    return Integer.MIN_VALUE;
  }
  return (int) desiredSize;
}
 
Example 2
Source Project: JavaSCR   File: safeArithmetic.java    License: MIT License 5 votes vote down vote up
private static int safeAdd(int left, int right) throws ArithmeticException {
	if (right > 0 ? left > Integer.MAX_VALUE - right
			: left < Integer.MIN_VALUE - right) {
		throw new ArithmeticException("Integer overflow"); //$NON-NLS-1$
	}
	return left + right;
}
 
Example 3
Source Project: JavaSCR   File: safeArithmetic.java    License: MIT License 5 votes vote down vote up
static int safeSubtract(int left, int right)
		throws ArithmeticException {
	if (right > 0 ? left < Integer.MIN_VALUE + right
			: left > Integer.MAX_VALUE + right) {
		throw new ArithmeticException("Integer overflow"); //$NON-NLS-1$
	}
	return left - right;
}
 
Example 4
Source Project: JavaSCR   File: safeArithmetic.java    License: MIT License 5 votes vote down vote up
static int safeMultiply(int left, int right)
		throws ArithmeticException {
	if (right > 0 ? left > Integer.MAX_VALUE / right
			|| left < Integer.MIN_VALUE / right
			: (right < -1 ? left > Integer.MIN_VALUE / right
					|| left < Integer.MAX_VALUE / right : right == -1
					&& left == Integer.MIN_VALUE)) {
		throw new ArithmeticException("Integer overflow"); //$NON-NLS-1$
	}
	return left * right;
}
 
Example 5
Source Project: j2objc   File: DHGenParameterSpecTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * DHGenParameterSpec class testing. Tests the equivalence of
 * parameters specified in the constructor with the values returned
 * by getters.
 */
public void testDHGenParameterSpec() {
    int[] primes = {Integer.MIN_VALUE, -1, 0, 1, Integer.MAX_VALUE};
    int[] exponents = {Integer.MIN_VALUE, -1, 0, 1, Integer.MAX_VALUE};
    for (int i=0; i<primes.length; i++) {
        DHGenParameterSpec ps = new DHGenParameterSpec(primes[i],
                                                        exponents[i]);
        assertEquals("The value returned by getPrimeSize() must be "
                    + "equal to the value specified in the constructor",
                    ps.getPrimeSize(), primes[i]);
        assertEquals("The value returned by getExponentSize() must be "
                    + "equal to the value specified in the constructor",
                    ps.getPrimeSize(), exponents[i]);
    }
}
 
Example 6
Source Project: JavaSCR   File: safeArithmetic.java    License: MIT License 4 votes vote down vote up
static int safeDivide(int left, int right) throws ArithmeticException {
	if ((left == Integer.MIN_VALUE) && (right == -1)) {
		throw new ArithmeticException("Integer overflow"); //$NON-NLS-1$
	}
	return left / right;
}
 
Example 7
Source Project: JavaSCR   File: safeArithmetic.java    License: MIT License 4 votes vote down vote up
static int safeNegate(int a) throws ArithmeticException {
	if (a == Integer.MIN_VALUE) {
		throw new ArithmeticException("Integer overflow"); //$NON-NLS-1$
	}
	return -a;
}
 
Example 8
Source Project: JavaSCR   File: safeArithmetic.java    License: MIT License 4 votes vote down vote up
static int safeAbs(int a) throws ArithmeticException {
	if (a == Integer.MIN_VALUE) {
		throw new ArithmeticException("Integer overflow"); //$NON-NLS-1$
	}
	return Math.abs(a);
}