2 * FreenetSone - Sone.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.Collections;
21 import java.util.HashSet;
23 import java.util.UUID;
25 import freenet.keys.FreenetURI;
28 * A Sone defines everything about a user: the {@link User} itself, her profile,
31 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
35 /** A GUID for this Sone. */
36 private final UUID id = UUID.randomUUID();
38 /** The name of this Sone. */
39 private final String name;
41 /** The URI under which the Sone is stored in Freenet. */
42 private final FreenetURI requestUri;
44 /** The URI used to insert a new version of this Sone. */
45 /* This will be null for remote Sones! */
46 private final FreenetURI insertUri;
48 /** All friend Sones. */
49 private final Set<Sone> friendSones = new HashSet<Sone>();
55 * The name of the Sone
57 * The request URI of the Sone
59 public Sone(String name, FreenetURI requestUri) {
60 this(name, requestUri, null);
67 * The name of the Sone
69 * The request URI of the Sone
71 * The insert URI of the Sone
73 public Sone(String name, FreenetURI requestUri, FreenetURI insertUri) {
75 this.requestUri = requestUri;
76 this.insertUri = insertUri;
84 * Returns the ID of this Sone.
86 * @return The ID of this Sone
88 public String getId() {
93 * Returns the name of this Sone.
95 * @return The name of this Sone
97 public String getName() {
102 * Returns the request URI of this Sone.
104 * @return The request URI of this Sone
106 public FreenetURI getRequestUri() {
111 * Returns the insert URI of this Sone.
113 * @return The insert URI of this Sone
115 public FreenetURI getInsertUri() {
120 * Returns all friend Sones of this Sone.
122 * @return The friend Sones of this Sone
124 public Set<Sone> getFriendSones() {
125 return Collections.unmodifiableSet(friendSones);
129 * Returns whether this Sone has the given Sone as a friend Sone.
132 * The friend Sone to check for
133 * @return {@code true} if this Sone has the given Sone as a friend,
134 * {@code false} otherwise
136 public boolean hasFriendSone(Sone friendSone) {
137 return friendSones.contains(friendSone);
141 * Adds the given Sone as a friend Sone.
144 * The friend Sone to add
145 * @return This Sone (for method chaining)
147 public Sone addFriendSone(Sone friendSone) {
148 friendSones.add(friendSone);
153 * Removes the given Sone as a friend Sone.
156 * The friend Sone to remove
157 * @return This Sone (for method chaining)
159 public Sone removeFriendSone(Sone friendSone) {
160 friendSones.remove(friendSone);
172 public int hashCode() {
173 return id.hashCode();