From 4afe573a68ef848efe075a4a1710890f7b7c5f69 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Tue, 17 Jul 2018 11:39:51 +0200 Subject: [PATCH] Add Objects.requireNonNullOrEmpty --- .../main/java/org/jivesoftware/smack/util/Objects.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/smack-core/src/main/java/org/jivesoftware/smack/util/Objects.java b/smack-core/src/main/java/org/jivesoftware/smack/util/Objects.java index 26d0bbe85..80e15d4b2 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/util/Objects.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/util/Objects.java @@ -16,6 +16,8 @@ */ package org.jivesoftware.smack.util; +import java.util.Collection; + public class Objects { public static T requireNonNull(T obj, String message) { @@ -29,6 +31,13 @@ public class Objects { return requireNonNull(obj, null); } + public static > 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)); }