KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xerces > impl > xs > util > StringListImpl


1 /*
2  * Copyright 2002,2003-2004 The Apache Software Foundation.
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  *
8  * http://www.apache.org/licenses/LICENSE-2.0
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 org.apache.xerces.impl.xs.util;
18
19 import org.apache.xerces.xs.StringList;
20 import java.util.Vector JavaDoc;
21 /**
22  * Containts a list of Object's.
23  *
24  * @xerces.internal
25  *
26  * @author Sandy Gao, IBM
27  *
28  * @version $Id: StringListImpl.java,v 1.8 2004/10/06 15:14:50 mrglavas Exp $
29  */

30 public class StringListImpl implements StringList {
31
32     /**
33      * An immutable empty list.
34      */

35     public static final StringList EMPTY_LIST = new StringList () {
36         public int getLength() {
37             return 0;
38         }
39         public boolean contains(String JavaDoc item) {
40             return false;
41         }
42         public String JavaDoc item(int index) {
43             return null;
44         }
45     };
46     
47     // The array to hold all data
48
private String JavaDoc[] fArray = null;
49     // Number of elements in this list
50
private int fLength = 0;
51
52     // REVISIT: this is temp solution. In general we need to use this class
53
// instead of the Vector.
54
private Vector JavaDoc fVector;
55
56     public StringListImpl(Vector JavaDoc v) {
57         fVector = v;
58         fLength = (v == null) ? 0 : v.size();
59     }
60
61     /**
62      * Construct an XSObjectList implementation
63      *
64      * @param array the data array
65      * @param length the number of elements
66      */

67     public StringListImpl(String JavaDoc[] array, int length) {
68         fArray = array;
69         fLength = length;
70     }
71
72     /**
73      * The number of <code>Objects</code> in the list. The range of valid
74      * child node indices is 0 to <code>length-1</code> inclusive.
75      */

76     public int getLength() {
77         return fLength;
78     }
79
80     /**
81      * Checks if the <code>GenericString</code> <code>item</code> is a member
82      * of this list.
83      * @param item <code>GenericString</code> whose presence in this list is
84      * to be tested.
85      * @return True if this list contains the <code>GenericString</code>
86      * <code>item</code>.
87      */

88     public boolean contains(String JavaDoc item) {
89         if (fVector != null)
90             return fVector.contains(item);
91         
92         if (item == null) {
93             for (int i = 0; i < fLength; i++) {
94                 if (fArray[i] == null)
95                     return true;
96             }
97         }
98         else {
99             for (int i = 0; i < fLength; i++) {
100                 if (item.equals(fArray[i]))
101                     return true;
102             }
103         }
104         return false;
105     }
106
107     public String JavaDoc item(int index) {
108         if (index < 0 || index >= fLength)
109             return null;
110         if (fVector != null) {
111             return (String JavaDoc)fVector.elementAt(index);
112         }
113         return fArray[index];
114     }
115
116 } // class XSParticle
117
Popular Tags