src/share/jaxws_classes/com/sun/xml/internal/fastinfoset/util/CharArrayArray.java

changeset 286
f50545b5e2f1
parent 0
373ffda63c9a
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/fastinfoset/util/CharArrayArray.java	Tue Mar 06 16:09:35 2012 -0800
     1.3 @@ -0,0 +1,119 @@
     1.4 +/*
     1.5 + * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + *
    1.28 + * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
    1.29 + */
    1.30 +
    1.31 +package com.sun.xml.internal.fastinfoset.util;
    1.32 +
    1.33 +import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
    1.34 +
    1.35 +public class CharArrayArray extends ValueArray {
    1.36 +
    1.37 +    private CharArray[] _array;
    1.38 +
    1.39 +    private CharArrayArray _readOnlyArray;
    1.40 +
    1.41 +    public CharArrayArray(int initialCapacity, int maximumCapacity) {
    1.42 +        _array = new CharArray[initialCapacity];
    1.43 +        _maximumCapacity = maximumCapacity;
    1.44 +    }
    1.45 +
    1.46 +    public CharArrayArray() {
    1.47 +        this(DEFAULT_CAPACITY, MAXIMUM_CAPACITY);
    1.48 +    }
    1.49 +
    1.50 +    public final void clear() {
    1.51 +        for (int i = 0; i < _size; i++) {
    1.52 +            _array[i] = null;
    1.53 +        }
    1.54 +        _size = 0;
    1.55 +    }
    1.56 +
    1.57 +    /**
    1.58 +     * Returns cloned version of internal CharArray[].
    1.59 +     * @return cloned version of internal CharArray[].
    1.60 +     */
    1.61 +    public final CharArray[] getArray() {
    1.62 +        if (_array == null) return null;
    1.63 +
    1.64 +        final CharArray[] clonedArray = new CharArray[_array.length];
    1.65 +        System.arraycopy(_array, 0, clonedArray, 0, _array.length);
    1.66 +        return clonedArray;
    1.67 +    }
    1.68 +
    1.69 +    public final void setReadOnlyArray(ValueArray readOnlyArray, boolean clear) {
    1.70 +        if (!(readOnlyArray instanceof CharArrayArray)) {
    1.71 +            throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.illegalClass", new Object[]{readOnlyArray}));
    1.72 +        }
    1.73 +
    1.74 +        setReadOnlyArray((CharArrayArray)readOnlyArray, clear);
    1.75 +    }
    1.76 +
    1.77 +    public final void setReadOnlyArray(CharArrayArray readOnlyArray, boolean clear) {
    1.78 +        if (readOnlyArray != null) {
    1.79 +            _readOnlyArray = readOnlyArray;
    1.80 +            _readOnlyArraySize = readOnlyArray.getSize();
    1.81 +
    1.82 +            if (clear) {
    1.83 +                clear();
    1.84 +            }
    1.85 +        }
    1.86 +    }
    1.87 +
    1.88 +    public final CharArray get(int i) {
    1.89 +        if (_readOnlyArray == null) {
    1.90 +            return _array[i];
    1.91 +        } else {
    1.92 +            if (i < _readOnlyArraySize) {
    1.93 +               return _readOnlyArray.get(i);
    1.94 +            } else {
    1.95 +                return _array[i - _readOnlyArraySize];
    1.96 +            }
    1.97 +        }
    1.98 +   }
    1.99 +
   1.100 +    public final void add(CharArray s) {
   1.101 +        if (_size == _array.length) {
   1.102 +            resize();
   1.103 +        }
   1.104 +
   1.105 +       _array[_size++] = s;
   1.106 +    }
   1.107 +
   1.108 +    protected final void resize() {
   1.109 +        if (_size == _maximumCapacity) {
   1.110 +            throw new ValueArrayResourceException(CommonResourceBundle.getInstance().getString("message.arrayMaxCapacity"));
   1.111 +        }
   1.112 +
   1.113 +        int newSize = _size * 3 / 2 + 1;
   1.114 +        if (newSize > _maximumCapacity) {
   1.115 +            newSize = _maximumCapacity;
   1.116 +        }
   1.117 +
   1.118 +        final CharArray[] newArray = new CharArray[newSize];
   1.119 +        System.arraycopy(_array, 0, newArray, 0, _size);
   1.120 +        _array = newArray;
   1.121 +    }
   1.122 +}

mercurial