X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FSone.java;h=bb36a9cec9558978c5bbd76a9c3825252f15bc47;hb=87386f93e655178eed6024babd50bf236ab882ff;hp=4a73470982eccfb9deabf61f553e5d1e48584cd0;hpb=8b9c6e55b8509e4651ceca3b052f201739623213;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/data/Sone.java b/src/main/java/net/pterodactylus/sone/data/Sone.java index 4a73470..bb36a9c 100644 --- a/src/main/java/net/pterodactylus/sone/data/Sone.java +++ b/src/main/java/net/pterodactylus/sone/data/Sone.java @@ -48,6 +48,9 @@ public class Sone { /** All friend Sones. */ private final Set friendSones = new HashSet(); + /** Modification count. */ + private volatile long modificationCounter = 0; + /** * Creates a new Sone. * @@ -149,8 +152,10 @@ public class Sone { * The friend Sone to add * @return This Sone (for method chaining) */ - public Sone addFriendSone(Sone friendSone) { - friendSones.add(friendSone); + public synchronized Sone addFriendSone(Sone friendSone) { + if (friendSones.add(friendSone)) { + modificationCounter++; + } return this; } @@ -161,11 +166,32 @@ public class Sone { * The friend Sone to remove * @return This Sone (for method chaining) */ - public Sone removeFriendSone(Sone friendSone) { - friendSones.remove(friendSone); + public synchronized Sone removeFriendSone(Sone friendSone) { + if (friendSones.remove(friendSone)) { + modificationCounter++; + } return this; } + /** + * Returns the modification counter. + * + * @return The modification counter + */ + public synchronized long getModificationCounter() { + return modificationCounter; + } + + /** + * Sets the modification counter. + * + * @param modificationCounter + * The new modification counter + */ + public synchronized void setModificationCounter(long modificationCounter) { + this.modificationCounter = modificationCounter; + } + // // OBJECT METHODS //