/* synchronize access on this on itself. */
private Map<String, Sone> remoteSones = new HashMap<String, Sone>();
- /** All new Sones. */
- private Set<String> newSones = new HashSet<String>();
-
/** All known Sones. */
- /* synchronize access on {@link #newSones}. */
private Set<String> knownSones = new HashSet<String>();
/** All posts. */
}
/**
- * Returns whether the Sone with the given ID is a new Sone.
- *
- * @param soneId
- * The ID of the sone to check for
- * @return {@code true} if the given Sone is new, false otherwise
- */
- public boolean isNewSone(String soneId) {
- synchronized (newSones) {
- return !knownSones.contains(soneId) && newSones.contains(soneId);
- }
- }
-
- /**
* Returns whether the given Sone has been modified.
*
* @param sone
sone.setRequestUri(getSoneUri(identity.getRequestUri()));
sone.setLatestEdition(Numbers.safeParseLong(identity.getProperty("Sone.LatestEdition"), (long) 0));
if (newSone) {
- synchronized (newSones) {
+ synchronized (knownSones) {
newSone = !knownSones.contains(sone.getId());
- if (newSone) {
- newSones.add(sone.getId());
- }
}
+ sone.setKnown(!newSone);
if (newSone) {
coreListenerManager.fireNewSoneFound(sone);
for (Sone localSone : getLocalSones()) {
* The Sone to mark as known
*/
public void markSoneKnown(Sone sone) {
- synchronized (newSones) {
- if (newSones.remove(sone.getId())) {
+ if (!sone.isKnown()) {
+ sone.setKnown(true);
+ synchronized (knownSones) {
knownSones.add(sone.getId());
- coreListenerManager.fireMarkSoneKnown(sone);
- touchConfiguration();
}
+ coreListenerManager.fireMarkSoneKnown(sone);
+ touchConfiguration();
}
}
sone.setAlbums(topLevelAlbums);
soneInserters.get(sone).setLastInsertFingerprint(lastInsertFingerprint);
}
- synchronized (newSones) {
+ synchronized (knownSones) {
for (String friend : friends) {
knownSones.add(friend);
}
/* save known Sones. */
int soneCounter = 0;
- synchronized (newSones) {
+ synchronized (knownSones) {
for (String knownSoneId : knownSones) {
configuration.getStringValue("KnownSone/" + soneCounter++ + "/ID").setValue(knownSoneId);
}
if (knownSoneId == null) {
break;
}
- synchronized (newSones) {
+ synchronized (knownSones) {
knownSones.add(knownSoneId);
}
}
synchronized (remoteSones) {
remoteSones.remove(identity.getId());
}
- synchronized (newSones) {
- newSones.remove(identity.getId());
- coreListenerManager.fireSoneRemoved(sone);
- }
+ coreListenerManager.fireSoneRemoved(sone);
}
//
/** The client used by the Sone. */
private volatile Client client;
+ /** Whether this Sone is known. */
+ private volatile boolean known;
+
/** All friend Sones. */
private final Set<String> friendSones = new CopyOnWriteArraySet<String>();
}
/**
+ * Returns whether this Sone is known.
+ *
+ * @return {@code true} if this Sone is known, {@code false} otherwise
+ */
+ public boolean isKnown() {
+ return known;
+ }
+
+ /**
+ * Sets whether this Sone is known.
+ *
+ * @param known
+ * {@code true} if this Sone is known, {@code false} otherwise
+ * @return This Sone
+ */
+ public Sone setKnown(boolean known) {
+ this.known = known;
+ return this;
+ }
+
+ /**
* Returns all friend Sones of this Sone.
*
* @return The friend Sones of this Sone