Index: modules/security/src/main/java/common/java/security/Provider.java =================================================================== --- modules/security/src/main/java/common/java/security/Provider.java (revision 420746) +++ modules/security/src/main/java/common/java/security/Provider.java (working copy) @@ -56,18 +56,18 @@ // Contains "Service.Algorithm" and Provider.Service classes added using // putService() - private transient TwoKeyHashMap serviceTable; + private transient TwoKeyHashMap serviceTable; // Contains "Service.Alias" and Provider.Service classes added using // putService() - private transient TwoKeyHashMap aliasTable; + private transient TwoKeyHashMap aliasTable; // Contains "Service.Algorithm" and Provider.Service classes added using // put() - private transient TwoKeyHashMap propertyServiceTable; + private transient TwoKeyHashMap propertyServiceTable; // Contains "Service.Alias" and Provider.Service classes added using put() - private transient TwoKeyHashMap propertyAliasTable; + private transient TwoKeyHashMap propertyAliasTable; // The properties changed via put() private transient Properties changedProperties; @@ -440,12 +440,12 @@ } servicesChanged(); if (serviceTable == null) { - serviceTable = new TwoKeyHashMap(128); + serviceTable = new TwoKeyHashMap(128); } serviceTable.put(s.type, s.algorithm.toUpperCase(), s); if (s.aliases != null) { if (aliasTable == null) { - aliasTable = new TwoKeyHashMap(256); + aliasTable = new TwoKeyHashMap(256); } for (Iterator it = s.getAliases(); it.hasNext();) { aliasTable.put(s.type, (it.next()).toUpperCase(), s); @@ -620,7 +620,7 @@ String algUp = algorithm.toUpperCase(); Object o = null; if (propertyServiceTable == null) { - propertyServiceTable = new TwoKeyHashMap(128); + propertyServiceTable = new TwoKeyHashMap(128); } else { o = propertyServiceTable.get(serviceName, algUp); } @@ -628,7 +628,7 @@ s = (Provider.Service) o; s.aliases.add(aliasName); if (propertyAliasTable == null) { - propertyAliasTable = new TwoKeyHashMap(256); + propertyAliasTable = new TwoKeyHashMap(256); } propertyAliasTable.put(serviceName, aliasName.toUpperCase(), s); @@ -642,7 +642,7 @@ className, l, new HashMap()); propertyServiceTable.put(serviceName, algUp, s); if (propertyAliasTable == null) { - propertyAliasTable = new TwoKeyHashMap(256); + propertyAliasTable = new TwoKeyHashMap(256); } propertyAliasTable.put(serviceName, aliasName .toUpperCase(), s); @@ -670,7 +670,7 @@ s = new Provider.Service(this, serviceName, algorithm, value, new ArrayList(), new HashMap()); if (propertyServiceTable == null) { - propertyServiceTable = new TwoKeyHashMap(128); + propertyServiceTable = new TwoKeyHashMap(128); } propertyServiceTable.put(serviceName, alg, s); @@ -697,7 +697,7 @@ s = new Provider.Service(this, serviceName, algorithm, className, new ArrayList(), m); if (propertyServiceTable == null) { - propertyServiceTable = new TwoKeyHashMap(128); + propertyServiceTable = new TwoKeyHashMap(128); } propertyServiceTable.put(serviceName, alg, s); } Index: modules/security/src/main/java/common/org/apache/harmony/security/utils/TwoKeyHashMap.java =================================================================== --- modules/security/src/main/java/common/org/apache/harmony/security/utils/TwoKeyHashMap.java (revision 420746) +++ modules/security/src/main/java/common/org/apache/harmony/security/utils/TwoKeyHashMap.java (working copy) @@ -32,7 +32,7 @@ * Reductive hash with two keys * */ -public class TwoKeyHashMap extends AbstractMap { +public class TwoKeyHashMap extends AbstractMap { static final float DEFAULT_LOAD_FACTOR = 0.75f; static final int DEFAULT_INITIAL_SIZE = 16; @@ -43,13 +43,20 @@ private int arrSize; private transient int modCount; - private Entry[] arr; + private Entry[] arr; private float loadFactor; int threshold = 0; /** * Constructs an empty HashMap + */ + public TwoKeyHashMap() { + this(DEFAULT_INITIAL_SIZE, DEFAULT_LOAD_FACTOR); + } + + /** + * Constructs an empty HashMap * @param initialCapacity */ public TwoKeyHashMap(int initialCapacity) { @@ -113,7 +120,7 @@ * @return */ public V remove(Object key1, Object key2) { - Entry e = removeEntry(key1, key2); + Entry e = removeEntry(key1, key2); return null != e ? e.value : null; } @@ -124,7 +131,7 @@ * @param value * @return */ - public V put(String key1, String key2, V value) { + public V put(E key1, K key2, V value) { if (key1 == null && key2 == null) { int index = arrSize; if (arr[index] == null) { @@ -141,7 +148,7 @@ int hash = key1.hashCode() + key2.hashCode(); int index = (hash & 0x7fffffff) % arrSize; - Entry e = arr[index]; + Entry e = arr[index]; while (e != null) { if (hash == e.hash && key1.equals(e.getKey1()) && key2.equals(e.getKey2())) { @@ -171,12 +178,12 @@ if (newArrSize < 0) { newArrSize = Integer.MAX_VALUE - 1; } - Entry[] newArr = new Entry[newArrSize + 1]; + Entry[] newArr = new Entry[newArrSize + 1]; for (int i = 0; i < arr.length - 1; i++) { - Entry entry = arr[i]; + Entry entry = arr[i]; while (entry != null) { - Entry next = entry.next; + Entry next = entry.next; int newIndex = (entry.hash & 0x7fffffff) % newArrSize; entry.next = newArr[newIndex]; @@ -214,7 +221,7 @@ * @return */ public V get(Object key1, Object key2) { - Entry e = findEntry(key1, key2); + Entry e = findEntry(key1, key2); if (e != null) { return e.value; } @@ -244,9 +251,9 @@ * @param next * @return */ - Entry createEntry(int hashCode, String key1, String key2, - V value, Entry next) { - return new Entry(hashCode, key1, key2, value, next); + Entry createEntry(int hashCode, E key1, K key2, + V value, Entry next) { + return new Entry(hashCode, key1, key2, value, next); } /** @@ -270,14 +277,14 @@ * Entry implementation for the TwoKeyHashMap class * */ - static class Entry implements Map.Entry { + public static class Entry implements Map.Entry { int hash; - String key1; - String key2; + E key1; + K key2; V value; - Entry next; + Entry next; - public Entry(int hash, String key1, String key2, V value, Entry next) { + public Entry(int hash, E key1, K key2, V value, Entry next) { this.hash = hash; this.key1 = key1; this.key2 = key2; @@ -286,14 +293,14 @@ } public String getKey() { - return key1 + key2; + return key1.toString() + key2.toString(); } - public String getKey1() { + public E getKey1() { return key1; } - public String getKey2() { + public K getKey2() { return key2; } @@ -312,7 +319,7 @@ return false; } - Entry e = (Entry) obj; + Entry e = (Entry) obj; Object getKey1 = e.getKey1(); Object getKey2 = e.getKey2(); Object getValue = e.getValue(); @@ -353,8 +360,8 @@ return false; } - Entry entry = (Entry) obj; - Entry entry2 = findEntry(entry.getKey1(), entry.getKey2()); + Entry entry = (Entry) obj; + Entry entry2 = findEntry(entry.getKey1(), entry.getKey2()); if (entry2 == null) { return false; } @@ -381,8 +388,8 @@ private boolean found; private int curr = -1; private int returned_index = -1; - private Entry curr_entry; - private Entry returned_entry; + private Entry curr_entry; + private Entry returned_entry; EntryIteratorImpl() { startModCount = modCount; @@ -429,8 +436,8 @@ throw new ConcurrentModificationException(); } - Entry p = null; - Entry e = arr[returned_index]; + Entry p = null; + Entry e = arr[returned_index]; while (e != returned_entry) { p = e; e = e.next; @@ -447,14 +454,14 @@ } } - private final Entry findEntry(Object key1, Object key2) { + private final Entry findEntry(Object key1, Object key2) { if (key1 == null && key2 == null) { return arr[arrSize]; } int hash = key1.hashCode() + key2.hashCode(); int index = (hash & 0x7fffffff) % arrSize; - Entry e = arr[index]; + Entry e = arr[index]; while (e != null) { if (hash == e.hash && key1.equals(e.getKey1()) && key2.equals(e.getKey2())) { @@ -466,11 +473,11 @@ } // Removes entry - private final Entry removeEntry(Object key1, Object key2) { + private final Entry removeEntry(Object key1, Object key2) { if (key1 == null && key2 == null) { int index = arrSize; if (arr[index] != null) { - Entry ret = arr[index]; + Entry ret = arr[index]; arr[index] = null; size--; modCount++; @@ -482,8 +489,8 @@ int hash = key1.hashCode() + key2.hashCode(); int index = (hash & 0x7fffffff) % arrSize; - Entry e = arr[index]; - Entry prev = e; + Entry e = arr[index]; + Entry prev = e; while (e != null) { if (hash == e.hash && key1.equals(e.getKey1()) && key2.equals(e.getKey2())) { if (prev == e) {