1 /* Copyright 2002-2004 Elliotte Rusty Harold
2 
3    This library is free software; you can redistribute it and/or modify
4    it under the terms of version 2.1 of the GNU Lesser General Public
5    License as published by the Free Software Foundation.
6 
7    This library is distributed in the hope that it will be useful,
8    but WITHOUT ANY WARRANTY; without even the implied warranty of
9    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@ibiblio.org. 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 
44     private List elements = new ArrayList(1);
45 
46     // non-public constructor to prevent instantiation
Elements()47     Elements() {}
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      */
size()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      */
get(int index)75     public Element get(int index) {
76         return (Element) elements.get(index);
77     }
78 
79 
80     // Add the specified Element object to the list
add(Element element)81     void add(Element element) {
82         elements.add(element);
83     }
84 
85 }