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.StringList;
021: import java.util.Vector;
022:
023: /**
024: * Containts a list of Object's.
025: *
026: * @xerces.internal
027: *
028: * @author Sandy Gao, IBM
029: *
030: * @version $Id: StringListImpl.java 446723 2006-09-15 20:37:45Z mrglavas $
031: */
032: public class StringListImpl implements StringList {
033:
034: /**
035: * An immutable empty list.
036: */
037: public static final StringList EMPTY_LIST = new StringList() {
038: public int getLength() {
039: return 0;
040: }
041:
042: public boolean contains(String item) {
043: return false;
044: }
045:
046: public String item(int index) {
047: return null;
048: }
049: };
050:
051: // The array to hold all data
052: private String[] fArray = null;
053: // Number of elements in this list
054: private int fLength = 0;
055:
056: // REVISIT: this is temp solution. In general we need to use this class
057: // instead of the Vector.
058: private Vector fVector;
059:
060: public StringListImpl(Vector v) {
061: fVector = v;
062: fLength = (v == null) ? 0 : v.size();
063: }
064:
065: /**
066: * Construct an XSObjectList implementation
067: *
068: * @param array the data array
069: * @param length the number of elements
070: */
071: public StringListImpl(String[] array, int length) {
072: fArray = array;
073: fLength = length;
074: }
075:
076: /**
077: * The number of <code>Objects</code> in the list. The range of valid
078: * child node indices is 0 to <code>length-1</code> inclusive.
079: */
080: public int getLength() {
081: return fLength;
082: }
083:
084: /**
085: * Checks if the <code>GenericString</code> <code>item</code> is a member
086: * of this list.
087: * @param item <code>GenericString</code> whose presence in this list is
088: * to be tested.
089: * @return True if this list contains the <code>GenericString</code>
090: * <code>item</code>.
091: */
092: public boolean contains(String item) {
093: if (fVector != null)
094: return fVector.contains(item);
095:
096: if (item == null) {
097: for (int i = 0; i < fLength; i++) {
098: if (fArray[i] == null)
099: return true;
100: }
101: } else {
102: for (int i = 0; i < fLength; i++) {
103: if (item.equals(fArray[i]))
104: return true;
105: }
106: }
107: return false;
108: }
109:
110: public String item(int index) {
111: if (index < 0 || index >= fLength)
112: return null;
113: if (fVector != null) {
114: return (String) fVector.elementAt(index);
115: }
116: return fArray[index];
117: }
118:
119: } // class XSParticle
|