Java Collection Empty isNullOrEmpty(final Collection c)

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

Description

Checks whether the given Collection is null or is empty.

License

Open Source License

Parameter

Parameter Description
c The Collection to check

Return

true if c == null || c.isEmpty() == true,
false otherwise

Declaration

public static boolean isNullOrEmpty(final Collection<?> c) 

Method Source Code

//package com.java2s;
/**/*from   w ww .j a va 2 s. c om*/
 * Copyright (C) 2014 The Holodeck B2B Team, Sander Fieten
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.util.Collection;

import java.util.Iterator;

import java.util.Map;

public class Main {
    /**
     * Checks whether the given String is <code>null</code> or is an empty string, i.e. does not contain any other
     * characters then whitespace.
     * 
     * @param s     The string to check
     * @return      <code>true</code> if <code>s == null || s.trim().isEmpty() == true</code>,<br>
     *              <code>false</code> otherwise
     */
    public static boolean isNullOrEmpty(final String s) {
        return s == null || s.trim().isEmpty();
    }

    /**
     * Checks whether the given Collection is <code>null</code> or is empty.
     * 
     * @param c     The Collection to check
     * @return      <code>true</code> if <code>c == null || c.isEmpty() == true</code>,<br>
     *              <code>false</code> otherwise
     */
    public static boolean isNullOrEmpty(final Collection<?> c) {
        return c == null || c.isEmpty();
    }

    /**
     * Checks whether the given Map is <code>null</code> or is empty.
     * 
     * @param m     The Map to check
     * @return      <code>true</code> if <code>m == null || m.isEmpty() == true</code>,<br>
     *              <code>false</code> otherwise
     */
    public static boolean isNullOrEmpty(final Map<?, ?> m) {
        return m == null || m.isEmpty();
    }

    /**
     * Checks whether the given Iterator is <code>null</code> or does not contain any more objects.
     * 
     * @param i     The Iterator to check
     * @return      <code>true</code> if <code>i == null || i.hasNext() == true</code>,<br>
     *              <code>false</code> otherwise
     */
    public static boolean isNullOrEmpty(final Iterator<?> i) {
        return i == null || !i.hasNext();
    }
}

Related

  1. isNullOrEmpty(Collection collection)
  2. isNullOrEmpty(Collection list)
  3. isNullOrEmpty(Collection obj)
  4. isNullOrEmpty(Collection s)
  5. isNullOrEmpty(Collection values)
  6. isNullOrEmpty(final Collection collection)
  7. isNullOrEmpty(final Collection value)
  8. isNullOrEmpty(final Collection collection)
  9. isNullOrEmpty(T collection)