01: /* Copyright 2002-2004 Elliotte Rusty Harold
02:
03: This library is free software; you can redistribute it and/or modify
04: it under the terms of version 2.1 of the GNU Lesser General Public
05: License as published by the Free Software Foundation.
06:
07: This library is distributed in the hope that it will be useful,
08: but WITHOUT ANY WARRANTY; without even the implied warranty of
09: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10: GNU Lesser General Public License for more details.
11:
12: You should have received a copy of the GNU Lesser General Public
13: License along with this library; if not, write to the
14: Free Software Foundation, Inc., 59 Temple Place, Suite 330,
15: Boston, MA 02111-1307 USA
16:
17: You can contact Elliotte Rusty Harold by sending e-mail to
18: elharo@metalab.unc.edu. Please include the word "XOM" in the
19: subject line. The XOM home page is located at http://www.xom.nu/
20: */
21:
22: package nu.xom;
23:
24: import java.util.ArrayList;
25: import java.util.List;
26:
27: /**
28: *
29: * <p>
30: * A read-only list of elements for traversal purposes.
31: * Changes to the document from which this list was generated
32: * are not reflected in this list. Changes to the individual
33: * <code>Element</code> objects in the list are reflected.
34: * </p>
35: *
36: * @author Elliotte Rusty Harold
37: * @version 1.0
38: *
39: *
40: */
41: public final class Elements {
42:
43: private List elements = new ArrayList(1);
44:
45: // non-public constructor to prevent instantiation
46: Elements() {
47: }
48:
49: /**
50: * <p>
51: * Returns the number of elements in the list.
52: * This is guaranteed non-negative.
53: * </p>
54: *
55: * @return the number of elements in the list
56: */
57: public int size() {
58: return elements.size();
59: }
60:
61: /**
62: * <p>
63: * Returns the index<sup>th</sup> element in the list.
64: * The first element has index 0. The last element
65: * has index <code>size()-1</code>.
66: * </p>
67: *
68: * @param index the element to return
69: *
70: * @return the element at the specified position
71: *
72: * @throws IndexOutOfBoundsException if index is negative
73: * or greater than or equal to the size of the list
74: */
75: public Element get(int index) {
76: return (Element) elements.get(index);
77: }
78:
79: // Add the specified Element object to the list
80: void add(Element element) {
81: elements.add(element);
82: }
83:
84: }
|