NodeListImpl.java revision 6b811c5daec1b28e6f63b57f98a032236f2c3cf7
1/* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package org.apache.harmony.xml.dom; 18 19import org.w3c.dom.Node; 20import org.w3c.dom.NodeList; 21 22import java.util.ArrayList; 23import java.util.List; 24 25/** 26 * Provides a straightforward implementation of the corresponding W3C DOM 27 * interface. The class is used internally only, thus only notable members that 28 * are not in the original interface are documented (the W3C docs are quite 29 * extensive). Hope that's ok. 30 * <p> 31 * Some of the fields may have package visibility, so other classes belonging to 32 * the DOM implementation can easily access them while maintaining the DOM tree 33 * structure. 34 */ 35public class NodeListImpl implements NodeList { 36 37 private List<NodeImpl> children; 38 39 NodeListImpl() { 40 children = new ArrayList<NodeImpl>(); 41 } 42 43 NodeListImpl(List<NodeImpl> list) { 44 children = list; 45 } 46 47 void add(NodeImpl node) { 48 children.add(node); 49 } 50 51 public int getLength() { 52 return children.size(); 53 } 54 55 public Node item(int index) { 56 if (index >= children.size()) { 57 return null; 58 } else { 59 return children.get(index); 60 } 61 } 62 63} 64