Author: manik.surtani(a)jboss.com
Date: 2008-07-30 04:56:14 -0400 (Wed, 30 Jul 2008)
New Revision: 6425
Modified:
core/trunk/src/main/java/org/jboss/cache/util/FastCopyHashMap.java
Log:
Moved SuppressWarnings from method body.
Allow null keys
Modified: core/trunk/src/main/java/org/jboss/cache/util/FastCopyHashMap.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/util/FastCopyHashMap.java 2008-07-30 08:50:56
UTC (rev 6424)
+++ core/trunk/src/main/java/org/jboss/cache/util/FastCopyHashMap.java 2008-07-30 08:56:14
UTC (rev 6425)
@@ -40,6 +40,8 @@
*/
public class FastCopyHashMap<K, V> extends AbstractMap<K, V> implements
Map<K, V>, Cloneable, Serializable
{
+
+ private static final Object NULL = new Object();
private static final long serialVersionUID = 10929568968762L;
/**
@@ -108,14 +110,13 @@
putAll(data);
}
+ @SuppressWarnings("unchecked")
private void init(int initialCapacity, float loadFactor)
{
int c = 1;
for (; c < initialCapacity; c <<= 1) ;
- @SuppressWarnings("unchecked")
- Entry<K, V>[] table = (Entry<K, V>[]) new Entry[c];
- this.table = table;
+ this.table = (Entry<K, V>[]) new Entry[c];
threshold = (int) (c * loadFactor);
}
@@ -166,8 +167,7 @@
public V get(Object key)
{
- if (key == null)
- throw new IllegalArgumentException("Null keys are not allowed");
+ if (key == null) key = NULL;
int hash = hash(key);
int length = table.length;
@@ -188,8 +188,7 @@
public boolean containsKey(Object key)
{
- if (key == null)
- throw new IllegalArgumentException("Null keys are not allowed");
+ if (key == null) key = NULL;
int hash = hash(key);
int length = table.length;
@@ -217,10 +216,10 @@
return false;
}
+ @SuppressWarnings("unchecked")
public V put(K key, V value)
{
- if (key == null)
- throw new IllegalArgumentException("Null keys are not allowed");
+ if (key == null) key = (K) NULL;
Entry<K, V>[] table = this.table;
@@ -256,6 +255,7 @@
}
+ @SuppressWarnings("unchecked")
private void resize(int from)
{
int newLength = from << 1;
@@ -264,7 +264,6 @@
if (newLength > MAXIMUM_CAPACITY || newLength <= from)
return;
- @SuppressWarnings("unchecked")
Entry<K, V>[] newTable = new Entry[newLength];
Entry<K, V>[] old = table;
@@ -307,8 +306,7 @@
public V remove(Object key)
{
- if (key == null)
- throw new IllegalArgumentException("Null keys are not allowed");
+ if (key == null) key = NULL;
Entry<K, V>[] table = this.table;
int length = table.length;
@@ -376,11 +374,11 @@
size = 0;
}
+ @SuppressWarnings("unchecked")
public Object clone()
{
try
{
- @SuppressWarnings("unchecked")
FastCopyHashMap<K, V> clone = (FastCopyHashMap<K, V>)
super.clone();
clone.table = table.clone();
clone.entrySet = null;
@@ -470,10 +468,10 @@
}
}
+ @SuppressWarnings("unchecked")
private void putForCreate(K key, V value)
{
- if (key == null)
- throw new IllegalArgumentException("Null keys are not allowed");
+ if (key == null) key = (K) NULL;
Entry<K, V>[] table = this.table;
int hash = hash(key);
@@ -560,6 +558,7 @@
return table[current];
}
+ @SuppressWarnings("unchecked")
public void remove()
{
if (modCount != expectedCount)
@@ -609,7 +608,6 @@
if (i < current && current <= delete && table ==
FastCopyHashMap.this.table)
{
int remaining = length - current;
- @SuppressWarnings("unchecked")
Entry<K, V>[] newTable = (Entry<K, V>[]) new
Entry[remaining];
System.arraycopy(table, current, newTable, 0, remaining);