[jboss-cvs] JBossCache/src-50/org/jboss/cache/pojo/collection ...
Ben Wang
bwang at jboss.com
Wed Jan 3 03:55:37 EST 2007
User: bwang
Date: 07/01/03 03:55:37
Modified: src-50/org/jboss/cache/pojo/collection
CachedMapImpl.java CachedListAbstract.java
CollectionInterceptorUtil.java IntegerCache.java
CachedListImpl.java CachedSetImpl.java
Log:
Siwtch RuntimeException to PojoCacheException inside PojoCache.
Revision Changes Path
1.19 +14 -65 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.18
retrieving revision 1.19
diff -u -b -r1.18 -r1.19
--- CachedMapImpl.java 3 Jan 2007 06:23:25 -0000 1.18
+++ CachedMapImpl.java 3 Jan 2007 08:55:37 -0000 1.19
@@ -7,17 +7,16 @@
package org.jboss.cache.pojo.collection;
import org.jboss.aop.Advised;
-import org.jboss.cache.CacheException;
import org.jboss.cache.CacheSPI;
import org.jboss.cache.Fqn;
import org.jboss.cache.Node;
+import org.jboss.cache.pojo.PojoCacheException;
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.CacheApiUtil;
import org.jboss.cache.pojo.util.Null;
-import java.io.NotSerializableException;
import java.io.Serializable;
import java.util.AbstractCollection;
import java.util.AbstractSet;
@@ -52,11 +51,11 @@
}
- private static Fqn constructFqn(Fqn baseFqn, Object relative) throws NotSerializableException
+ private static Fqn constructFqn(Fqn baseFqn, Object relative)
{
if (!(relative instanceof Serializable) && !(relative instanceof Advised))
{
- throw new NotSerializableException(relative.getClass().getName());
+ throw new PojoCacheException("Non-serializable for " + relative.getClass().getName());
}
return new Fqn(baseFqn, relative);
@@ -72,39 +71,18 @@
private Set<Node> getNodeChildren()
{
- try
- {
return CacheApiUtil.getNodeChildren(cache_, getFqn());
}
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
public Object get(Object key)
{
- try
- {
return Null.toNullValue(pCache_.getObject(constructFqn(getFqn(), Null.toNullKeyObject(key))));
}
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
public Object put(Object key, Object value)
{
- try
- {
return pCache_.attach(constructFqn(getFqn(), Null.toNullKeyObject(key)), Null.toNullObject(value));
}
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
public void putAll(Map map)
{
@@ -117,15 +95,8 @@
public Object remove(Object key)
{
- try
- {
return pCache_.detach(constructFqn(getFqn(), Null.toNullKeyObject(key)));
}
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
public void clear()
{
@@ -154,7 +125,7 @@
if (children == null) return false;
for (Object n : children)
{
- if (((Node)n).getFqn().getLastElement().equals(Null.toNullKeyObject(object))) return true;
+ if (((Node) n).getFqn().getLastElement().equals(Null.toNullKeyObject(object))) return true;
}
return false;
@@ -245,17 +216,10 @@
public Object next()
{
- try
- {
Fqn f = ((Node) i.next()).getFqn();
lastKey = f.getLastElement();
return Null.toNullValue(pCache_.getObject(f));
}
- catch (CacheException e)
- {
- throw new RuntimeException(e);
- }
- }
public void remove()
{
@@ -349,8 +313,7 @@
{
return false;
}
- }
- else
+ } else
{
if (!value.equals(map.get(key)))
return false;
@@ -390,27 +353,13 @@
public Object getValue()
{
- try
- {
return Null.toNullValue(pCache_.getObject(constructFqn(getFqn(), key)));
}
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
public Object setValue(Object value)
{
- try
- {
return pCache_.attach(constructFqn(getFqn(), key), Null.toNullObject(value));
}
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
public int hashCode()
{
1.6 +7 -5 JBossCache/src-50/org/jboss/cache/pojo/collection/CachedListAbstract.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CachedListAbstract.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src-50/org/jboss/cache/pojo/collection/CachedListAbstract.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- CachedListAbstract.java 17 Sep 2006 07:42:18 -0000 1.5
+++ CachedListAbstract.java 3 Jan 2007 08:55:37 -0000 1.6
@@ -55,7 +55,7 @@
{
a[looper] = get(looper);
}
- for (; looper < a.length; looper ++)
+ for (; looper < a.length; looper++)
a[looper] = null; // if the array is larger than needed, set extra slots to null
return a;
}
@@ -129,7 +129,8 @@
public int hashCode()
{
int result = 1;
- for (int i =0; i < size(); i++) {
+ for (int i = 0; i < size(); i++)
+ {
Object o = get(i);
result = 31 * result + (o == null ? 0 : o.hashCode());
}
@@ -145,10 +146,11 @@
List list = (List) object;
if (size() != list.size())
return false;
- for (int i=0; i < list.size(); i++) {
+ for (int i = 0; i < list.size(); i++)
+ {
Object value1 = get(i);
Object value2 = list.get(i);
- if( (value1 == null && value2 != null) ||
+ if ((value1 == null && value2 != null) ||
(value1 != null && !(value1.equals(value2))))
return false;
}
@@ -175,7 +177,7 @@
Iterator iter = iterator();
while (iter.hasNext())
{
- if (! c.contains(iter.next()))
+ if (!c.contains(iter.next()))
{
iter.remove();
changedAnything = true;
1.10 +7 -11 JBossCache/src-50/org/jboss/cache/pojo/collection/CollectionInterceptorUtil.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: CollectionInterceptorUtil.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src-50/org/jboss/cache/pojo/collection/CollectionInterceptorUtil.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- CollectionInterceptorUtil.java 30 Dec 2006 19:48:50 -0000 1.9
+++ CollectionInterceptorUtil.java 3 Jan 2007 08:55:37 -0000 1.10
@@ -63,16 +63,13 @@
if (interceptor instanceof CachedListInterceptor)
{
bind = "execution(public String " + CachedListAbstract.class.getName() + "->toString())";
- }
- else if (interceptor instanceof CachedSetInterceptor)
+ } else if (interceptor instanceof CachedSetInterceptor)
{
bind = "execution(public String " + CachedSetImpl.class.getName() + "->toString())";
- }
- else if (interceptor instanceof CachedMapInterceptor)
+ } else if (interceptor instanceof CachedMapInterceptor)
{
bind = "execution(public String " + CachedMapImpl.class.getName() + "->toString())";
- }
- else
+ } else
{
throw new IllegalStateException("CollectionInterceptorUtil.createProxy(). Non Collection interceptor"
+ interceptor);
@@ -126,7 +123,7 @@
}
catch (Exception e)
{
- throw new RuntimeException(e);
+ throw new PojoCacheException(e);
}
result = ClassProxyFactory.getMethodMap(clazz.getName());
}
@@ -143,7 +140,7 @@
catch (NoSuchMethodException e)
{
e.printStackTrace();
- throw new RuntimeException("getManagedMathods: " + e);
+ throw new PojoCacheException("getManagedMathods: " + e);
}
Map managedMethods = new HashMap();
@@ -188,8 +185,7 @@
if (method != null)
{
return method.invoke(interceptor, args);
- }
- else
+ } else
{
method = methodInvocation.getMethod();
if (method == null)
@@ -202,7 +198,7 @@
Object target = methodInvocation.getTargetObject();
if (target == null)
{
- throw new RuntimeException("CollectionInterceptorUtil.invoke(): targetObject is null." +
+ throw new PojoCacheException("CollectionInterceptorUtil.invoke(): targetObject is null." +
" Can't invoke " + method.toString());
}
return method.invoke(target, args);
1.2 +28 -24 JBossCache/src-50/org/jboss/cache/pojo/collection/IntegerCache.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: IntegerCache.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src-50/org/jboss/cache/pojo/collection/IntegerCache.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- IntegerCache.java 6 Nov 2006 23:32:16 -0000 1.1
+++ IntegerCache.java 3 Jan 2007 08:55:37 -0000 1.2
@@ -6,8 +6,12 @@
public class IntegerCache
{
- private IntegerCache() {}
+ private IntegerCache()
+ {
+ }
+
private static final String values[] = new String[100];
+
static
{
for (int i = 0; i < values.length; i++)
1.16 +50 -119 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.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- CachedListImpl.java 3 Jan 2007 06:23:25 -0000 1.15
+++ CachedListImpl.java 3 Jan 2007 08:55:37 -0000 1.16
@@ -19,7 +19,6 @@
import java.io.ObjectStreamException;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
@@ -56,15 +55,8 @@
private Set<Node> getNodeChildren()
{
- try
- {
return CacheApiUtil.getNodeChildren(cache_, getFqn());
}
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
/**
* Serialize a normal ArrayList
@@ -82,15 +74,8 @@
public Object get(int index)
{
checkIndex();
- try
- {
return Null.toNullValue(pCache_.getObject(AopUtil.constructFqn(getFqn(), IntegerCache.toString(index))));
}
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
private static void checkIndex()
{
@@ -113,23 +98,14 @@
public Object set(int index, Object element)
{
- try
- {
if (index != 0)
checkIndex(); // Since index can be size().
return Null.toNullValue(pCache_.attach(AopUtil.constructFqn(getFqn(),
IntegerCache.toString(index)), Null.toNullObject(element)));
}
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
public void add(int index, Object element)
{
- try
- {
if (index != 0)
checkIndex(); // Since index can be size().
for (int i = size(); i > index; i--)
@@ -139,11 +115,6 @@
}
pCache_.attach(AopUtil.constructFqn(getFqn(), IntegerCache.toString(index)), Null.toNullObject(element));
}
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
public int indexOf(Object o)
{
@@ -155,8 +126,7 @@
if (null == get(i))
return i;
}
- }
- else
+ } else
{
for (int i = 0; i < size; i++)
{
@@ -176,8 +146,7 @@
if (null == get(i))
return i;
}
- }
- else
+ } else
{
for (int i = size() - 1; i >= 0; i--)
{
@@ -190,8 +159,6 @@
public Object remove(int index)
{
- try
- {
checkIndex();
// Object result = cache.removeObject(((Fqn) fqn.clone()).add(new Integer(index)));
int size = size();
@@ -207,11 +174,6 @@
}
return result;
}
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
public Iterator iterator()
{
@@ -238,21 +200,12 @@
throw new NoSuchElementException("CachedSetImpl.iterator.next(). " +
" Cursor position " + current + " is greater than the size " + size());
- try
- {
return Null.toNullValue(pCache_.getObject(AopUtil.constructFqn(getFqn(), IntegerCache.toString(++current))));
}
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
public void remove()
{
// TODO Need optimization here since set does not care about index
- try
- {
if (size == 0) return;
if (current == size)
throw new IllegalStateException("CachedSetImpl.iterator.remove(). " +
@@ -266,8 +219,7 @@
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)));
@@ -275,11 +227,6 @@
current--;
size--;
}
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
};
}
@@ -334,9 +281,6 @@
public void remove()
{
-
- try
- {
int size = list_.size();
if (size == 0) return;
if (previousIndex() == size)
@@ -348,12 +292,6 @@
index--;
}
}
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
-
- }
public boolean hasNext()
{
@@ -469,15 +407,8 @@
throw new IllegalStateException("CachedSetImpl.MyCachedSubListImpl.iterator.next(). " +
" Cursor position " + current + " is greater than the size " + size());
current++;
- try
- {
return iter_.next();
}
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
public void remove()
{
1.16 +2 -9 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.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- CachedSetImpl.java 3 Jan 2007 06:23:25 -0000 1.15
+++ CachedSetImpl.java 3 Jan 2007 08:55:37 -0000 1.16
@@ -52,15 +52,8 @@
private Set<Node> getNodeChildren()
{
- try
- {
return CacheApiUtil.getNodeChildren(cache_, getFqn());
}
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- }
private Fqn getFqn()
{
@@ -157,7 +150,7 @@
public int size()
{
Set<Node> children = getNodeChildren();
- return (children == null)? 0: children.size();
+ return (children == null) ? 0 : children.size();
}
public String toString()
More information about the jboss-cvs-commits
mailing list