• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007 The Android Open Source Project
3  *
4  * Licensed under the Eclipse Public License, Version 1.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  *
8  *      http://www.eclipse.org/org/documents/epl-v10.php
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.ide.eclipse.adt.internal.editors.mock;
18 
19 import org.w3c.dom.Node;
20 import org.w3c.dom.NodeList;
21 
22 import java.util.ArrayList;
23 
24 
25 /**
26  * A quick mock implementation of NodeList on top of ArrayList.
27  */
28 public class MockNodeList implements NodeList {
29 
30     ArrayList<MockXmlNode> mChildren;
31 
32     /**
33     * Constructs a node list from a given children list.
34     *
35     * @param children The children list. Can be null.
36      */
MockNodeList(MockXmlNode[] children)37     public MockNodeList(MockXmlNode[] children) {
38         mChildren = new ArrayList<MockXmlNode>();
39         if (children != null) {
40             for (MockXmlNode n : children) {
41                 mChildren.add(n);
42             }
43         }
44     }
45 
46     @Override
getLength()47     public int getLength() {
48         return mChildren.size();
49     }
50 
51     @Override
item(int index)52     public Node item(int index) {
53         if (index >= 0 && index < mChildren.size()) {
54             return mChildren.get(index);
55         }
56         return null;
57     }
58 
getArrayList()59     public ArrayList<MockXmlNode> getArrayList() {
60         return mChildren;
61     }
62 }
63