Author: batosai
Date: 2008-09-07 14:09:06 +0000 (Sun, 07 Sep 2008)
New Revision: 22527
Modified:
trunk/plugins/WoT/src/plugins/WoT/Identity.java
trunk/plugins/WoT/src/plugins/WoT/IdentityTest.java
Log:
Stupid me ! Not sure switching to Strings was necessary now. But Toad suggested
it and it's done so...
Modified: trunk/plugins/WoT/src/plugins/WoT/Identity.java
===================================================================
--- trunk/plugins/WoT/src/plugins/WoT/Identity.java 2008-09-07 13:51:05 UTC
(rev 22526)
+++ trunk/plugins/WoT/src/plugins/WoT/Identity.java 2008-09-07 14:09:06 UTC
(rev 22527)
@@ -39,7 +39,7 @@
}; // Identities with negative score have zero
capacity
@SuppressWarnings("unused")
- private ByteArrayWrapper id;
+ private String id;
private FreenetURI requestURI;
private Date lastChange;
@@ -57,7 +57,7 @@
props = new HashMap<String, String>();
contexts = new ArrayList<String>();
contexts.add(context);
- id = new ByteArrayWrapper(getRequestURI().getRoutingKey());
+ id = getIdFromURI(getRequestURI());
}
public Identity (String requestURI, String nickName, String
publishTrustList, String context) throws InvalidParameterException,
MalformedURLException {
@@ -67,7 +67,7 @@
@SuppressWarnings("unchecked")
- public static Identity getById (ObjectContainer db, ByteArrayWrapper
id) throws DuplicateIdentityException, UnknownIdentityException {
+ private static Identity getById (ObjectContainer db, String id) throws
DuplicateIdentityException, UnknownIdentityException {
Query query = db.query();
query.constrain(Identity.class);
@@ -84,7 +84,7 @@
}
public static Identity getByURI (ObjectContainer db, FreenetURI uri)
throws UnknownIdentityException, DuplicateIdentityException {
- return getById(db, new ByteArrayWrapper(uri.getRoutingKey()));
+ return getById(db, getIdFromURI(uri));
}
public static int getNbIdentities(ObjectContainer db) {
@@ -95,6 +95,12 @@
return db.queryByExample(Identity.class);
}
+ private static String getIdFromURI (FreenetURI uri) {
+ int begin = uri.toString().indexOf(',') + 1;
+ int end = uri.toString().indexOf(',', begin);
+ return uri.toString().substring(begin, end);
+ }
+
@SuppressWarnings("unchecked")
@@ -359,6 +365,4 @@
public boolean hasContext(String context) {
return contexts.contains(context.trim());
}
-
-
}
Modified: trunk/plugins/WoT/src/plugins/WoT/IdentityTest.java
===================================================================
--- trunk/plugins/WoT/src/plugins/WoT/IdentityTest.java 2008-09-07 13:51:05 UTC
(rev 22526)
+++ trunk/plugins/WoT/src/plugins/WoT/IdentityTest.java 2008-09-07 14:09:06 UTC
(rev 22527)
@@ -49,6 +49,10 @@
public void testGetByURI() throws MalformedURLException,
UnknownIdentityException, DuplicateIdentityException {
assertNotNull(Identity.getByURI(db, uri));
}
+
+ public void testGetNbIdentities() {
+ assertEquals(Identity.getNbIdentities(db), 1);
+ }
public void testContexts() throws InvalidParameterException {
assertFalse(identity.hasContext("foo"));
@@ -77,11 +81,16 @@
} catch (InvalidParameterException e) {}
}
- public void testPersistence() throws MalformedURLException,
UnknownIdentityException, DuplicateIdentityException {
+ public void testPersistence() throws MalformedURLException,
DuplicateIdentityException {
db.close();
System.gc();
- db = Db4o.openFile("scoreTest.db4o");
+ db = Db4o.openFile("identityTest.db4o");
- assertNotNull(Identity.getByURI(db, uri));
+ assertEquals(Identity.getNbIdentities(db), 1);
+ try {
+ Identity.getByURI(db, uri);
+ } catch (UnknownIdentityException e) {
+ fail();
+ }
}
}