1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Copyright 2004 The Apache Software Foundation. 7 * 8 * Licensed under the Apache License, Version 2.0 (the "License"); 9 * you may not use this file except in compliance with the License. 10 * You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 package com.sun.org.apache.xerces.internal.impl.dv.util; 21 22 import java.util.AbstractList; 23 24 import com.sun.org.apache.xerces.internal.xs.XSException; 25 import com.sun.org.apache.xerces.internal.xs.datatypes.ByteList; 26 27 /** 28 * Implementation of <code>com.sun.org.apache.xerces.internal.xs.datatypes.ByteList</code>. 29 * 30 * @xerces.internal 31 * 32 * @author Ankit Pasricha, IBM 33 * 34 */ 35 public class ByteListImpl extends AbstractList implements ByteList { 36 37 // actually data stored in a byte array 38 protected final byte[] data; 39 40 // canonical representation of the data 41 protected String canonical; 42 43 public ByteListImpl(byte[] data) { 44 this.data = data; 45 } 46 47 /** 48 * The number of <code>byte</code>s in the list. The range of 49 * valid child object indices is 0 to <code>length-1</code> inclusive. 50 */ 51 public int getLength() { 52 return data.length; 53 } 54 55 /** 56 * Checks if the <code>byte</code> <code>item</code> is a 57 * member of this list. 58 * @param item <code>byte</code> whose presence in this list 59 * is to be tested. 60 * @return True if this list contains the <code>byte</code> 61 * <code>item</code>. 62 */ 63 public boolean contains(byte item) { 64 for (int i = 0; i < data.length; ++i) { 65 if (data[i] == item) { 66 return true; 67 } 68 } 69 return false; 70 } 71 72 /** 73 * Returns the <code>index</code>th item in the collection. The index 74 * starts at 0. 75 * @param index index into the collection. 76 * @return The <code>byte</code> at the <code>index</code>th 77 * position in the <code>ByteList</code>. 78 * @exception XSException 79 * INDEX_SIZE_ERR: if <code>index</code> is greater than or equal to the 80 * number of objects in the list. 81 */ 82 public byte item(int index) 83 throws XSException { 84 85 if(index < 0 || index > data.length - 1) { 86 throw new XSException(XSException.INDEX_SIZE_ERR, null); 87 } 88 return data[index]; 89 } 90 91 /* 92 * List methods 93 */ 94 95 public Object get(int index) { 96 if (index >= 0 && index < data.length) { 97 return new Byte(data[index]); 98 } 99 throw new IndexOutOfBoundsException("Index: " + index); 100 } 101 102 public int size() { 103 return getLength(); 104 } 105 }