forked from nus-cs2103-AY1718S2/addressbook-level2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Utils.java
37 lines (33 loc) · 925 Bytes
/
Utils.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
package seedu.addressbook.common;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
/**
* Utility methods
*/
public class Utils {
/**
* Returns true if any of the given items are null.
*/
public static boolean isAnyNull(Object... items) {
for (Object item : items) {
if (item == null) {
return true;
}
}
return false;
}
/**
* Returns true if every element the given collection are unique by {@link Object#equals(Object)}.
*/
public static boolean elementsAreUnique(Collection<?> items) {
final Set<Object> testSet = new HashSet<>();
for (Object item : items) {
final boolean itemAlreadyExists = !testSet.add(item); // see Set documentation
if (itemAlreadyExists) {
return false;
}
}
return true;
}
}