io.github.bhowell2.apilib.checks.utils.CollectionUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of api-lib Show documentation
Show all versions of api-lib Show documentation
API verification library.
The newest version!
package io.github.bhowell2.apilib.checks.utils;
import java.util.Collection;
/**
* @author Blake Howell
*/
public class CollectionUtils {
@SafeVarargs
public static void requireNonNullEntries(T... ary) {
requireNonNullEntries("Cannot have null value in varargs.", ary);
}
@SafeVarargs
public static void requireNonNullEntries(String errMsg, T... ary) {
for (Object o : ary) {
if (o == null) {
throw new IllegalArgumentException(errMsg);
}
}
}
public static void requireNonNullEntries(Collection> c) {
requireNonNullEntries(c, "Cannot have null entry in collection.");
}
public static void requireNonNullEntries(Collection> c, String errMsg) {
for (Object o : c) {
if (o == null) {
throw new IllegalArgumentException(errMsg);
}
}
}
public static void requireSizeGreaterThan(int size, Collection> c) {
requireSizeGreaterThan(size, c, "Collection size must be greater than " + size + ".");
}
public static void requireSizeGreaterThan(int size, Collection> c, String errMsg) {
IntegerUtils.requireIntGreaterThan(size, c.size(), errMsg);
}
public static void requireNonEmptyStrings(Collection c) {
for (String s : c) {
StringUtils.requireNonEmptyString(s, "String in collection cannot be empty.");
}
}
}