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

Thu, 12 Oct 2017 19:44:07 +0800

author
aoqi
date
Thu, 12 Oct 2017 19:44:07 +0800
changeset 760
e530533619ec
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 *
aoqi@0 25 * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
aoqi@0 26 */
aoqi@0 27
aoqi@0 28 package com.sun.xml.internal.fastinfoset.util;
aoqi@0 29
aoqi@0 30 import com.sun.xml.internal.fastinfoset.QualifiedName;
aoqi@0 31 import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
aoqi@0 32
aoqi@0 33 public class LocalNameQualifiedNamesMap extends KeyIntMap {
aoqi@0 34
aoqi@0 35 private LocalNameQualifiedNamesMap _readOnlyMap;
aoqi@0 36
aoqi@0 37 private int _index;
aoqi@0 38
aoqi@0 39 public static class Entry {
aoqi@0 40 final String _key;
aoqi@0 41 final int _hash;
aoqi@0 42 public QualifiedName[] _value;
aoqi@0 43 public int _valueIndex;
aoqi@0 44 Entry _next;
aoqi@0 45
aoqi@0 46 public Entry(String key, int hash, Entry next) {
aoqi@0 47 _key = key;
aoqi@0 48 _hash = hash;
aoqi@0 49 _next = next;
aoqi@0 50 _value = new QualifiedName[1];
aoqi@0 51 }
aoqi@0 52
aoqi@0 53 public void addQualifiedName(QualifiedName name) {
aoqi@0 54 if (_valueIndex < _value.length) {
aoqi@0 55 _value[_valueIndex++] = name;
aoqi@0 56 } else if (_valueIndex == _value.length) {
aoqi@0 57 QualifiedName[] newValue = new QualifiedName[_valueIndex * 3 / 2 + 1];
aoqi@0 58 System.arraycopy(_value, 0, newValue, 0, _valueIndex);
aoqi@0 59 _value = newValue;
aoqi@0 60 _value[_valueIndex++] = name;
aoqi@0 61 }
aoqi@0 62 }
aoqi@0 63 }
aoqi@0 64
aoqi@0 65 private Entry[] _table;
aoqi@0 66
aoqi@0 67 public LocalNameQualifiedNamesMap(int initialCapacity, float loadFactor) {
aoqi@0 68 super(initialCapacity, loadFactor);
aoqi@0 69
aoqi@0 70 _table = new Entry[_capacity];
aoqi@0 71 }
aoqi@0 72
aoqi@0 73 public LocalNameQualifiedNamesMap(int initialCapacity) {
aoqi@0 74 this(initialCapacity, DEFAULT_LOAD_FACTOR);
aoqi@0 75 }
aoqi@0 76
aoqi@0 77 public LocalNameQualifiedNamesMap() {
aoqi@0 78 this(DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR);
aoqi@0 79 }
aoqi@0 80
aoqi@0 81 public final void clear() {
aoqi@0 82 for (int i = 0; i < _table.length; i++) {
aoqi@0 83 _table[i] = null;
aoqi@0 84 }
aoqi@0 85 _size = 0;
aoqi@0 86
aoqi@0 87 if (_readOnlyMap != null) {
aoqi@0 88 _index = _readOnlyMap.getIndex();
aoqi@0 89 } else {
aoqi@0 90 _index = 0;
aoqi@0 91 }
aoqi@0 92 }
aoqi@0 93
aoqi@0 94 public final void setReadOnlyMap(KeyIntMap readOnlyMap, boolean clear) {
aoqi@0 95 if (!(readOnlyMap instanceof LocalNameQualifiedNamesMap)) {
aoqi@0 96 throw new IllegalArgumentException(CommonResourceBundle.getInstance().
aoqi@0 97 getString("message.illegalClass", new Object[]{readOnlyMap}));
aoqi@0 98 }
aoqi@0 99
aoqi@0 100 setReadOnlyMap((LocalNameQualifiedNamesMap)readOnlyMap, clear);
aoqi@0 101 }
aoqi@0 102
aoqi@0 103 public final void setReadOnlyMap(LocalNameQualifiedNamesMap readOnlyMap, boolean clear) {
aoqi@0 104 _readOnlyMap = readOnlyMap;
aoqi@0 105 if (_readOnlyMap != null) {
aoqi@0 106 _readOnlyMapSize = _readOnlyMap.size();
aoqi@0 107 _index = _readOnlyMap.getIndex();
aoqi@0 108 if (clear) {
aoqi@0 109 clear();
aoqi@0 110 }
aoqi@0 111 } else {
aoqi@0 112 _readOnlyMapSize = 0;
aoqi@0 113 _index = 0;
aoqi@0 114 }
aoqi@0 115 }
aoqi@0 116
aoqi@0 117 public final boolean isQNameFromReadOnlyMap(QualifiedName name) {
aoqi@0 118 return (_readOnlyMap != null && name.index <= _readOnlyMap.getIndex());
aoqi@0 119 }
aoqi@0 120
aoqi@0 121 public final int getNextIndex() {
aoqi@0 122 return _index++;
aoqi@0 123 }
aoqi@0 124
aoqi@0 125 public final int getIndex() {
aoqi@0 126 return _index;
aoqi@0 127 }
aoqi@0 128
aoqi@0 129 public final Entry obtainEntry(String key) {
aoqi@0 130 final int hash = hashHash(key.hashCode());
aoqi@0 131
aoqi@0 132 if (_readOnlyMap != null) {
aoqi@0 133 final Entry entry = _readOnlyMap.getEntry(key, hash);
aoqi@0 134 if (entry != null) {
aoqi@0 135 return entry;
aoqi@0 136 }
aoqi@0 137 }
aoqi@0 138
aoqi@0 139 final int tableIndex = indexFor(hash, _table.length);
aoqi@0 140 for (Entry e = _table[tableIndex]; e != null; e = e._next) {
aoqi@0 141 if (e._hash == hash && eq(key, e._key)) {
aoqi@0 142 return e;
aoqi@0 143 }
aoqi@0 144 }
aoqi@0 145
aoqi@0 146 return addEntry(key, hash, tableIndex);
aoqi@0 147 }
aoqi@0 148
aoqi@0 149 public final Entry obtainDynamicEntry(String key) {
aoqi@0 150 final int hash = hashHash(key.hashCode());
aoqi@0 151
aoqi@0 152 final int tableIndex = indexFor(hash, _table.length);
aoqi@0 153 for (Entry e = _table[tableIndex]; e != null; e = e._next) {
aoqi@0 154 if (e._hash == hash && eq(key, e._key)) {
aoqi@0 155 return e;
aoqi@0 156 }
aoqi@0 157 }
aoqi@0 158
aoqi@0 159 return addEntry(key, hash, tableIndex);
aoqi@0 160 }
aoqi@0 161
aoqi@0 162 private final Entry getEntry(String key, int hash) {
aoqi@0 163 if (_readOnlyMap != null) {
aoqi@0 164 final Entry entry = _readOnlyMap.getEntry(key, hash);
aoqi@0 165 if (entry != null) {
aoqi@0 166 return entry;
aoqi@0 167 }
aoqi@0 168 }
aoqi@0 169
aoqi@0 170 final int tableIndex = indexFor(hash, _table.length);
aoqi@0 171 for (Entry e = _table[tableIndex]; e != null; e = e._next) {
aoqi@0 172 if (e._hash == hash && eq(key, e._key)) {
aoqi@0 173 return e;
aoqi@0 174 }
aoqi@0 175 }
aoqi@0 176
aoqi@0 177 return null;
aoqi@0 178 }
aoqi@0 179
aoqi@0 180
aoqi@0 181 private final Entry addEntry(String key, int hash, int bucketIndex) {
aoqi@0 182 Entry e = _table[bucketIndex];
aoqi@0 183 _table[bucketIndex] = new Entry(key, hash, e);
aoqi@0 184 e = _table[bucketIndex];
aoqi@0 185 if (_size++ >= _threshold) {
aoqi@0 186 resize(2 * _table.length);
aoqi@0 187 }
aoqi@0 188
aoqi@0 189 return e;
aoqi@0 190 }
aoqi@0 191
aoqi@0 192 private final void resize(int newCapacity) {
aoqi@0 193 _capacity = newCapacity;
aoqi@0 194 Entry[] oldTable = _table;
aoqi@0 195 int oldCapacity = oldTable.length;
aoqi@0 196 if (oldCapacity == MAXIMUM_CAPACITY) {
aoqi@0 197 _threshold = Integer.MAX_VALUE;
aoqi@0 198 return;
aoqi@0 199 }
aoqi@0 200
aoqi@0 201 Entry[] newTable = new Entry[_capacity];
aoqi@0 202 transfer(newTable);
aoqi@0 203 _table = newTable;
aoqi@0 204 _threshold = (int)(_capacity * _loadFactor);
aoqi@0 205 }
aoqi@0 206
aoqi@0 207 private final void transfer(Entry[] newTable) {
aoqi@0 208 Entry[] src = _table;
aoqi@0 209 int newCapacity = newTable.length;
aoqi@0 210 for (int j = 0; j < src.length; j++) {
aoqi@0 211 Entry e = src[j];
aoqi@0 212 if (e != null) {
aoqi@0 213 src[j] = null;
aoqi@0 214 do {
aoqi@0 215 Entry next = e._next;
aoqi@0 216 int i = indexFor(e._hash, newCapacity);
aoqi@0 217 e._next = newTable[i];
aoqi@0 218 newTable[i] = e;
aoqi@0 219 e = next;
aoqi@0 220 } while (e != null);
aoqi@0 221 }
aoqi@0 222 }
aoqi@0 223 }
aoqi@0 224
aoqi@0 225 private final boolean eq(String x, String y) {
aoqi@0 226 return x == y || x.equals(y);
aoqi@0 227 }
aoqi@0 228
aoqi@0 229 }

mercurial