[jbosscache-commits] JBoss Cache SVN: r5631 - in core/trunk/src: test/java/org/jboss/cache and 1 other directory.
jbosscache-commits at lists.jboss.org
jbosscache-commits at lists.jboss.org
Tue Apr 22 14:33:28 EDT 2008
Author: manik.surtani at jboss.com
Date: 2008-04-22 14:33:28 -0400 (Tue, 22 Apr 2008)
New Revision: 5631
Modified:
core/trunk/src/main/java/org/jboss/cache/Fqn.java
core/trunk/src/main/java/org/jboss/cache/StringFqn.java
core/trunk/src/test/java/org/jboss/cache/FqnTest.java
Log:
Cache loader fixes
Modified: core/trunk/src/main/java/org/jboss/cache/Fqn.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/Fqn.java 2008-04-22 17:35:55 UTC (rev 5630)
+++ core/trunk/src/main/java/org/jboss/cache/Fqn.java 2008-04-22 18:33:28 UTC (rev 5631)
@@ -125,8 +125,11 @@
{
// if not safe make a defensive copy
elements = safe ? names : new ArrayList(names);
- if (elements.get(0).equals(SEPARATOR)) elements.remove(0);
- if (elements.get(0).equals("")) elements.remove(0);
+ if (elements.size() > 0)
+ {
+ if (SEPARATOR.equals(elements.get(0))) elements.remove(0);
+ if ("".equals(elements.get(0))) elements.remove(0);
+ }
size = elements.size();
}
else
@@ -509,19 +512,7 @@
{
if (stringRepresentation == null)
{
- if (isRoot())
- {
- stringRepresentation = SEPARATOR;
- }
- else
- {
- StringBuilder sb = new StringBuilder();
- for (E element : elements)
- {
- sb.append(SEPARATOR).append(element);
- }
- stringRepresentation = sb.toString();
- }
+ stringRepresentation = getStringRepresentation(elements);
}
return stringRepresentation;
}
@@ -545,6 +536,8 @@
E e = (E) in.readObject();
elements.add(e);
}
+
+ if (getClass().equals(StringFqn.class)) stringRepresentation = getStringRepresentation(elements);
}
@@ -605,6 +598,11 @@
*/
protected int calculateHashCode()
{
+ if (containsStrings(elements))
+ {
+ if (stringRepresentation == null) stringRepresentation = getStringRepresentation(elements);
+ return stringRepresentation.hashCode();
+ }
int hashCode = 0;
int count = 1;
Object o;
@@ -620,6 +618,21 @@
return hashCode;
}
+ protected String getStringRepresentation(List elements)
+ {
+ StringBuilder builder = new StringBuilder();
+ for (Object e : elements)
+ {
+ if (!e.equals(SEPARATOR) && !e.equals(""))
+ {
+ builder.append(SEPARATOR);
+ builder.append(e);
+ }
+ }
+ return builder.toString();
+ }
+
+
/**
* Returns the parent of this Fqn.
* The parent of the root node is {@link #ROOT}.
Modified: core/trunk/src/main/java/org/jboss/cache/StringFqn.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/StringFqn.java 2008-04-22 17:35:55 UTC (rev 5630)
+++ core/trunk/src/main/java/org/jboss/cache/StringFqn.java 2008-04-22 18:33:28 UTC (rev 5631)
@@ -50,21 +50,6 @@
this(Arrays.asList(stringRep.split("/")));
}
- private String getStringRepresentation(List<String> elements)
- {
- StringBuilder builder = new StringBuilder();
- for (String e : elements)
- {
- if (!e.equals(SEPARATOR) && !e.equals(""))
- {
- builder.append(SEPARATOR);
- // escape special chars.
- builder.append(e);
- }
- }
- return builder.toString();
- }
-
@Override
public boolean equals(Object other)
{
Modified: core/trunk/src/test/java/org/jboss/cache/FqnTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/FqnTest.java 2008-04-22 17:35:55 UTC (rev 5630)
+++ core/trunk/src/test/java/org/jboss/cache/FqnTest.java 2008-04-22 18:33:28 UTC (rev 5631)
@@ -18,6 +18,7 @@
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
+import java.util.Arrays;
import java.util.HashMap;
/**
@@ -447,6 +448,30 @@
System.out.println("-- " + msg);
}
+ public void testDifferentFactories()
+ {
+ Fqn[] fqns = new Fqn[7];
+ int i = 0;
+ fqns[i++] = Fqn.fromString("/a/b/c");
+ fqns[i++] = Fqn.fromRelativeElements(Fqn.ROOT, "a", "b", "c");
+ fqns[i++] = Fqn.fromElements("a", "b", "c");
+ fqns[i++] = Fqn.fromList(Arrays.asList(new String[]{"a", "b", "c"}));
+ fqns[i++] = Fqn.fromRelativeList(Fqn.ROOT, Arrays.asList(new String[]{"a", "b", "c"}));
+ fqns[i++] = Fqn.fromRelativeFqn(Fqn.ROOT, Fqn.fromString("/a/b/c"));
+ fqns[i] = new Fqn("a", "b", "c"); // "old-style" Fqn
+
+ // all of the above should be equal to each other.
+ for (i = 0; i < fqns.length; i++)
+ {
+ for (int j = 0; j < fqns.length; j++)
+ {
+ assert fqns[i].equals(fqns[j]) : "Error on equals comparing " + i + " and " + j;
+ assert fqns[j].equals(fqns[i]) : "Error on equals comparing " + i + " and " + j;
+ assert fqns[i].hashCode() == fqns[j].hashCode() : "Error on hashcode comparing " + i + " and " + j;
+ }
+ }
+ }
+
@Test(enabled = false)
// TODO enable once String escaping is in place
public void testUnescapedString()
More information about the jbosscache-commits
mailing list