001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.xerces.impl.xs.util;
019:
020: import org.apache.xerces.xs.ShortList;
021: import org.apache.xerces.xs.XSException;
022:
023: /**
024: * Containts a list of Object's.
025: *
026: * @xerces.internal
027: *
028: * @author Sandy Gao, IBM
029: *
030: * @version $Id: ShortListImpl.java 446723 2006-09-15 20:37:45Z mrglavas $
031: */
032: public class ShortListImpl implements ShortList {
033:
034: /**
035: * An immutable empty list.
036: */
037: public static final ShortList EMPTY_LIST = new ShortList() {
038: public int getLength() {
039: return 0;
040: }
041:
042: public boolean contains(short item) {
043: return false;
044: }
045:
046: public short item(int index) throws XSException {
047: throw new XSException(XSException.INDEX_SIZE_ERR, null);
048: }
049: };
050:
051: // The array to hold all data
052: private short[] fArray = null;
053: // Number of elements in this list
054: private int fLength = 0;
055:
056: /**
057: * Construct an XSObjectList implementation
058: *
059: * @param array the data array
060: * @param length the number of elements
061: */
062: public ShortListImpl(short[] array, int length) {
063: fArray = array;
064: fLength = length;
065: }
066:
067: /**
068: * The number of <code>Objects</code> in the list. The range of valid
069: * child node indices is 0 to <code>length-1</code> inclusive.
070: */
071: public int getLength() {
072: return fLength;
073: }
074:
075: /**
076: * Checks if the <code>unsigned short</code> <code>item</code> is a
077: * member of this list.
078: * @param item <code>unsigned short</code> whose presence in this list
079: * is to be tested.
080: * @return True if this list contains the <code>unsigned short</code>
081: * <code>item</code>.
082: */
083: public boolean contains(short item) {
084: for (int i = 0; i < fLength; i++) {
085: if (fArray[i] == item)
086: return true;
087: }
088: return false;
089: }
090:
091: public short item(int index) throws XSException {
092: if (index < 0 || index >= fLength)
093: throw new XSException(XSException.INDEX_SIZE_ERR, null);
094: return fArray[index];
095: }
096:
097: public boolean equals(Object obj) {
098: if (obj == null || !(obj instanceof ShortList)) {
099: return false;
100: }
101: ShortList rhs = (ShortList) obj;
102:
103: if (fLength != rhs.getLength()) {
104: return false;
105: }
106:
107: for (int i = 0; i < fLength; ++i) {
108: if (fArray[i] != rhs.item(i)) {
109: return false;
110: }
111: }
112: return true;
113: }
114:
115: } // class XSParticle
|