public class IntUtil extends Object
Modifier and Type | Field and Description |
---|---|
static int |
MIN_PRIME
The smallest prime number.
|
Modifier and Type | Method and Description |
---|---|
static boolean |
areIdentical(List<Integer> values)
Given a sorted list, returns true if all of the elements of the list are
equal (have the same value), and false otherwise.
|
static boolean |
areUnique(List<Integer> values)
Returns true if the argument list contains only unique values (has no
repeated values), and false otherwise.
|
static int |
incr(int x)
Returns the increment of x (the value equal to
x + 1 )
without overflow. |
static boolean |
isPeriodic(List<Integer> values,
int n)
Returns true if the values in the argument list periodically repeat
exactly n times, and false otherwise.
|
public static final int MIN_PRIME
public static int incr(int x)
x + 1
)
without overflow. Returns Integer.MAX_VALUE
if the increment
of x would overflow.x
- a valuepublic static boolean areIdentical(List<Integer> values)
values
- a sorted listIllegalArgumentException
- if values is emptypublic static boolean areUnique(List<Integer> values)
values
- a list of valuespublic static boolean isPeriodic(List<Integer> values, int n)
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.
values
- a list of valuesn
- the number of repeating periods to check for