KickJava   Java API By Example, From Geeks To Geeks.

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


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.ShortList;
20 import org.apache.xerces.xs.XSException;
21
22 /**
23  * Containts a list of Object's.
24  *
25  * @xerces.internal
26  *
27  * @author Sandy Gao, IBM
28  *
29  * @version $Id: ShortListImpl.java,v 1.4 2005/05/16 20:07:07 mrglavas Exp $
30  */

31 public class ShortListImpl implements ShortList {
32
33     // The array to hold all data
34
private short[] fArray = null;
35     // Number of elements in this list
36
private int fLength = 0;
37
38     /**
39      * Construct an XSObjectList implementation
40      *
41      * @param array the data array
42      * @param length the number of elements
43      */

44     public ShortListImpl(short[] array, int length) {
45         fArray = array;
46         fLength = length;
47     }
48
49     /**
50      * The number of <code>Objects</code> in the list. The range of valid
51      * child node indices is 0 to <code>length-1</code> inclusive.
52      */

53     public int getLength() {
54         return fLength;
55     }
56
57     /**
58      * Checks if the <code>unsigned short</code> <code>item</code> is a
59      * member of this list.
60      * @param item <code>unsigned short</code> whose presence in this list
61      * is to be tested.
62      * @return True if this list contains the <code>unsigned short</code>
63      * <code>item</code>.
64      */

65     public boolean contains(short item) {
66         for (int i = 0; i < fLength; i++) {
67             if (fArray[i] == item)
68                 return true;
69         }
70         return false;
71     }
72     
73     public short item(int index) throws XSException {
74         if (index < 0 || index >= fLength)
75             throw new XSException(XSException.INDEX_SIZE_ERR, null);
76         return fArray[index];
77     }
78     
79     public boolean equals(Object JavaDoc obj) {
80         if (obj == null || !(obj instanceof ShortList)) {
81             return false;
82         }
83         ShortList rhs = (ShortList)obj;
84         
85         if (fLength != rhs.getLength()) {
86             return false;
87         }
88         
89         for (int i = 0;i < fLength; ++i) {
90             if (fArray[i] != rhs.item(i)) {
91                 return false;
92             }
93         }
94         return true;
95     }
96
97 } // class XSParticle
98
Popular Tags