KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > xml > NodeListImpl


1 /*
2  * @(#)HashMapNode.java 1.36 02/03/21
3  *
4  * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7 package org.enhydra.xml;
8
9 import java.util.ArrayList JavaDoc;
10 import java.util.List JavaDoc;
11
12 import org.w3c.dom.Node JavaDoc;
13 import org.w3c.dom.NodeList JavaDoc;
14
15
16
17 /**
18  * @author Tweety
19  *
20  * A class representing a node in a meta-data tree, which implements
21  * the <a HREF="../../../../api/org/w3c/dom/NodeList.html">
22  *
23  * <p> Namespaces are ignored in this implementation. The terms "tag
24  * name" and "node name" are always considered to be synonymous.
25  *
26  * @version 1.0
27  */

28 public class NodeListImpl implements NodeList JavaDoc {
29
30     /**
31      * List of <code>Node</code>s.
32      */

33     List JavaDoc nodes;
34
35
36     /**
37      * Constructs an empty <code>NodeListImpl</code>.
38      */

39     public NodeListImpl() {
40         this.nodes = new ArrayList JavaDoc();
41     }
42     
43     
44     /**
45      * Constructs <code>NodeListImpl</code> with the given list of nodes.
46      *
47      * @param nodes list of nodes.
48      */

49     public NodeListImpl(List JavaDoc nodes) {
50         this.nodes = nodes;
51     }
52
53
54     /**
55      * Returns the count of nodes.
56      *
57      * @return the count of nodes.
58      */

59     public int getLength() {
60         return nodes.size();
61     }
62
63
64     /**
65      * Returns the <code>Node</code> with the given index.
66      *
67      * @param index node index.
68      *
69      * @return the <code>Node</code> with the given index.
70      */

71     public Node JavaDoc item(int index) {
72         if (index < 0 || index > nodes.size()) {
73             return null;
74         }
75         return (Node JavaDoc) nodes.get(index);
76     }
77
78     
79     /**
80      * Appends the given list to the end of the existing one.
81      *
82      * @param list list to add, as <code>NodeListImpl</code>.
83      *
84      * @return this as </code>NodeList</code>.
85      */

86     public NodeList JavaDoc append(NodeListImpl list) {
87         this.nodes.addAll(list.nodes);
88         return this;
89     }
90     
91 }
Popular Tags