Home | History | Annotate | Download | only in dom
      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 
     17 package org.apache.harmony.xml.dom;
     18 
     19 import java.util.ArrayList;
     20 import java.util.List;
     21 import org.w3c.dom.Node;
     22 import org.w3c.dom.NodeList;
     23 
     24 /**
     25  * Provides a straightforward implementation of the corresponding W3C DOM
     26  * interface. The class is used internally only, thus only notable members that
     27  * are not in the original interface are documented (the W3C docs are quite
     28  * extensive). Hope that's ok.
     29  * <p>
     30  * Some of the fields may have package visibility, so other classes belonging to
     31  * the DOM implementation can easily access them while maintaining the DOM tree
     32  * structure.
     33  */
     34 public class NodeListImpl implements NodeList {
     35 
     36     private List<NodeImpl> children;
     37 
     38     NodeListImpl() {
     39         children = new ArrayList<NodeImpl>();
     40     }
     41 
     42     NodeListImpl(List<NodeImpl> list) {
     43         children = list;
     44     }
     45 
     46     void add(NodeImpl node) {
     47         children.add(node);
     48     }
     49 
     50     public int getLength() {
     51         return children.size();
     52     }
     53 
     54     public Node item(int index) {
     55         if (index >= children.size()) {
     56             return null;
     57         } else {
     58             return children.get(index);
     59         }
     60     }
     61 
     62 }
     63