2 * Sone - SoneShell.java - Copyright © 2010 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.sone.data;
20 import java.util.ArrayList;
21 import java.util.Collections;
22 import java.util.HashSet;
23 import java.util.List;
25 import java.util.UUID;
27 import freenet.keys.FreenetURI;
30 * {@link Shell} around a {@link Sone} that has not yet been retrieved.
32 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
34 public class SoneShell extends Sone implements Shell<Sone> {
36 /** A GUID for this Sone. */
39 /** The name of this Sone. */
42 /** The URI under which the Sone is stored in Freenet. */
43 private FreenetURI requestUri;
45 /** The profile of this Sone. */
46 private Profile profile;
48 /** All friend Sones. */
49 private final Set<Sone> friendSones = new HashSet<Sone>();
52 private final List<Post> posts = new ArrayList<Post>();
55 private final Set<Reply> replies = new HashSet<Reply>();
58 * Creates a new Sone shell.
61 super(null, null, null);
69 * Returns the ID of this Sone.
71 * @return The ID of this Sone
74 public String getId() {
79 * Sets the ID of the Sone.
83 * @return This Sone shell (for method chaining)
85 public SoneShell setId(UUID id) {
91 * Returns the name of this Sone.
93 * @return The name of this Sone
96 public String getName() {
101 * Sets the name of the Sone.
104 * The name of the Sone
105 * @return This Sone shell (for method chaining)
107 public SoneShell setName(String name) {
113 * Returns the request URI of this Sone.
115 * @return The request URI of this Sone
118 public FreenetURI getRequestUri() {
123 * Sets the request URI of the Sone.
126 * The request URI of the Sone
127 * @return This Sone shell (for method chaining)
129 public SoneShell setRequestUri(FreenetURI requestUri) {
130 this.requestUri = requestUri;
135 * Returns a copy of the profile. If you want to update values in the
136 * profile of this Sone, update the values in the returned {@link Profile}
137 * and use {@link #setProfile(Profile)} to change the profile in this Sone.
139 * @return A copy of the profile
142 public Profile getProfile() {
143 return new Profile(profile);
150 public void setProfile(Profile profile) {
151 this.profile = profile;
155 * Returns all friend Sones of this Sone.
157 * @return The friend Sones of this Sone
160 public Set<Sone> getFriendSones() {
161 return Collections.unmodifiableSet(friendSones);
165 * Returns whether this Sone has the given Sone as a friend Sone.
168 * The friend Sone to check for
169 * @return {@code true} if this Sone has the given Sone as a friend,
170 * {@code false} otherwise
173 public boolean hasFriendSone(Sone friendSone) {
174 return friendSones.contains(friendSone);
178 * Adds the given Sone as a friend Sone.
181 * The friend Sone to add
182 * @return This Sone (for method chaining)
185 public Sone addFriendSone(Sone friendSone) {
186 friendSones.add(friendSone);
191 * Removes the given Sone as a friend Sone.
194 * The friend Sone to remove
195 * @return This Sone (for method chaining)
198 public Sone removeFriendSone(Sone friendSone) {
199 friendSones.remove(friendSone);
204 * Returns the list of posts of this Sone.
206 * @return All posts of this Sone
209 public List<Post> getPosts() {
210 return Collections.unmodifiableList(posts);
214 * Adds the given post to this Sone. The post will not be added if its
215 * {@link Post#getSone() Sone} is not this Sone.
221 public void addPost(Post post) {
226 * Removes the given post from this Sone.
232 public void removePost(Post post) {
237 * Returns all replies this Sone made.
239 * @return All replies this Sone made
242 public Set<Reply> getReplies() {
243 return Collections.unmodifiableSet(replies);
247 * Adds a reply to this Sone. If the given reply was not made by this Sone,
248 * nothing is added to this Sone.
254 public void addReply(Reply reply) {
259 * Removes a reply from this Sone.
262 * The reply to remove
265 public void removeReply(Reply reply) {
266 replies.remove(reply);
277 public boolean canUnshell() {
278 return (id != null) && (name != null) && (requestUri != null) && (profile != null);
285 public Sone getShelled() {
287 Sone sone = new Sone(id, name, requestUri);
288 sone.setProfile(profile);
289 for (Sone friendSone : friendSones) {
290 sone.addFriendSone(friendSone);
292 for (Post post : posts) {
295 for (Reply reply : replies) {
296 sone.addReply(reply);