Java Collection Check isBlank(final Collection c)

Here you can find the source of isBlank(final Collection c)

Description

Check if a collection of a string is blank.

License

Apache License

Parameter

Parameter Description
c a parameter

Declaration

public static boolean isBlank(final Collection<String> c) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.Collection;

public class Main {
    /**// w  w w. jav a  2  s .  com
     * Check if a collection of a string is blank.
     *
     * @param c
     * @return
     */
    public static boolean isBlank(final Collection<String> c) {
        if (c == null || c.isEmpty()) {
            return false;
        }
        for (final String text : c) {
            if (isNotBlank(text)) {
                return false;
            }
        }
        return true;
    }

    /**
     * Check if a string is blank.
     *
     * @param str
     * @return
     */
    public static boolean isBlank(final String str) {
        if (str == null || str.length() == 0) {
            return true;
        }
        for (int i = 0; i < str.length(); i++) {
            if (!Character.isWhitespace(str.charAt(i))) {
                return false;
            }
        }
        return true;
    }

    /**
     * Check if a collection of a string is empty.
     *
     * @param c
     * @return
     */
    public static boolean isEmpty(final Collection<String> c) {
        if (c == null || c.isEmpty()) {
            return false;
        }
        for (final String text : c) {
            if (isNotEmpty(text)) {
                return false;
            }
        }
        return true;
    }

    /**
     * Check if a string is empty.
     *
     * @param text
     * @return
     */
    public static final boolean isEmpty(final String text) {
        return text == null || text.length() == 0;
    }

    /**
     * Check if a collection of a string is not blank.
     *
     * @param c
     * @return
     */
    public static boolean isNotBlank(final Collection<String> c) {
        return !isBlank(c);
    }

    /**
     * Check if a string is not blank.
     *
     * @param str
     * @return
     */
    public static boolean isNotBlank(final String str) {
        return !isBlank(str);
    }

    /**
     * Check if a collection of a string is not empty.
     *
     * @param c
     * @return
     */
    public static boolean isNotEmpty(final Collection<String> c) {
        return !isEmpty(c);
    }

    /**
     * Check if a string is not empty.
     *
     * @param text
     * @return
     */
    public static final boolean isNotEmpty(final String text) {
        return !isEmpty(text);
    }
}

Related

  1. isAssignableFrom(final Collection> classes, final Class objectClass)
  2. isBlank(Collection coll)
  3. isBlank(Collection c)
  4. isBlank(Collection c)
  5. isBlank(Collection collection)
  6. isBlank(final Collection collection)
  7. isBlankAll(Collection... collections)
  8. isC2InC1(Collection c1, Collection c2)
  9. isClassCollection(Class c)