01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.xerces.impl.dv.util;
19:
20: import org.apache.xerces.xs.datatypes.ByteList;
21: import org.apache.xerces.xs.XSException;
22:
23: /**
24: * Implementation of <code>org.apache.xerces.xs.datatypes.ByteList</code>.
25: *
26: * @xerces.internal
27: *
28: * @author Ankit Pasricha, IBM
29: *
30: * @version $Id: ByteListImpl.java 446747 2006-09-15 21:46:20Z mrglavas $
31: */
32: public class ByteListImpl implements ByteList {
33:
34: // actually data stored in a byte array
35: protected final byte[] data;
36:
37: // canonical representation of the data
38: protected String canonical;
39:
40: public ByteListImpl(byte[] data) {
41: this .data = data;
42: }
43:
44: /**
45: * The number of <code>byte</code>s in the list. The range of
46: * valid child object indices is 0 to <code>length-1</code> inclusive.
47: */
48: public int getLength() {
49: return data.length;
50: }
51:
52: /**
53: * Checks if the <code>byte</code> <code>item</code> is a
54: * member of this list.
55: * @param item <code>byte</code> whose presence in this list
56: * is to be tested.
57: * @return True if this list contains the <code>byte</code>
58: * <code>item</code>.
59: */
60: public boolean contains(byte item) {
61: for (int i = 0; i < data.length; ++i) {
62: if (data[i] == item) {
63: return true;
64: }
65: }
66: return false;
67: }
68:
69: /**
70: * Returns the <code>index</code>th item in the collection. The index
71: * starts at 0.
72: * @param index index into the collection.
73: * @return The <code>byte</code> at the <code>index</code>th
74: * position in the <code>ByteList</code>.
75: * @exception XSException
76: * INDEX_SIZE_ERR: if <code>index</code> is greater than or equal to the
77: * number of objects in the list.
78: */
79: public byte item(int index) throws XSException {
80:
81: if (index < 0 || index > data.length - 1) {
82: throw new XSException(XSException.INDEX_SIZE_ERR, null);
83: }
84: return data[index];
85: }
86:
87: }
|