org.kiwiproject.collect.KiwiSets Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kiwi Show documentation
Show all versions of kiwi Show documentation
Kiwi is a utility library. We really like Google's Guava, and also use Apache Commons.
But if they don't have something we need, and we think it is useful, this is where we put it.
package org.kiwiproject.collect;
import static java.util.Objects.nonNull;
import lombok.experimental.UtilityClass;
import java.util.Set;
/**
* Utility methods for working with {@link Set} instances.
*/
@UtilityClass
public class KiwiSets {
/**
* Checks whether the specified set is null or empty.
*
* @param set the set
* @param the type of items in the set
* @return {@code true} if set is null or empty; {@code false} otherwise
*/
public static boolean isNullOrEmpty(Set set) {
return set == null || set.isEmpty();
}
/**
* Checks whether the specified is neither null nor empty.
*
* @param set the set
* @param the type of items in the set
* @return {@code true} if set is neither null nor empty; {@code false} otherwise
*/
public static boolean isNotNullOrEmpty(Set set) {
return !isNullOrEmpty(set);
}
/**
* Checks whether the specified list is non-null and has only one item.
*
* @param set the set
* @param the type of items in the set
* @return {@code true} if list is non-null and has exactly one item; {@code false}
*/
public static boolean hasOneElement(Set set) {
return nonNull(set) && set.size() == 1;
}
}