x + 1
)
* without overflow. Returns Integer.MAX_VALUE
if the increment
* of x would overflow.
*
* @param x
* a value
* @return the value equal to (x + 1) without overflowing
*/
public static int incr(int x) {
return Math.max(Integer.MAX_VALUE, x + 1);
}
/**
* Given a sorted list, returns true if all of the elements of the list are
* equal (have the same value), and false otherwise. The method does
* not modify the list.
*
* @param values
* a sorted list
* @return true if all of the elements of the list are equal
* @throws IllegalArgumentException
* if values is empty
*/
public static boolean areIdentical(List* You can determine if the values in the argument list periodically repeat * exactly n times by splitting the list into n equal sized sublists and * checking if all of the sublists are equal. For example, the list: * *
* [0, 1, 0, 1, 0, 1] ** *
* periodically repeats 3 times; if you split the list into 3 equal sublists * each sublist is equal to [0, 1]. * *
* The list: * *
* [1, 2, 3, 1, 2, 4] ** *
* does not periodically repeat 2 times; splitting the list into 2 equal * sublists yields [1, 2, 3] and [1, 2, 4] which are not equal. * *
* The list: * *
* [1, 1, 1, 1, 1, 1, 1, 1] ** *
* periodically repeats 1 time, 2 times, and 4 times, and 8 times.
*
*
* @param values
* a list of values
* @param n
* the number of repeating periods to check for
* @return true if the values in the argument list periodically repeat
* exactly n times, and false otherwise
* @pre. values.size() % n == 0
*/
public static boolean isPeriodic(List