[jboss-cvs] JBossCache/tests/functional/org/jboss/cache/loader ...
Manik Surtani
manik at jboss.org
Fri Jul 20 08:54:19 EDT 2007
User: msurtani
Date: 07/07/20 08:54:19
Modified: tests/functional/org/jboss/cache/loader
DummyInMemoryCacheLoader.java
Log:
CHM dealing with nulls
Revision Changes Path
1.14 +73 -11 JBossCache/tests/functional/org/jboss/cache/loader/DummyInMemoryCacheLoader.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: DummyInMemoryCacheLoader.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/tests/functional/org/jboss/cache/loader/DummyInMemoryCacheLoader.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- DummyInMemoryCacheLoader.java 19 Jul 2007 10:50:43 -0000 1.13
+++ DummyInMemoryCacheLoader.java 20 Jul 2007 12:54:19 -0000 1.14
@@ -13,6 +13,7 @@
import org.jboss.cache.Modification;
import org.jboss.cache.config.CacheLoaderConfig.IndividualCacheLoaderConfig;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -31,6 +32,13 @@
protected Log log = LogFactory.getLog(DummyInMemoryCacheLoader.class);
protected Map<Object, List<Modification>> transactions = new ConcurrentHashMap<Object, List<Modification>>();
protected boolean debug; // whether to dump System.out messages as well as log messages or not
+ protected final Object NULL = new Object()
+ {
+ public String toString()
+ {
+ return "NULL placeholder";
+ }
+ };
public void setConfig(IndividualCacheLoaderConfig config)
{
@@ -79,13 +87,64 @@
public Map get(Fqn name) throws Exception
{
DummyNode dn = nodes.get(name);
- Map d = dn != null ? dn.data : null;
+ Map<Object, Object> d = dn != null ? dn.data : null;
if (log.isDebugEnabled()) log.debug("Getting data for fqn " + name + " = " + d);
debugMessage("Getting data for fqn " + name + " = " + d);
+ return stripNULLs(d);
+ }
+
+ private Map stripNULLs(Map data)
+ {
+ if (data == null) return null;
+ // otherwise make sure we replace NULL placeholders with nulls.
+ Map<Object, Object> d = new HashMap(data);
+ if (d.containsKey(NULL))
+ {
+ Object v = d.remove(NULL);
+ d.put(null, v);
+ }
+ Set keys = new HashSet();
+ for (Map.Entry<?, ?> e : d.entrySet())
+ {
+ if (e.getValue() == NULL)
+ {
+ keys.add(e.getKey());
+ }
+ }
+ for (Object k : keys)
+ {
+ d.put(k, null);
+ }
return d;
}
+ private Map injectNULLs(Map data)
+ {
+ if (data == null) return null;
+ // otherwise make sure we replace NULL placeholders with nulls.
+ Map<Object, Object> d = new HashMap(data);
+ if (d.containsKey(null))
+ {
+ Object v = d.remove(null);
+ d.put(NULL, v);
+ }
+ Set keys = new HashSet();
+ for (Map.Entry<?, ?> e : d.entrySet())
+ {
+ if (e.getValue() == null)
+ {
+ keys.add(e.getKey());
+ }
+ }
+ for (Object k : keys)
+ {
+ d.put(k, NULL);
+ }
+ return d;
+ }
+
+
public boolean exists(Fqn name) throws Exception
{
debugMessage("Performing exists() on " + name);
@@ -99,13 +158,16 @@
{
n = new DummyNode(name);
}
- Object old = n.data.put(key, value);
+ Object k = key == null ? NULL : key;
+ Object v = value == null ? NULL : value;
+ Object old = n.data.put(k, v);
+
nodes.put(name, n);
// we need to make sure parents get put in as well.
recursivelyPutParentsIfNeeded(name);
if (log.isDebugEnabled()) log.debug("Did a put on " + name + ", data is " + n.data);
debugMessage("Did a put on " + name + ", data is " + n.data);
- return old;
+ return old == NULL ? null : old;
}
public void put(Fqn name, Map attributes) throws Exception
@@ -115,7 +177,7 @@
{
n = new DummyNode(name);
}
- if (attributes != null) n.data.putAll(attributes);
+ if (attributes != null) n.data.putAll(injectNULLs(attributes));
nodes.put(name, n);
// we need to make sure parents get put in as well.
recursivelyPutParentsIfNeeded(name);
@@ -139,9 +201,9 @@
debugMessage("Removing data from " + fqn);
DummyNode n = nodes.get(fqn);
if (n == null) n = new DummyNode(fqn);
- Object old = n.data.remove(key);
+ Object old = n.data.remove(key == null ? NULL : key);
nodes.put(fqn, n);
- return old;
+ return old == NULL ? null : old;
}
public void remove(Fqn fqn) throws Exception
More information about the jboss-cvs-commits
mailing list