1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Copyright 2002,2003-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 21 package com.sun.org.apache.xerces.internal.impl.xs.util; 22 23 import java.util.AbstractList; 24 25 import com.sun.org.apache.xerces.internal.xs.ShortList; 26 import com.sun.org.apache.xerces.internal.xs.XSException; 27 28 /** 29 * Containts a list of Object's. 30 * 31 * @xerces.internal 32 * 33 * @author Sandy Gao, IBM 34 * 35 */ 36 public final class ShortListImpl extends AbstractList implements ShortList { 37 38 /** 39 * An immutable empty list. 40 */ 41 public static final ShortListImpl EMPTY_LIST = new ShortListImpl(new short[0], 0); 42 43 // The array to hold all data 44 private final short[] fArray; 45 // Number of elements in this list 46 private final int fLength; 47 48 /** 49 * Construct an XSObjectList implementation 50 * 51 * @param array the data array 52 * @param length the number of elements 53 */ 54 public ShortListImpl(short[] array, int length) { 55 fArray = array; 56 fLength = length; 57 } 58 59 /** 60 * The number of <code>Objects</code> in the list. The range of valid 61 * child node indices is 0 to <code>length-1</code> inclusive. 62 */ 63 public int getLength() { 64 return fLength; 65 } 66 67 /** 68 * Checks if the <code>unsigned short</code> <code>item</code> is a 69 * member of this list. 70 * @param item <code>unsigned short</code> whose presence in this list 71 * is to be tested. 72 * @return True if this list contains the <code>unsigned short</code> 73 * <code>item</code>. 74 */ 75 public boolean contains(short item) { 76 for (int i = 0; i < fLength; i++) { 77 if (fArray[i] == item) { 78 return true; 79 } 80 } 81 return false; 82 } 83 84 public short item(int index) throws XSException { 85 if (index < 0 || index >= fLength) { 86 throw new XSException(XSException.INDEX_SIZE_ERR, null); 87 } 88 return fArray[index]; 89 } 90 91 public boolean equals(Object obj) { 92 if (obj == null || !(obj instanceof ShortList)) { 93 return false; 94 } 95 ShortList rhs = (ShortList)obj; 96 97 if (fLength != rhs.getLength()) { 98 return false; 99 } 100 for (int i = 0;i < fLength; ++i) { 101 if (fArray[i] != rhs.item(i)) { 102 return false; 103 } 104 } 105 return true; 106 } 107 108 /* 109 * List methods 110 */ 111 112 public Object get(int index) { 113 if (index >= 0 && index < fLength) { 114 return new Short(fArray[index]); 115 } 116 throw new IndexOutOfBoundsException("Index: " + index); 117 } 118 119 public int size() { 120 return getLength(); 121 } 122 123 } // class ShortListImpl