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/LocalNameQualifiedNamesMap.java Tue Mar 06 16:09:35 2012 -0800 1.3 @@ -0,0 +1,229 @@ 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.QualifiedName; 1.34 +import com.sun.xml.internal.fastinfoset.CommonResourceBundle; 1.35 + 1.36 +public class LocalNameQualifiedNamesMap extends KeyIntMap { 1.37 + 1.38 + private LocalNameQualifiedNamesMap _readOnlyMap; 1.39 + 1.40 + private int _index; 1.41 + 1.42 + public static class Entry { 1.43 + final String _key; 1.44 + final int _hash; 1.45 + public QualifiedName[] _value; 1.46 + public int _valueIndex; 1.47 + Entry _next; 1.48 + 1.49 + public Entry(String key, int hash, Entry next) { 1.50 + _key = key; 1.51 + _hash = hash; 1.52 + _next = next; 1.53 + _value = new QualifiedName[1]; 1.54 + } 1.55 + 1.56 + public void addQualifiedName(QualifiedName name) { 1.57 + if (_valueIndex < _value.length) { 1.58 + _value[_valueIndex++] = name; 1.59 + } else if (_valueIndex == _value.length) { 1.60 + QualifiedName[] newValue = new QualifiedName[_valueIndex * 3 / 2 + 1]; 1.61 + System.arraycopy(_value, 0, newValue, 0, _valueIndex); 1.62 + _value = newValue; 1.63 + _value[_valueIndex++] = name; 1.64 + } 1.65 + } 1.66 + } 1.67 + 1.68 + private Entry[] _table; 1.69 + 1.70 + public LocalNameQualifiedNamesMap(int initialCapacity, float loadFactor) { 1.71 + super(initialCapacity, loadFactor); 1.72 + 1.73 + _table = new Entry[_capacity]; 1.74 + } 1.75 + 1.76 + public LocalNameQualifiedNamesMap(int initialCapacity) { 1.77 + this(initialCapacity, DEFAULT_LOAD_FACTOR); 1.78 + } 1.79 + 1.80 + public LocalNameQualifiedNamesMap() { 1.81 + this(DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR); 1.82 + } 1.83 + 1.84 + public final void clear() { 1.85 + for (int i = 0; i < _table.length; i++) { 1.86 + _table[i] = null; 1.87 + } 1.88 + _size = 0; 1.89 + 1.90 + if (_readOnlyMap != null) { 1.91 + _index = _readOnlyMap.getIndex(); 1.92 + } else { 1.93 + _index = 0; 1.94 + } 1.95 + } 1.96 + 1.97 + public final void setReadOnlyMap(KeyIntMap readOnlyMap, boolean clear) { 1.98 + if (!(readOnlyMap instanceof LocalNameQualifiedNamesMap)) { 1.99 + throw new IllegalArgumentException(CommonResourceBundle.getInstance(). 1.100 + getString("message.illegalClass", new Object[]{readOnlyMap})); 1.101 + } 1.102 + 1.103 + setReadOnlyMap((LocalNameQualifiedNamesMap)readOnlyMap, clear); 1.104 + } 1.105 + 1.106 + public final void setReadOnlyMap(LocalNameQualifiedNamesMap readOnlyMap, boolean clear) { 1.107 + _readOnlyMap = readOnlyMap; 1.108 + if (_readOnlyMap != null) { 1.109 + _readOnlyMapSize = _readOnlyMap.size(); 1.110 + _index = _readOnlyMap.getIndex(); 1.111 + if (clear) { 1.112 + clear(); 1.113 + } 1.114 + } else { 1.115 + _readOnlyMapSize = 0; 1.116 + _index = 0; 1.117 + } 1.118 + } 1.119 + 1.120 + public final boolean isQNameFromReadOnlyMap(QualifiedName name) { 1.121 + return (_readOnlyMap != null && name.index <= _readOnlyMap.getIndex()); 1.122 + } 1.123 + 1.124 + public final int getNextIndex() { 1.125 + return _index++; 1.126 + } 1.127 + 1.128 + public final int getIndex() { 1.129 + return _index; 1.130 + } 1.131 + 1.132 + public final Entry obtainEntry(String key) { 1.133 + final int hash = hashHash(key.hashCode()); 1.134 + 1.135 + if (_readOnlyMap != null) { 1.136 + final Entry entry = _readOnlyMap.getEntry(key, hash); 1.137 + if (entry != null) { 1.138 + return entry; 1.139 + } 1.140 + } 1.141 + 1.142 + final int tableIndex = indexFor(hash, _table.length); 1.143 + for (Entry e = _table[tableIndex]; e != null; e = e._next) { 1.144 + if (e._hash == hash && eq(key, e._key)) { 1.145 + return e; 1.146 + } 1.147 + } 1.148 + 1.149 + return addEntry(key, hash, tableIndex); 1.150 + } 1.151 + 1.152 + public final Entry obtainDynamicEntry(String key) { 1.153 + final int hash = hashHash(key.hashCode()); 1.154 + 1.155 + final int tableIndex = indexFor(hash, _table.length); 1.156 + for (Entry e = _table[tableIndex]; e != null; e = e._next) { 1.157 + if (e._hash == hash && eq(key, e._key)) { 1.158 + return e; 1.159 + } 1.160 + } 1.161 + 1.162 + return addEntry(key, hash, tableIndex); 1.163 + } 1.164 + 1.165 + private final Entry getEntry(String key, int hash) { 1.166 + if (_readOnlyMap != null) { 1.167 + final Entry entry = _readOnlyMap.getEntry(key, hash); 1.168 + if (entry != null) { 1.169 + return entry; 1.170 + } 1.171 + } 1.172 + 1.173 + final int tableIndex = indexFor(hash, _table.length); 1.174 + for (Entry e = _table[tableIndex]; e != null; e = e._next) { 1.175 + if (e._hash == hash && eq(key, e._key)) { 1.176 + return e; 1.177 + } 1.178 + } 1.179 + 1.180 + return null; 1.181 + } 1.182 + 1.183 + 1.184 + private final Entry addEntry(String key, int hash, int bucketIndex) { 1.185 + Entry e = _table[bucketIndex]; 1.186 + _table[bucketIndex] = new Entry(key, hash, e); 1.187 + e = _table[bucketIndex]; 1.188 + if (_size++ >= _threshold) { 1.189 + resize(2 * _table.length); 1.190 + } 1.191 + 1.192 + return e; 1.193 + } 1.194 + 1.195 + private final void resize(int newCapacity) { 1.196 + _capacity = newCapacity; 1.197 + Entry[] oldTable = _table; 1.198 + int oldCapacity = oldTable.length; 1.199 + if (oldCapacity == MAXIMUM_CAPACITY) { 1.200 + _threshold = Integer.MAX_VALUE; 1.201 + return; 1.202 + } 1.203 + 1.204 + Entry[] newTable = new Entry[_capacity]; 1.205 + transfer(newTable); 1.206 + _table = newTable; 1.207 + _threshold = (int)(_capacity * _loadFactor); 1.208 + } 1.209 + 1.210 + private final void transfer(Entry[] newTable) { 1.211 + Entry[] src = _table; 1.212 + int newCapacity = newTable.length; 1.213 + for (int j = 0; j < src.length; j++) { 1.214 + Entry e = src[j]; 1.215 + if (e != null) { 1.216 + src[j] = null; 1.217 + do { 1.218 + Entry next = e._next; 1.219 + int i = indexFor(e._hash, newCapacity); 1.220 + e._next = newTable[i]; 1.221 + newTable[i] = e; 1.222 + e = next; 1.223 + } while (e != null); 1.224 + } 1.225 + } 1.226 + } 1.227 + 1.228 + private final boolean eq(String x, String y) { 1.229 + return x == y || x.equals(y); 1.230 + } 1.231 + 1.232 +}