[infinispan-commits] Infinispan SVN: r2596 - branches/4.2.x/core/src/main/java/org/infinispan/atomic.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Mon Oct 25 11:24:42 EDT 2010


Author: manik.surtani at jboss.com
Date: 2010-10-25 11:24:41 -0400 (Mon, 25 Oct 2010)
New Revision: 2596

Modified:
   branches/4.2.x/core/src/main/java/org/infinispan/atomic/AtomicHashMap.java
   branches/4.2.x/core/src/main/java/org/infinispan/atomic/AtomicHashMapProxy.java
Log:
Genericized

Modified: branches/4.2.x/core/src/main/java/org/infinispan/atomic/AtomicHashMap.java
===================================================================
--- branches/4.2.x/core/src/main/java/org/infinispan/atomic/AtomicHashMap.java	2010-10-25 15:10:46 UTC (rev 2595)
+++ branches/4.2.x/core/src/main/java/org/infinispan/atomic/AtomicHashMap.java	2010-10-25 15:24:41 UTC (rev 2596)
@@ -69,10 +69,11 @@
     * Construction only allowed through this factory method.  This factory is intended for use internally by the
     * CacheDelegate.  User code should use {@link AtomicMapLookup#getAtomicMap(Cache, Object)}.
     */
-   public static AtomicHashMap newInstance(Cache cache, Object cacheKey) {
-      AtomicHashMap value = new AtomicHashMap();
+   @SuppressWarnings("unchecked")
+   public static <K, V> AtomicHashMap<K, V> newInstance(Cache cache, Object cacheKey) {
+      AtomicHashMap<K, V> value = new AtomicHashMap<K, V>();
       Object oldValue = cache.putIfAbsent(cacheKey, value);
-      if (oldValue != null) value = (AtomicHashMap) oldValue;
+      if (oldValue != null) value = (AtomicHashMap<K, V>) oldValue;
       return value;
    }
 
@@ -133,6 +134,7 @@
       return oldValue;
    }
 
+   @SuppressWarnings("unchecked")
    public V remove(Object key) {
       V oldValue = delegate.remove(key);
       RemoveOperation<K, V> op = new RemoveOperation<K, V>((K) key, oldValue);
@@ -145,6 +147,7 @@
       for (Entry<? extends K, ? extends V> e : t.entrySet()) put(e.getKey(), e.getValue());
    }
 
+   @SuppressWarnings("unchecked")
    public void clear() {
       FastCopyHashMap<K, V> originalEntries = (FastCopyHashMap<K, V>) delegate.clone();
       ClearOperation<K, V> op = new ClearOperation<K, V>(originalEntries);
@@ -175,10 +178,11 @@
       return toReturn;
    }
 
-   public AtomicHashMap copyForWrite() {
+   @SuppressWarnings("unchecked")
+   public AtomicHashMap<K, V> copyForWrite() {
       try {
-         AtomicHashMap clone = (AtomicHashMap) super.clone();
-         clone.delegate = (FastCopyHashMap) delegate.clone();
+         AtomicHashMap<K, V> clone = (AtomicHashMap<K, V>) super.clone();
+         clone.delegate = (FastCopyHashMap<K, V>) delegate.clone();
          clone.proxy = proxy;
          clone.copied = true;
          return clone;
@@ -214,6 +218,7 @@
          output.writeObject(map.delegate);
       }
 
+      @SuppressWarnings("unchecked")
       public Object readObject(ObjectInput input) throws IOException, ClassNotFoundException {
          FastCopyHashMap delegate = (FastCopyHashMap) input.readObject();
          return new AtomicHashMap(delegate);

Modified: branches/4.2.x/core/src/main/java/org/infinispan/atomic/AtomicHashMapProxy.java
===================================================================
--- branches/4.2.x/core/src/main/java/org/infinispan/atomic/AtomicHashMapProxy.java	2010-10-25 15:10:46 UTC (rev 2595)
+++ branches/4.2.x/core/src/main/java/org/infinispan/atomic/AtomicHashMapProxy.java	2010-10-25 15:24:41 UTC (rev 2596)
@@ -62,13 +62,14 @@
    Cache cache;
    InvocationContextContainer icc;
 
-   AtomicHashMapProxy(Cache cache, Object deltaMapKey, BatchContainer batchContainer, InvocationContextContainer icc) {
+   AtomicHashMapProxy(Cache<?, ?> cache, Object deltaMapKey, BatchContainer batchContainer, InvocationContextContainer icc) {
       this.cache = cache;
       this.deltaMapKey = deltaMapKey;
       this.batchContainer = batchContainer;
       this.icc = icc;
    }
 
+   @SuppressWarnings("unchecked")
    private AtomicHashMap<K, V> toMap(Object object) {
       Object map = (object instanceof MarshalledValue) ? ((MarshalledValue) object).get() : object;
       return (AtomicHashMap<K, V>) map;
@@ -79,6 +80,7 @@
       return toMap(cache.get(deltaMapKey));
    }
 
+   @SuppressWarnings("unchecked")
    private AtomicHashMap<K, V> getDeltaMapForWrite(InvocationContext ctx) {
       CacheEntry lookedUpEntry = ctx.lookupEntry(deltaMapKey);
       boolean lockedAndCopied = lookedUpEntry != null && lookedUpEntry.isChanged() &&
@@ -98,9 +100,9 @@
                log.trace("Forcing write lock even for reads");
          }
 
-         AtomicHashMap map = getDeltaMapForRead();
+         AtomicHashMap<K, V> map = getDeltaMapForRead();
          // copy for write
-         AtomicHashMap copy = map == null ? new AtomicHashMap(true) : map.copyForWrite();
+         AtomicHashMap<K, V> copy = map == null ? new AtomicHashMap<K, V>(true) : map.copyForWrite();
          copy.initForWriting();
          // reinstate the flag
          if (suppressLocks) ctx.setFlags(Flag.SKIP_LOCKING);
@@ -113,17 +115,17 @@
 
    public Set<K> keySet() {
       AtomicHashMap<K, V> map = getDeltaMapForRead();
-      return map == null ? Collections.EMPTY_SET : map.keySet();
+      return map == null ? Collections.<K>emptySet() : map.keySet();
    }
 
    public Collection<V> values() {
       AtomicHashMap<K, V> map = getDeltaMapForRead();
-      return map == null ? Collections.EMPTY_SET : map.values();
+      return map == null ? Collections.<V>emptySet() : map.values();
    }
 
    public Set<Entry<K, V>> entrySet() {
       AtomicHashMap<K, V> map = getDeltaMapForRead();
-      return map == null ? Collections.EMPTY_SET : map.entrySet();
+      return map == null ? Collections.<Entry<K,V>>emptySet() : map.entrySet();
    }
 
    public int size() {
@@ -133,17 +135,17 @@
 
    public boolean isEmpty() {
       AtomicHashMap<K, V> map = getDeltaMapForRead();
-      return map == null ? true : map.isEmpty();
+      return map == null || map.isEmpty();
    }
 
    public boolean containsKey(Object key) {
       AtomicHashMap<K, V> map = getDeltaMapForRead();
-      return map == null ? false : map.containsKey(key);
+      return map != null && map.containsKey(key);
    }
 
    public boolean containsValue(Object value) {
       AtomicHashMap<K, V> map = getDeltaMapForRead();
-      return map == null ? false : map.containsValue(value);
+      return map != null && map.containsValue(value);
    }
 
    public V get(Object key) {



More information about the infinispan-commits mailing list