/
Assert.java
35 lines (31 loc) · 898 Bytes
/
Assert.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
package me.prettyprint.cassandra.utils;
/**
* A generic low weight assert utility, very similar with Spring's Assert class,
* just without the dependency on Spring
*
* See for example
* http://www.jarvana.com/jarvana/view/org/springframework/spring
* /1.2.9/spring-1.2.9-javadoc.jar!/org/springframework/util/Assert.html
*
* @author Ran Tavory
*
*/
public final class Assert {
public static void notNull(Object object, String message) {
if (object == null) {
throw new IllegalArgumentException(message);
}
}
public static void noneNull(Object... object) {
for (int i = 0; i < object.length; ++i) {
if (object[i] == null) {
throw new NullPointerException("Null not allowed, number " + (i + 1));
}
}
}
public static void isTrue(boolean b, String message) {
if (!b) {
throw new IllegalArgumentException(message);
}
}
}