mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-22 12:02:05 +01:00
Merge pull request #252 from vanitasvitae/requireNonNullOrEmpty
Add Objects.requireNonNullOrEmpty
This commit is contained in:
commit
cf2b3ef634
1 changed files with 9 additions and 0 deletions
|
@ -16,6 +16,8 @@
|
|||
*/
|
||||
package org.jivesoftware.smack.util;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class Objects {
|
||||
|
||||
public static <T> T requireNonNull(T obj, String message) {
|
||||
|
@ -29,6 +31,13 @@ public class Objects {
|
|||
return requireNonNull(obj, null);
|
||||
}
|
||||
|
||||
public static <T extends Collection<?>> T requireNonNullOrEmpty(T collection, String message) {
|
||||
if (requireNonNull(collection).isEmpty()) {
|
||||
throw new IllegalArgumentException(message);
|
||||
}
|
||||
return collection;
|
||||
}
|
||||
|
||||
public static boolean equals(Object a, Object b) {
|
||||
return a == b || (a != null && a.equals(b));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue