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 /** The shell creator. */
37 public static final ShellCreator<Sone> creator = new ShellCreator<Sone>() {
40 public Shell<Sone> createShell(String id) {
41 return new SoneShell().setId(UUID.fromString(id));
45 /** A GUID for this Sone. */
48 /** The name of this Sone. */
51 /** The URI under which the Sone is stored in Freenet. */
52 private FreenetURI requestUri;
54 /** The profile of this Sone. */
55 private Profile profile;
57 /** All friend Sones. */
58 private final Set<Sone> friendSones = new HashSet<Sone>();
61 private final List<Post> posts = new ArrayList<Post>();
64 private final Set<Reply> replies = new HashSet<Reply>();
67 * Creates a new Sone shell.
70 super(null, null, null);
78 * Returns the ID of this Sone.
80 * @return The ID of this Sone
83 public String getId() {
88 * Sets the ID of the Sone.
92 * @return This Sone shell (for method chaining)
94 public SoneShell setId(UUID id) {
100 * Returns the name of this Sone.
102 * @return The name of this Sone
105 public String getName() {
110 * Sets the name of the Sone.
113 * The name of the Sone
114 * @return This Sone shell (for method chaining)
116 public SoneShell setName(String name) {
122 * Returns the request URI of this Sone.
124 * @return The request URI of this Sone
127 public FreenetURI getRequestUri() {
132 * Sets the request URI of the Sone.
135 * The request URI of the Sone
136 * @return This Sone shell (for method chaining)
138 public SoneShell setRequestUri(FreenetURI requestUri) {
139 this.requestUri = requestUri;
144 * Returns a copy of the profile. If you want to update values in the
145 * profile of this Sone, update the values in the returned {@link Profile}
146 * and use {@link #setProfile(Profile)} to change the profile in this Sone.
148 * @return A copy of the profile
151 public Profile getProfile() {
152 return new Profile(profile);
159 public void setProfile(Profile profile) {
160 this.profile = profile;
164 * Returns all friend Sones of this Sone.
166 * @return The friend Sones of this Sone
169 public Set<Sone> getFriendSones() {
170 return Collections.unmodifiableSet(friendSones);
174 * Returns whether this Sone has the given Sone as a friend Sone.
177 * The friend Sone to check for
178 * @return {@code true} if this Sone has the given Sone as a friend,
179 * {@code false} otherwise
182 public boolean hasFriendSone(Sone friendSone) {
183 return friendSones.contains(friendSone);
187 * Adds the given Sone as a friend Sone.
190 * The friend Sone to add
191 * @return This Sone (for method chaining)
194 public Sone addFriendSone(Sone friendSone) {
195 friendSones.add(friendSone);
200 * Removes the given Sone as a friend Sone.
203 * The friend Sone to remove
204 * @return This Sone (for method chaining)
207 public Sone removeFriendSone(Sone friendSone) {
208 friendSones.remove(friendSone);
213 * Returns the list of posts of this Sone.
215 * @return All posts of this Sone
218 public List<Post> getPosts() {
219 return Collections.unmodifiableList(posts);
223 * Adds the given post to this Sone. The post will not be added if its
224 * {@link Post#getSone() Sone} is not this Sone.
230 public void addPost(Post post) {
235 * Removes the given post from this Sone.
241 public void removePost(Post post) {
246 * Returns all replies this Sone made.
248 * @return All replies this Sone made
251 public Set<Reply> getReplies() {
252 return Collections.unmodifiableSet(replies);
256 * Adds a reply to this Sone. If the given reply was not made by this Sone,
257 * nothing is added to this Sone.
263 public void addReply(Reply reply) {
268 * Removes a reply from this Sone.
271 * The reply to remove
274 public void removeReply(Reply reply) {
275 replies.remove(reply);
286 public boolean canUnshell() {
287 return (id != null) && (name != null) && (requestUri != null) && (profile != null);
294 public Sone getShelled() {
296 Sone sone = new Sone(id, name, requestUri);
297 sone.setProfile(profile);
298 for (Sone friendSone : friendSones) {
299 sone.addFriendSone(friendSone);
301 for (Post post : posts) {
304 for (Reply reply : replies) {
305 sone.addReply(reply);