forked from gooddata/gooddata-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValidate.java
More file actions
37 lines (31 loc) · 1.03 KB
/
Copy pathValidate.java
File metadata and controls
37 lines (31 loc) · 1.03 KB
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
package com.gooddata;
import java.util.Collection;
import java.util.Iterator;
/**
* Validation utils
*/
public abstract class Validate {
public static <T> T notNull(T value, String aargument) {
if (value == null) {
throw new IllegalArgumentException(aargument + " can't be null");
}
return value;
}
public static <T extends CharSequence> T notEmpty(T value, String argument) {
notNull(value, argument);
if (value.toString().trim().length() == 0) {
throw new IllegalArgumentException(argument + " can't be empty");
}
return value;
}
public static <T extends Collection> T noNullElements(T collection, String argument) {
notNull(collection, argument);
int i = 0;
for (Iterator it = collection.iterator(); it.hasNext(); i++) {
if (it.next() == null) {
throw new IllegalArgumentException(argument + " contains null element at index: " + i);
}
}
return collection;
}
}