jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/xs/PSVIErrorList.java
changeset 27111 7a491d709b83
equal deleted inserted replaced
26996:a137992d750c 27111:7a491d709b83
       
     1 /*
       
     2  * reserved comment block
       
     3  * DO NOT REMOVE OR ALTER!
       
     4  */
       
     5 /*
       
     6  * Licensed to the Apache Software Foundation (ASF) under one or more
       
     7  * contributor license agreements.  See the NOTICE file distributed with
       
     8  * this work for additional information regarding copyright ownership.
       
     9  * The ASF licenses this file to You under the Apache License, Version 2.0
       
    10  * (the "License"); you may not use this file except in compliance with
       
    11  * the License.  You may obtain a copy of the License at
       
    12  *
       
    13  *      http://www.apache.org/licenses/LICENSE-2.0
       
    14  *
       
    15  * Unless required by applicable law or agreed to in writing, software
       
    16  * distributed under the License is distributed on an "AS IS" BASIS,
       
    17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
       
    18  * See the License for the specific language governing permissions and
       
    19  * limitations under the License.
       
    20  */
       
    21 
       
    22 package com.sun.org.apache.xerces.internal.impl.xs;
       
    23 
       
    24 import java.util.AbstractList;
       
    25 
       
    26 import com.sun.org.apache.xerces.internal.xs.StringList;
       
    27 
       
    28 /**
       
    29  * StringList implementation for schema error codes and error messages.
       
    30  *
       
    31  * @xerces.internal
       
    32  *
       
    33  * @author Michael Glavassevich, IBM
       
    34  *
       
    35  */
       
    36 final class PSVIErrorList extends AbstractList implements StringList {
       
    37 
       
    38     private final String[] fArray;
       
    39     private final int fLength;
       
    40     private final int fOffset;
       
    41 
       
    42     public PSVIErrorList(String[] array, boolean even) {
       
    43         fArray = array;
       
    44         fLength = (fArray.length >> 1);
       
    45         fOffset = even ? 0 : 1;
       
    46     }
       
    47 
       
    48     public boolean contains(String item) {
       
    49         if (item == null) {
       
    50             for (int i = 0; i < fLength; ++i) {
       
    51                 if (fArray[(i << 1) + fOffset] == null) {
       
    52                     return true;
       
    53                 }
       
    54             }
       
    55         }
       
    56         else {
       
    57             for (int i = 0; i < fLength; ++i) {
       
    58                 if (item.equals(fArray[(i << 1) + fOffset])) {
       
    59                     return true;
       
    60                 }
       
    61             }
       
    62         }
       
    63         return false;
       
    64     }
       
    65 
       
    66     public int getLength() {
       
    67         return fLength;
       
    68     }
       
    69 
       
    70     public String item(int index) {
       
    71         if (index < 0 || index >= fLength) {
       
    72             return null;
       
    73         }
       
    74         return fArray[(index << 1) + fOffset];
       
    75     }
       
    76 
       
    77     /*
       
    78      * List methods
       
    79      */
       
    80 
       
    81     public Object get(int index) {
       
    82         if (index >= 0 && index < fLength) {
       
    83             return fArray[(index << 1) + fOffset];
       
    84         }
       
    85         throw new IndexOutOfBoundsException("Index: " + index);
       
    86     }
       
    87 
       
    88     public int size() {
       
    89         return getLength();
       
    90     }
       
    91 
       
    92 } // class PSVIErrorList