Java Collection Contain containsNullsOrEmptyStrings(Collection c)

Here you can find the source of containsNullsOrEmptyStrings(Collection c)

Description

Returns true if c contains empty Strings or null references.

License

Apache License

Parameter

Parameter Description
c a Collection

Return

true if c contains empty Strings or null references.

Declaration

public static boolean containsNullsOrEmptyStrings(Collection<String> c) 

Method Source Code

//package com.java2s;
/*/*  w w w . j a  v  a2 s  . co m*/
 * Copyright 2014 Johns Hopkins University
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.Collection;

public class Main {
    /**
     * Returns true if {@code c} contains empty Strings or {@code null} references.
     *
     * @param c a Collection
     * @return true if {@code c} contains empty Strings or {@code null} references.
     */
    public static boolean containsNullsOrEmptyStrings(Collection<String> c) {
        for (String s : c) {
            if (isEmptyOrNull(s)) {
                return true;
            }
        }

        return false;
    }

    /**
     * Returns true if {@code array} contains empty Strings or {@code null} references.
     *
     * @param array an array
     * @return true if {@code array} contains empty Strings or {@code null} references.
     */
    public static boolean containsNullsOrEmptyStrings(String[] array) {
        for (String s : array) {
            if (isEmptyOrNull(s)) {
                return true;
            }
        }

        return false;
    }

    /**
     * Returns true if <code>s</code> is empty or <code>null</code>.
     *
     * @param s a string
     * @return true if <code>s</code> is empty or <code>null</code>.
     */
    public static boolean isEmptyOrNull(String s) {
        return isNull(s) || isEmpty(s);
    }

    /**
     * Returns <code>true</code> if <code>o</code> is <code>null</code>.
     *
     * @param o a object
     * @return true if <code>o</code> is null
     */
    public static boolean isNull(Object o) {
        return o == null;
    }

    /**
     * Returns <code>true</code> if <code>s</code> is the empty string.  Returns
     * <code>false</code> if <code>s</code> is <code>null</code> or not empty.
     *
     * @param s a string
     * @return true if <code>s</code> is empty
     */
    public static boolean isEmpty(String s) {
        if (s == null) {
            return false;
        }
        return s.trim().length() == 0;
    }
}

Related

  1. containsNoNull(final Collection c, final String s)
  2. containsNoNulls(Collection container)
  3. containsNull(Collection collection)
  4. containsNull(Collection args)
  5. containsNull(final Collection c)
  6. containsNumber(Collection collection, Number number)
  7. containsObject(Collection c, T o)
  8. containsObjectIdentity(Collection collection, Object object)
  9. containsOne(final Collection sup, final Collection parts)

  10. HOME | Copyright © www.java2s.com 2016