-
Notifications
You must be signed in to change notification settings - Fork 0
/
Preconditions.java
53 lines (47 loc) · 1.32 KB
/
Preconditions.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* @author Clément Petit (282626)
* @author Yanis Berkani (271348)
*/
package ch.epfl.gameboj;
public interface Preconditions {
/**
* throws the exception IllegalArgumentException if its argument is false do
* nothing otherwise.
*
* @param b
* the condition
* @throws IllegalArgumentException
* if the argument is false
*/
public static void checkArgument(boolean b) {
if (!b) {
throw new IllegalArgumentException();
}
}
/**
* return the argument if it is included between 0 and FF.
*
* @param v
* the integer checked (must be included between 0 and FF)
* @throws IllegalArgumentException
* if the argument is invalid
* @return the argument
*/
public static int checkBits8(int v) {
checkArgument(v >= 0 && v <= 0xFF);
return v;
}
/**
* return the argument if it is included between 0 and FFFF.
*
* @param v
* the integer checked (must be included between 0 and FFFF)
* @throws IllegalArgumentException
* if the argument is invalid
* @return the argument
*/
public static int checkBits16(int v) {
checkArgument(v >= 0 && v <= 0xFFFF);
return v;
}
}