private Map<String, Sone> remoteSones = new HashMap<String, Sone>();
/** All new Sones. */
- private Set<Sone> newSones = new HashSet<Sone>();
+ private Set<String> newSones = new HashSet<String>();
/** All known Sones. */
/* synchronize access on {@link #newSones}. */
- private Set<Sone> knownSones = new HashSet<Sone>();
+ private Set<String> knownSones = new HashSet<String>();
/** All posts. */
private Map<String, Post> posts = new HashMap<String, Post>();
}
/**
+ * Checks whether the core knows a Sone with the given ID.
+ *
+ * @param id
+ * The ID of the Sone
+ * @return {@code true} if there is a Sone with the given ID, {@code false}
+ * otherwise
+ */
+ public boolean hasSone(String id) {
+ return isLocalSone(id) || isRemoteSone(id);
+ }
+
+ /**
* Returns whether the given Sone is a local Sone.
*
* @param sone
*/
public boolean isNewSone(Sone sone) {
synchronized (newSones) {
- boolean isNew = !knownSones.contains(sone) && newSones.remove(sone);
- knownSones.add(sone);
+ boolean isNew = !knownSones.contains(sone.getId()) && newSones.remove(sone.getId());
+ knownSones.add(sone.getId());
return isNew;
}
}
sone.setLatestEdition(Numbers.safeParseLong(identity.getProperty("Sone.LatestEdition"), (long) 0));
if (newSone) {
synchronized (newSones) {
- newSones.add(sone);
+ newSones.add(sone.getId());
}
}
remoteSones.put(identity.getId(), sone);
}
/* load friends. */
- Set<Sone> friends = new HashSet<Sone>();
+ Set<String> friends = new HashSet<String>();
while (true) {
String friendId = configuration.getStringValue(sonePrefix + "/Friends/" + friends.size() + "/ID").getValue(null);
if (friendId == null) {
break;
}
- Boolean friendLocal = configuration.getBooleanValue(sonePrefix + "/Friends/" + friends.size() + "/Local").getValue(null);
- if (friendLocal == null) {
- logger.log(Level.WARNING, "Invalid friend found, aborting load!");
- return;
- }
- friends.add(friendLocal ? getLocalSone(friendId) : getRemoteSone(friendId));
+ friends.add(friendId);
}
/* if we’re still here, Sone was loaded successfully. */
sone.setModificationCounter(soneModificationCounter);
}
synchronized (newSones) {
- for (Sone friend : friends) {
+ for (String friend : friends) {
knownSones.add(friend);
}
}
/* 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);
+ for (String friend : sone.getFriends()) {
+ configuration.getStringValue(sonePrefix + "/Friends/" + friendCounter + "/ID").setValue(friend);
}
configuration.getStringValue(sonePrefix + "/Friends/" + friendCounter + "/ID").setValue(null);
break;
}
synchronized (newSones) {
- knownSones.add(getRemoteSone(knownSoneId));
+ knownSones.add(knownSoneId);
}
}
}
/* save known Sones. */
int soneCounter = 0;
synchronized (newSones) {
- for (Sone knownSone : knownSones) {
- configuration.getStringValue("KnownSone/" + soneCounter++ + "/ID").setValue(knownSone.getId());
+ for (String knownSoneId : knownSones) {
+ configuration.getStringValue("KnownSone/" + soneCounter++ + "/ID").setValue(knownSoneId);
}
configuration.getStringValue("KnownSone/" + soneCounter + "/ID").setValue(null);
}