* Sone
*/
public Sone getSone(String id) {
- Sone sone = getRemoteSone(id);
- if (sone != null) {
- return sone;
+ if (isLocalSone(id)) {
+ return getLocalSone(id);
}
- sone = getLocalSone(id);
- return sone;
+ return getRemoteSone(id);
}
/**
}
/**
+ * Returns whether the given ID is the ID of a local Sone.
+ *
+ * @param id
+ * The Sone ID to check for its locality
+ * @return {@code true} if the given ID is a local Sone, {@code false}
+ * otherwise
+ */
+ public boolean isLocalSone(String id) {
+ synchronized (localSones) {
+ return localSones.containsKey(id);
+ }
+ }
+
+ /**
* Returns all local Sones.
*
* @return All local Sones
*
* @param id
* The ID of the Sone to get
- * @return The Sone, or {@code null} if there is no Sone with the given ID
+ * @return The Sone with the given ID
*/
public Sone getLocalSone(String id) {
synchronized (localSones) {
- return localSones.get(id);
+ Sone sone = localSones.get(id);
+ if (sone == null) {
+ sone = new Sone(id);
+ localSones.put(id, sone);
+ }
+ return sone;
}
}
*
* @param id
* The ID of the remote Sone to get
- * @return The Sone, or {@code null} if there is no such Sone
+ * @return The Sone with the given ID
*/
public Sone getRemoteSone(String id) {
synchronized (remoteSones) {
- return remoteSones.get(id);
+ Sone sone = remoteSones.get(id);
+ if (sone == null) {
+ sone = new Sone(id);
+ remoteSones.put(id, sone);
+ }
+ return sone;
}
}
*/
public Post getPost(String postId) {
synchronized (posts) {
- return posts.get(postId);
+ Post post = posts.get(postId);
+ if (post == null) {
+ post = new Post(postId);
+ posts.put(postId, post);
+ }
+ return post;
}
}
*/
public Reply getReply(String replyId) {
synchronized (replies) {
- return replies.get(replyId);
+ Reply reply = replies.get(replyId);
+ if (reply == null) {
+ reply = new Reply(replyId);
+ replies.put(replyId, reply);
+ }
+ return reply;
}
}
}
final Sone sone;
try {
- sone = new Sone(ownIdentity).setInsertUri(new FreenetURI(ownIdentity.getInsertUri())).setRequestUri(new FreenetURI(ownIdentity.getRequestUri()));
+ sone = getLocalSone(ownIdentity.getId()).setIdentity(ownIdentity).setInsertUri(new FreenetURI(ownIdentity.getInsertUri())).setRequestUri(new FreenetURI(ownIdentity.getRequestUri()));
sone.setLatestEdition(Numbers.safeParseLong(ownIdentity.getProperty("Sone.LatestEdition"), (long) 0));
} catch (MalformedURLException mue1) {
logger.log(Level.SEVERE, "Could not convert the Identity’s URIs to Freenet URIs: " + ownIdentity.getInsertUri() + ", " + ownIdentity.getRequestUri(), mue1);
}
configuration.getStringValue(sonePrefix + "/Likes/Reply/" + replyLikeCounter + "/ID").setValue(null);
+ /* save friends. */
+ int friendCounter = 0;
+ for (Sone friend : sone.getFriends()) {
+ configuration.getStringValue(sonePrefix + "/Friends/" + friendCounter + "/ID").setValue(friend.getId());
+ configuration.getBooleanValue(sonePrefix + "/Friends/" + friendCounter++ + "/Local").setValue(friend.getInsertUri() != null);
+ }
+ configuration.getStringValue(sonePrefix + "/Friends/" + friendCounter + "/ID").setValue(null);
+
logger.log(Level.INFO, "Sone %s saved.", sone);
} catch (ConfigurationException ce1) {
logger.log(Level.WARNING, "Could not save Sone: " + sone, ce1);