01: /*
02: * @(#)HashMapNode.java 1.36 02/03/21
03: *
04: * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
05: * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
06: */
07: package org.enhydra.xml;
08:
09: import java.util.ArrayList;
10: import java.util.List;
11:
12: import org.w3c.dom.Node;
13: import org.w3c.dom.NodeList;
14:
15: /**
16: * @author Tweety
17: *
18: * A class representing a node in a meta-data tree, which implements
19: * the <a href="../../../../api/org/w3c/dom/NodeList.html">
20: *
21: * <p> Namespaces are ignored in this implementation. The terms "tag
22: * name" and "node name" are always considered to be synonymous.
23: *
24: * @version 1.0
25: */
26: public class NodeListImpl implements NodeList {
27:
28: /**
29: * List of <code>Node</code>s.
30: */
31: List nodes;
32:
33: /**
34: * Constructs an empty <code>NodeListImpl</code>.
35: */
36: public NodeListImpl() {
37: this .nodes = new ArrayList();
38: }
39:
40: /**
41: * Constructs <code>NodeListImpl</code> with the given list of nodes.
42: *
43: * @param nodes list of nodes.
44: */
45: public NodeListImpl(List nodes) {
46: this .nodes = nodes;
47: }
48:
49: /**
50: * Returns the count of nodes.
51: *
52: * @return the count of nodes.
53: */
54: public int getLength() {
55: return nodes.size();
56: }
57:
58: /**
59: * Returns the <code>Node</code> with the given index.
60: *
61: * @param index node index.
62: *
63: * @return the <code>Node</code> with the given index.
64: */
65: public Node item(int index) {
66: if (index < 0 || index > nodes.size()) {
67: return null;
68: }
69: return (Node) nodes.get(index);
70: }
71:
72: /**
73: * Appends the given list to the end of the existing one.
74: *
75: * @param list list to add, as <code>NodeListImpl</code>.
76: *
77: * @return this as </code>NodeList</code>.
78: */
79: public NodeList append(NodeListImpl list) {
80: this.nodes.addAll(list.nodes);
81: return this;
82: }
83:
84: }
|