View Javadoc
1   /*
2    * Copyright (c) 2002-2025 Gargoyle Software Inc.
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    * https://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  package org.htmlunit.html;
16  
17  import java.io.Serializable;
18  import java.util.AbstractList;
19  import java.util.List;
20  
21  import org.w3c.dom.Node;
22  
23  /**
24   * An implementation of DomNodeList that is static.
25   *
26   * @author Ahmed Ashour
27   * @author Ronald Brill
28   */
29  class StaticDomNodeList extends AbstractList<DomNode> implements DomNodeList<DomNode>, Serializable {
30  
31      private final List<DomNode> elements_;
32  
33      StaticDomNodeList(final List<DomNode> elements) {
34          super();
35          elements_ = elements;
36      }
37  
38      /**
39       * {@inheritDoc}
40       */
41      @Override
42      public int getLength() {
43          return elements_.size();
44      }
45  
46      /**
47       * {@inheritDoc}
48       */
49      @Override
50      public int size() {
51          return getLength();
52      }
53  
54      /**
55       * {@inheritDoc}
56       */
57      @Override
58      public Node item(final int index) {
59          return get(index);
60      }
61  
62      /**
63       * {@inheritDoc}
64       */
65      @Override
66      public DomNode get(final int index) {
67          return elements_.get(index);
68      }
69  
70  }