[jboss-cvs] JBossCache/src/org/jboss/cache ...
Manik Surtani
msurtani at jboss.com
Fri Jan 19 05:50:42 EST 2007
User: msurtani
Date: 07/01/19 05:50:42
Modified: src/org/jboss/cache Node.java UnversionedNode.java
Log:
API Changes
Revision Changes Path
1.58 +74 -23 JBossCache/src/org/jboss/cache/Node.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Node.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/Node.java,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -b -r1.57 -r1.58
--- Node.java 19 Jan 2007 02:04:10 -0000 1.57
+++ Node.java 19 Jan 2007 10:50:42 -0000 1.58
@@ -19,7 +19,7 @@
* different accounts simultaneously.
* Another is that when making changes to this Node, its data might be kept in a single
* database row or file on disk.
- * <p />
+ * <p/>
* A Node has references to its children, parent (each Node except the root has
* a single parent) and data contained within the Node (key-value pairs). The
* data access methods are similar to the collections {@link Map} interface,
@@ -41,30 +41,35 @@
/**
* Returns an immutable set of children nodes.
+ *
* @return an immutable {@link Set} of child nodes. Empty {@link Set} if there aren't any children.
*/
Set<Node> getChildren();
/**
* Returns an immutable set of children node names.
+ *
* @return an immutable {@link Set} of child node names. Empty {@link Set} if there aren't any children.
*/
Set<Object> getChildrenNames();
/**
* Returns a map containing the data in this {@link Node}.
+ *
* @return a {@link Map} containing the data in this {@link Node}. If there is no data, an empty {@link Map} is returned. The {@link Map} returned is always immutable.
*/
Map<Object, Object> getData();
/**
* Returns a {@link Set} containing the data in this {@link Node}.
+ *
* @return a {@link Set} containing the data in this {@link Node}. If there is no data, an empty {@link Set} is returned. The {@link Set} returned is always immutable.
*/
Set<Object> getKeys();
/**
* Returns the {@link Fqn} which represents the location of this {@link Node} in the cache structure. The {@link Fqn} returned is absolute.
+ *
* @return The {@link Fqn} which represents the location of this {@link Node} in the cache structure. The {@link Fqn} returned is absolute.
*/
Fqn getFqn();
@@ -123,42 +128,82 @@
Object put(Object key, Object value);
/**
- * If the specified key is not already associated with a value, associate it with the given value.
+ * If the specified key is not already associated with a value, associate it with the given value, and returns the
+ * Object (if any) that occupied the space, or null.
+ * <p/>
+ * Equivalent to calling
+ * <pre>
+ * if (!node.getKeys().contains(key))
+ * return node.putAll(key, value);
+ * else
+ * return node.get(key);
+ * </pre>
+ * <p/>
+ * except that this is atomic.
*
* @param key key with which the specified value is to be associated.
* @param value value to be associated with the specified key.
+ * @return previous value associated with specified key, or null if there was no mapping for key.
*/
- void putIfAbsent(Object key, Object value);
+ Object putIfAbsent(Object key, Object value);
/**
- * Copies all of the mappings from the specified map to this node's map.
- * If any data exists, existing keys are overwritten with the keys in the new map.
- * The behavior is equivalent to:
+ * Replace entry for key only if currently mapped to some value.
+ * Acts as
* <pre>
- * Node node;
- * for (Map.Entry me : map.entrySet())
- * node.put(me.getKey(), me.getValue());
+ * if ((node.getKeys().contains(key))
+ * {
+ * return node.putAll(key, value);
+ * }
+ * else
+ * return null;
+ * </pre>
+ * <p/>
+ * except that this is atomic.
+ *
+ * @param key key with which the specified value is associated.
+ * @param value value to be associated with the specified key.
+ * @return previous value associated with specified key, or <tt>null</tt>
+ * if there was no mapping for key.
+ */
+ Object replace(Object key, Object value);
+
+ /**
+ * Replace entry for key only if currently mapped to given value.
+ * Acts as
+ * <pre>
+ * if (node.get(key).equals(oldValue))
+ * {
+ * node.putAll(key, newValue);
+ * return true;
+ * }
+ * else
+ * return false;
* </pre>
+ * <p/>
+ * except that this is atomic.
*
- * @param map map to copy from
+ * @param key key with which the specified value is associated.
+ * @param oldValue value expected to be associated with the specified key.
+ * @param newValue value to be associated with the specified key.
+ * @return true if the value was replaced
*/
- void put(Map<Object, Object> map);
+ boolean replace(Object key, Object oldValue, Object newValue);
+
/**
* Copies all of the mappings from the specified map to this node's map.
- * If any data exists, existing
- * keys are not overwritten with the keys in the new map.
- * <p/>
+ * If any data exists, existing keys are overwritten with the keys in the new map.
* The behavior is equivalent to:
* <pre>
* Node node;
* for (Map.Entry me : map.entrySet())
- * node.put(me.getKey(), me.getValue());
+ * node.putAll(me.getKey(), me.getValue());
* </pre>
*
* @param map map to copy from
*/
- void putIfAbsent(Map<Object, Object> map);
+ void putAll(Map<Object, Object> map);
/**
* Returns the value to which this node maps the specified key.
@@ -186,7 +231,13 @@
void clearData();
/**
+ * @return the number of elements (key/value pairs) in the node's data map.
+ */
+ int dataSize();
+
+ /**
* Returns true if the child node denoted by the relative {@link Fqn} passed in exists.
+ *
* @param f {@link Fqn} relative to the current node of the child you are testing the existence of.
* @return true if the child node denoted by the relative {@link Fqn} passed in exists.
*/
1.21 +41 -5 JBossCache/src/org/jboss/cache/UnversionedNode.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: UnversionedNode.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/UnversionedNode.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -b -r1.20 -r1.21
--- UnversionedNode.java 17 Jan 2007 16:24:07 -0000 1.20
+++ UnversionedNode.java 19 Jan 2007 10:50:42 -0000 1.21
@@ -431,14 +431,45 @@
return getChild(f) != null;
}
- public void putIfAbsent(Object k, Object v)
+ public Object putIfAbsent(Object k, Object v)
{
- throw new UnsupportedOperationException("This operation was only added in 2.0.0 to finalise the API. This will not be implemented till 2.1.0.");
+ // make sure this is atomic. Not hugely performant at the moment (should use the locking interceptors) but for now ...
+ synchronized (this)
+ {
+ if (!getKeys().contains(k))
+ return put(k, v);
+ else
+ return get(k);
+ }
}
- public void putIfAbsent(Map m)
+ public Object replace(Object key, Object value)
+ {
+ // make sure this is atomic. Not hugely performant at the moment (should use the locking interceptors) but for now ...
+ synchronized (this)
+ {
+ if (getKeys().contains(key))
{
- throw new UnsupportedOperationException("This operation was only added in 2.0.0 to finalise the API. This will not be implemented till 2.1.0.");
+ return put(key, value);
+ }
+ else
+ return null;
+ }
+ }
+
+ public boolean replace(Object key, Object oldValue, Object newValue)
+ {
+ // make sure this is atomic. Not hugely performant at the moment (should use the locking interceptors) but for now ...
+ synchronized (this)
+ {
+ if (oldValue.equals(get(key)))
+ {
+ put(key, newValue);
+ return true;
+ }
+ else
+ return false;
+ }
}
public void removeChild(Fqn fqn)
@@ -446,6 +477,11 @@
cache.removeNode(new Fqn(getFqn(), fqn));
}
+ public int dataSize()
+ {
+ return getData().size();
+ }
+
public void removeChild(Object childName)
{
removeChild(new Fqn(getFqn(), childName));
@@ -480,7 +516,7 @@
this.children.putAll(children);
}
- public void put(Map data)
+ public void putAll(Map data)
{
cache.put(fqn, data);
}
More information about the jboss-cvs-commits
mailing list