KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xerces > impl > dv > util > ByteListImpl


1 /*
2  * Copyright 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 package org.apache.xerces.impl.dv.util;
17
18 import org.apache.xerces.xs.datatypes.ByteList;
19 import org.apache.xerces.xs.XSException;
20
21 /**
22  * Implementation of <code>org.apache.xerces.xs.datatypes.ByteList</code>.
23  *
24  * @xerces.internal
25  *
26  * @author Ankit Pasricha, IBM
27  *
28  * @version $Id: ByteListImpl.java,v 1.5 2004/10/08 15:08:49 mrglavas Exp $
29  */

30 public class ByteListImpl implements ByteList {
31
32     // actually data stored in a byte array
33
protected final byte[] data;
34     
35     // canonical representation of the data
36
protected String JavaDoc canonical;
37     
38     public ByteListImpl(byte[] data) {
39         this.data = data;
40     }
41     
42     /**
43      * The number of <code>byte</code>s in the list. The range of
44      * valid child object indices is 0 to <code>length-1</code> inclusive.
45      */

46     public int getLength() {
47         return data.length;
48     }
49
50     /**
51      * Checks if the <code>byte</code> <code>item</code> is a
52      * member of this list.
53      * @param item <code>byte</code> whose presence in this list
54      * is to be tested.
55      * @return True if this list contains the <code>byte</code>
56      * <code>item</code>.
57      */

58     public boolean contains(byte item) {
59         for (int i = 0; i < data.length; ++i) {
60             if (data[i] == item) {
61                 return true;
62             }
63         }
64         return false;
65     }
66
67     /**
68      * Returns the <code>index</code>th item in the collection. The index
69      * starts at 0.
70      * @param index index into the collection.
71      * @return The <code>byte</code> at the <code>index</code>th
72      * position in the <code>ByteList</code>.
73      * @exception XSException
74      * INDEX_SIZE_ERR: if <code>index</code> is greater than or equal to the
75      * number of objects in the list.
76      */

77     public byte item(int index)
78         throws XSException {
79         
80         if(index < 0 || index > data.length - 1) {
81             throw new XSException(XSException.INDEX_SIZE_ERR, null);
82         }
83         return data[index];
84     }
85     
86 }
87
88
Popular Tags