[jboss-cvs] JBossCache/src-50/org/jboss/cache/pojo/collection ...
Manik Surtani
msurtani at jboss.com
Sat Dec 30 12:49:53 EST 2006
User: msurtani
Date: 06/12/30 12:49:53
Modified: src-50/org/jboss/cache/pojo/collection
CachedListImpl.java CachedSetImpl.java
CachedMapImpl.java
Log:
Major changes to restructure cache and node object model
Revision Changes Path
1.13 +39 -30 JBossCache/src-50/org/jboss/cache/pojo/collection/CachedListImpl.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CachedListImpl.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src-50/org/jboss/cache/pojo/collection/CachedListImpl.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- CachedListImpl.java 9 Nov 2006 16:53:28 -0000 1.12
+++ CachedListImpl.java 30 Dec 2006 17:49:53 -0000 1.13
@@ -6,28 +6,25 @@
*/
package org.jboss.cache.pojo.collection;
-import org.jboss.cache.DataNode;
-import org.jboss.cache.Fqn;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.jboss.cache.CacheSPI;
+import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
-import org.jboss.cache.pojo.util.AopUtil;
-import org.jboss.cache.pojo.util.Null;
-import org.jboss.cache.pojo.util.CacheApiUtil;
-import org.jboss.cache.pojo.PojoTreeCache;
import org.jboss.cache.pojo.impl.PojoCacheImpl;
import org.jboss.cache.pojo.interceptors.dynamic.AbstractCollectionInterceptor;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.jboss.cache.pojo.util.AopUtil;
+import org.jboss.cache.pojo.util.CacheApiUtil;
+import org.jboss.cache.pojo.util.Null;
+import java.io.ObjectStreamException;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
-import java.util.Map;
import java.util.NoSuchElementException;
-import java.util.Collection;
-import java.util.ArrayList;
-import java.io.ObjectStreamException;
/**
* List implementation that uses cache as a backend store.
@@ -45,7 +42,7 @@
public CachedListImpl(PojoCacheImpl cache, AbstractCollectionInterceptor interceptor)
{
pCache_ = cache;
- cache_ = (CacheSPI)pCache_.getCache();
+ cache_ = (CacheSPI) pCache_.getCache();
interceptor_ = interceptor;
}
@@ -60,14 +57,15 @@
try
{
return CacheApiUtil.getDataNode(cache_, getFqn());
- } catch (Exception e)
+ }
+ catch (Exception e)
{
throw new RuntimeException(e);
}
}
- /** Serialize a normal ArrayList
- *
+ /**
+ * Serialize a normal ArrayList
*/
private Object XwriteReplace() throws ObjectStreamException
{
@@ -85,7 +83,8 @@
try
{
return Null.toNullValue(pCache_.getObject(AopUtil.constructFqn(getFqn(), IntegerCache.toString(index))));
- } catch (Exception e)
+ }
+ catch (Exception e)
{
throw new RuntimeException(e);
}
@@ -124,7 +123,8 @@
checkIndex(); // Since index can be size().
return Null.toNullValue(pCache_.attach(AopUtil.constructFqn(getFqn(),
IntegerCache.toString(index)), Null.toNullObject(element)));
- } catch (Exception e)
+ }
+ catch (Exception e)
{
throw new RuntimeException(e);
}
@@ -142,7 +142,8 @@
pCache_.attach(AopUtil.constructFqn(getFqn(), IntegerCache.toString(i)), obj);
}
pCache_.attach(AopUtil.constructFqn(getFqn(), IntegerCache.toString(index)), Null.toNullObject(element));
- } catch (Exception e)
+ }
+ catch (Exception e)
{
throw new RuntimeException(e);
}
@@ -158,7 +159,8 @@
if (null == get(i))
return i;
}
- } else
+ }
+ else
{
for (int i = 0; i < size; i++)
{
@@ -178,7 +180,8 @@
if (null == get(i))
return i;
}
- } else
+ }
+ else
{
for (int i = size() - 1; i >= 0; i--)
{
@@ -207,7 +210,8 @@
pCache_.attach(AopUtil.constructFqn(getFqn(), IntegerCache.toString(i)), obj);
}
return result;
- } catch (Exception e)
+ }
+ catch (Exception e)
{
throw new RuntimeException(e);
}
@@ -241,7 +245,8 @@
try
{
return Null.toNullValue(pCache_.getObject(AopUtil.constructFqn(getFqn(), IntegerCache.toString(++current))));
- } catch (Exception e)
+ }
+ catch (Exception e)
{
throw new RuntimeException(e);
}
@@ -265,14 +270,16 @@
last = pCache_.detach(AopUtil.constructFqn(getFqn(), IntegerCache.toString(i)));
pCache_.attach(AopUtil.constructFqn(getFqn(), IntegerCache.toString(i - 1)), last);
}
- } else
+ }
+ else
{ // we are the last index.
// Need to move back the cursor.
pCache_.detach(AopUtil.constructFqn(getFqn(), IntegerCache.toString(current)));
}
current--;
size--;
- } catch (Exception e)
+ }
+ catch (Exception e)
{
throw new RuntimeException(e);
}
@@ -344,7 +351,8 @@
list_.remove(previousIndex());
index--;
}
- } catch (Exception e)
+ }
+ catch (Exception e)
{
throw new RuntimeException(e);
}
@@ -442,7 +450,7 @@
private Iterator initializeIter()
{
Iterator iter = backStore_.iterator();
- for (int looper = 0; looper < fromIndex_; looper ++)
+ for (int looper = 0; looper < fromIndex_; looper++)
if (iter.hasNext()) // skip past to where we need to start from
iter.next();
return iter;
@@ -468,7 +476,8 @@
try
{
return iter_.next();
- } catch (Exception e)
+ }
+ catch (Exception e)
{
throw new RuntimeException(e);
}
1.13 +82 -86 JBossCache/src-50/org/jboss/cache/pojo/collection/CachedSetImpl.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CachedSetImpl.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src-50/org/jboss/cache/pojo/collection/CachedSetImpl.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- CachedSetImpl.java 8 Nov 2006 22:20:15 -0000 1.12
+++ CachedSetImpl.java 30 Dec 2006 17:49:53 -0000 1.13
@@ -7,25 +7,20 @@
package org.jboss.cache.pojo.collection;
import org.jboss.cache.CacheException;
-import org.jboss.cache.DataNode;
-import org.jboss.cache.Fqn;
import org.jboss.cache.CacheSPI;
+import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
-import org.jboss.cache.pojo.util.AopUtil;
-import org.jboss.cache.pojo.util.Null;
-import org.jboss.cache.pojo.util.CacheApiUtil;
-import org.jboss.cache.pojo.PojoTreeCache;
import org.jboss.cache.pojo.annotation.Reentrant;
import org.jboss.cache.pojo.impl.PojoCacheImpl;
import org.jboss.cache.pojo.interceptors.dynamic.AbstractCollectionInterceptor;
+import org.jboss.cache.pojo.util.AopUtil;
+import org.jboss.cache.pojo.util.CacheApiUtil;
+import org.jboss.cache.pojo.util.Null;
import java.util.AbstractSet;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-import java.util.ArrayList;
/**
* Set implementation that uses a cache as an underlying backend store.
@@ -50,7 +45,7 @@
public CachedSetImpl(PojoCacheImpl cache, AbstractCollectionInterceptor interceptor)
{
pCache_ = cache;
- this.cache_ = (CacheSPI)pCache_.getCache();
+ this.cache_ = (CacheSPI) pCache_.getCache();
this.interceptor_ = interceptor;
}
@@ -182,7 +177,8 @@
* TODO should be able to use java.lang.Long, but some CacheLoader don't
* support non-String keys
*/
- private String toLong(long hashCode, long count) {
+ private String toLong(long hashCode, long count)
+ {
long key = (hashCode & 0xFFFFL) | (count << 32);
return Long.toHexString(key);
}
1.15 +40 -29 JBossCache/src-50/org/jboss/cache/pojo/collection/CachedMapImpl.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CachedMapImpl.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src-50/org/jboss/cache/pojo/collection/CachedMapImpl.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- CachedMapImpl.java 17 Sep 2006 07:50:31 -0000 1.14
+++ CachedMapImpl.java 30 Dec 2006 17:49:53 -0000 1.15
@@ -6,18 +6,19 @@
*/
package org.jboss.cache.pojo.collection;
+import org.jboss.aop.Advised;
import org.jboss.cache.CacheException;
-import org.jboss.cache.DataNode;
-import org.jboss.cache.Fqn;
import org.jboss.cache.CacheSPI;
+import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
-import org.jboss.cache.pojo.util.Null;
-import org.jboss.cache.pojo.util.CacheApiUtil;
import org.jboss.cache.pojo.annotation.Reentrant;
import org.jboss.cache.pojo.impl.PojoCacheImpl;
import org.jboss.cache.pojo.interceptors.dynamic.AbstractCollectionInterceptor;
-import org.jboss.aop.Advised;
+import org.jboss.cache.pojo.util.CacheApiUtil;
+import org.jboss.cache.pojo.util.Null;
+import java.io.NotSerializableException;
+import java.io.Serializable;
import java.util.AbstractCollection;
import java.util.AbstractSet;
import java.util.ArrayList;
@@ -26,8 +27,6 @@
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
-import java.io.Serializable;
-import java.io.NotSerializableException;
/**
* Map that uses cache as a backend store.
@@ -48,14 +47,15 @@
public CachedMapImpl(PojoCacheImpl pCache, AbstractCollectionInterceptor interceptor)
{
pCache_ = pCache;
- cache_ = (CacheSPI)pCache_.getCache();
+ cache_ = (CacheSPI) pCache_.getCache();
interceptor_ = interceptor;
}
private static Fqn constructFqn(Fqn baseFqn, Object relative) throws NotSerializableException
{
- if(! (relative instanceof Serializable ) && !(relative instanceof Advised)) {
+ if (!(relative instanceof Serializable) && !(relative instanceof Advised))
+ {
throw new NotSerializableException(relative.getClass().getName());
}
@@ -75,7 +75,8 @@
try
{
return CacheApiUtil.getDataNode(cache_, getFqn());
- } catch (Exception e)
+ }
+ catch (Exception e)
{
throw new RuntimeException(e);
}
@@ -86,7 +87,8 @@
try
{
return Null.toNullValue(pCache_.getObject(constructFqn(getFqn(), Null.toNullKeyObject(key))));
- } catch (Exception e)
+ }
+ catch (Exception e)
{
throw new RuntimeException(e);
}
@@ -97,7 +99,8 @@
try
{
return pCache_.attach(constructFqn(getFqn(), Null.toNullKeyObject(key)), Null.toNullObject(value));
- } catch (Exception e)
+ }
+ catch (Exception e)
{
throw new RuntimeException(e);
}
@@ -117,7 +120,8 @@
try
{
return pCache_.detach(constructFqn(getFqn(), Null.toNullKeyObject(key)));
- } catch (Exception e)
+ }
+ catch (Exception e)
{
throw new RuntimeException(e);
}
@@ -153,10 +157,10 @@
public boolean containsKey(Object object)
{
Collection<Node> children = getNode().getChildren();
- if(children == null) return false;
- for(Node n: children)
+ if (children == null) return false;
+ for (Node n : children)
{
- if(n.getFqn().getLast().equals(Null.toNullKeyObject(object))) return true;
+ if (n.getFqn().getLast().equals(Null.toNullKeyObject(object))) return true;
}
return false;
@@ -198,7 +202,7 @@
public Object next()
{
- return new Entry(lastKey = ((Node)i.next()).getFqn().getLast());
+ return new Entry(lastKey = ((Node) i.next()).getFqn().getLast());
}
public void remove()
@@ -249,7 +253,7 @@
{
try
{
- Fqn f = ((Node)i.next()).getFqn();
+ Fqn f = ((Node) i.next()).getFqn();
lastKey = f.getLast();
return Null.toNullValue(pCache_.getObject(f));
}
@@ -303,7 +307,7 @@
public Object next()
{
- lastKey = ((Node)i.next()).getFqn().getLast();
+ lastKey = ((Node) i.next()).getFqn().getLast();
return Null.toNullKeyValue(lastKey);
}
@@ -324,7 +328,8 @@
public int hashCode()
{
int result = 0;
- for (Iterator i = entrySet().iterator(); i.hasNext();) {
+ for (Iterator i = entrySet().iterator(); i.hasNext();)
+ {
result += i.next().hashCode();
}
return result;
@@ -339,17 +344,21 @@
Map map = (Map) object;
if (size() != map.size())
return false;
- for (Iterator i = entrySet().iterator(); i.hasNext();) {
+ for (Iterator i = entrySet().iterator(); i.hasNext();)
+ {
Entry entry = (Entry) i.next();
Object value = entry.getValue();
Object key = entry.getKey();
- if (value == null) {
- if(! (map.get(key) == null && map.containsKey(key))) {
+ if (value == null)
+ {
+ if (!(map.get(key) == null && map.containsKey(key)))
+ {
return false;
}
}
- else {
- if (! value.equals(map.get(key)))
+ else
+ {
+ if (!value.equals(map.get(key)))
return false;
}
}
@@ -390,7 +399,8 @@
try
{
return Null.toNullValue(pCache_.getObject(constructFqn(getFqn(), key)));
- } catch (Exception e)
+ }
+ catch (Exception e)
{
throw new RuntimeException(e);
}
@@ -401,7 +411,8 @@
try
{
return pCache_.attach(constructFqn(getFqn(), key), Null.toNullObject(value));
- } catch (Exception e)
+ }
+ catch (Exception e)
{
throw new RuntimeException(e);
}
More information about the jboss-cvs-commits
mailing list