X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FSone.java;h=a40b12e756ca72cdc69c244852668802572b07c5;hb=ec41f5f45fe6f31bfec77ca9b41c9bf60bfcd5dc;hp=62741e785c5a569a6ec1809e06901c843946805a;hpb=13540271116aaa7b350d283ce8a8b97fce7e8123;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 62741e7..a40b12e 100644 --- a/src/main/java/net/pterodactylus/sone/data/Sone.java +++ b/src/main/java/net/pterodactylus/sone/data/Sone.java @@ -17,8 +17,10 @@ package net.pterodactylus.sone.data; +import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; +import java.util.List; import java.util.Set; import java.util.UUID; @@ -53,6 +55,9 @@ public class Sone { /** All friend Sones. */ private final Set friendSones = new HashSet(); + /** All posts. */ + private final List posts = new ArrayList(); + /** Modification count. */ private volatile long modificationCounter = 0; @@ -141,13 +146,15 @@ public class Sone { } /** - * Sets the profile of this Sone. + * Sets the profile of this Sone. A copy of the given profile is stored so + * that subsequent modifications of the given profile are not reflected in + * this Sone! * * @param profile * The profile to set */ public synchronized void setProfile(Profile profile) { - this.profile = profile; + this.profile = new Profile(profile); modificationCounter++; } @@ -201,6 +208,40 @@ public class Sone { } /** + * Returns the list of posts of this Sone. + * + * @return All posts of this Sone + */ + public List getPosts() { + return Collections.unmodifiableList(posts); + } + + /** + * Adds a post with the given text to this Sone. + * + * @param text + * The text to post + */ + public synchronized void addPost(String text) { + Post post = new Post(this, System.currentTimeMillis(), text); + if (posts.add(post)) { + modificationCounter++; + } + } + + /** + * Removes the given post from this Sone. + * + * @param post + * The post to remove + */ + public synchronized void removePost(Post post) { + if (post.getSone().equals(this) && posts.remove(post)) { + modificationCounter++; + } + } + + /** * Returns the modification counter. * * @return The modification counter