1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-24 23:32:05 +01:00

Add Objects.requireNonNullOrEmpty

This commit is contained in:
Paul Schaub 2018-07-17 11:39:51 +02:00
parent 8011ba96bb
commit 4afe573a68
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -16,6 +16,8 @@
*/ */
package org.jivesoftware.smack.util; package org.jivesoftware.smack.util;
import java.util.Collection;
public class Objects { public class Objects {
public static <T> T requireNonNull(T obj, String message) { public static <T> T requireNonNull(T obj, String message) {
@ -29,6 +31,13 @@ public class Objects {
return requireNonNull(obj, null); 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) { public static boolean equals(Object a, Object b) {
return a == b || (a != null && a.equals(b)); return a == b || (a != null && a.equals(b));
} }