Java Collection Empty nullOrEmpty(Collection coll)

Here you can find the source of nullOrEmpty(Collection coll)

Description

null Or Empty

License

Apache License

Declaration

public final static boolean nullOrEmpty(Collection<?> coll) 

Method Source Code


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

import java.util.Collection;
import java.util.Map;

public class Main {
    /**/*from w ww .  j  av  a2s.co  m*/
     * (S is null) OR ( S is empty)
     *  
     *  Empty in the sense of only white space content.
     *  
     * @param s 
     * 
     * @return ((s==null)) &or; (s.isEmpty())
     */
    public final static boolean nullOrEmpty(String s) {
        return !notNullAndEmpty(s);
    }

    public final static boolean nullOrEmpty(Collection<?> coll) {
        return coll == null || coll.isEmpty();
    }

    public final static boolean nullOrEmpty(Map<?, ?> coll) {
        return coll == null || coll.isEmpty();
    }

    /**
    * (S is not null) AND ( S is not empty)
    *  
    *  Empty in the sense of not white space content.
    *  
    * @param s 
    * 
    * @return (!(s==null)) &and; (!s.isEmpty())
    */
    public final static boolean notNullAndEmpty(String s) {
        if (s == null)
            return false;
        if (s.trim().length() <= 0)
            return false;
        return true;
    }

    public final static boolean notNullAndEmpty(Collection<?> coll) {
        return coll != null && !coll.isEmpty();
    }

    public final static boolean notNullAndEmpty(Map<?, ?> coll) {
        return coll != null && !coll.isEmpty();
    }
}

Related

  1. isNullOrEmpty(final Collection c)
  2. isNullOrEmpty(final Collection collection)
  3. isNullOrEmpty(final Collection value)
  4. isNullOrEmpty(final Collection collection)
  5. isNullOrEmpty(T collection)
  6. nullOrEmpty(Collection tested)
  7. nullOrEmpty(Collection c)
  8. nullOrEmpty(final Collection in)
  9. nullOrEmptyToDefault(final Collection collection, final Collection defaultValue)