Java XML NodeList isEmpty(NodeList nl)

Here you can find the source of isEmpty(NodeList nl)

Description

Test if node list is null or empty.

License

Apache License

Declaration

public static boolean isEmpty(NodeList nl) 

Method Source Code

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

import java.lang.reflect.Method;

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

import org.w3c.dom.NodeList;

public class Main {
    /** Test if array is null or empty. */
    public static boolean isEmpty(byte[] ba) {
        return ba == null || ba.length == 0;
    }/*w  ww.ja  v a  2s .co  m*/

    /** Test if array is null or empty. */
    public static boolean isEmpty(Object[] oa) {
        return oa == null || oa.length == 0;
    }

    /** Test if string is null or empty. */
    public static boolean isEmpty(CharSequence s) {
        return s == null || s.length() == 0;
    }

    /** Test if string is null or empty. */
    public static boolean isEmpty(Appendable s) {
        int length = -1;
        if (s != null) {
            Method m = null;
            Class<? extends Appendable> sclass = s.getClass();
            try {
                m = sclass.getMethod("size");
            } catch (NoSuchMethodException e1) {
                try {
                    m = sclass.getMethod("length");
                } catch (NoSuchMethodException e2) {
                    try {
                        m = sclass.getMethod("getLength");
                    } catch (NoSuchMethodException e3) {
                    }
                }
            }
            if (m != null) {
                try {
                    length = (Integer) m.invoke(s);
                } catch (Exception e) {
                }
            }
        }
        return s == null || length == 0;
    }

    /** Test if node list is null or empty. */
    public static boolean isEmpty(NodeList nl) {
        return nl == null || nl.getLength() == 0;
    }

    /** Test if map is null or empty. */
    public static boolean isEmpty(Map<?, ?> m) {
        return m == null || m.size() == 0;
    }

    /** Test if collection is null or empty. */
    public static boolean isEmpty(Collection<?> c) {
        return c == null || c.size() == 0;
    }
}

Related

  1. getXmlNodeValue(NodeList nodeList)
  2. hasElementNodes(NodeList list)
  3. hasImageNodes(NodeList nodeList)
  4. indexOf(NodeList nodeList, String tagName, int startIdx)
  5. isEmpty(@Nullable final NodeList aNL)
  6. isListEmpty(NodeList list)
  7. isNodeListEmpty(final NodeList nodeList)
  8. isNotEmpty(NodeList nodeList)
  9. isNullOrEmpty(NodeList nodeList)