All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.kiwiproject.collect.KiwiSets Maven / Gradle / Ivy

Go to download

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.

There is a newer version: 4.4.0
Show newest version
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;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy