Java XML NodeList iterable(final NodeList list)

Here you can find the source of iterable(final NodeList list)

Description

iterable

License

Open Source License

Declaration

@SuppressWarnings("unchecked")
    public static Iterable<Node> iterable(final NodeList list) 

Method Source Code

//package com.java2s;
/*/*from  w  w  w .  java  2s.c o m*/
   Copyright (c) 2009-2011 Olivier Chafik, All Rights Reserved
       
   This file is part of JNAerator (http://jnaerator.googlecode.com/).
       
   JNAerator 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.
       
   JNAerator 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 JNAerator.  If not, see <http://www.gnu.org/licenses/>.
*/

import java.util.Collections;

import java.util.Iterator;

import java.util.NoSuchElementException;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class Main {
    @SuppressWarnings("unchecked")
    public static Iterable<Node> iterable(final NodeList list) {
        if (list == null)
            return Collections.EMPTY_LIST;

        return new Iterable<Node>() {
            int nextPos = 0;

            public Iterator<Node> iterator() {
                return new Iterator<Node>() {
                    public Node next() {
                        if (nextPos >= list.getLength())
                            throw new NoSuchElementException();
                        return list.item(nextPos++);
                    }

                    public boolean hasNext() {
                        return nextPos < list.getLength();
                    }

                    public void remove() {
                        throw new UnsupportedOperationException();
                    }
                };
            }
        };
    }
}

Related

  1. isEmpty(NodeList nl)
  2. isListEmpty(NodeList list)
  3. isNodeListEmpty(final NodeList nodeList)
  4. isNotEmpty(NodeList nodeList)
  5. isNullOrEmpty(NodeList nodeList)
  6. iterable(NodeList nodeList)
  7. iterableNodes(final NodeList nodeList)
  8. iterableNodes(final NodeList nodeList)
  9. listOf(final NodeList nodeList)