blob: 8ba744e4f6c85b098944e43b4bf0986bce78b53f (
plain)
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
54
55
56
57
58
|
package ch.epfl.xblast;
import ch.epfl.cs108.Sq;
import java.util.Collection;
import java.util.Objects;
/**
* ArgumentChecker.
*
* @author Pacien TRAN-GIRARD (261948)
* @author Timothée FLOURE (257420)
*/
public final class ArgumentChecker {
/**
* Returns the given value if it is non-negative.
*
* @param v the tested value
* @return the given value if non-negative
* @throws IllegalArgumentException if the value is inferior to 0
*/
public static int requireNonNegative(int v) {
if (v < 0)
throw new IllegalArgumentException();
return v;
}
/**
* Requires the given Collection to be non-empty and returns it or throw an IllegalArgumentException otherwise.
*
* @param c the Collection to check
* @param <T> the Collection type
* @return the checked Collection
*/
public static <T extends Collection> T requireNonEmpty(T c) {
if (Objects.requireNonNull(c).isEmpty())
throw new IllegalArgumentException();
return c;
}
/**
* Requires the given Sequence to be non-empty and returns it or throw an IllegalArgumentException otherwise.
*
* @param s the sequence to check
* @param <T> the sequence type
* @return the checked sequence
*/
public static <T extends Sq> T requireNonEmpty(T s) {
if (Objects.requireNonNull(s).isEmpty())
throw new IllegalArgumentException();
return s;
}
}
|