2 * Sone - Identity.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.freenet.wot;
20 import java.util.Collections;
21 import java.util.HashMap;
22 import java.util.HashSet;
27 * A Web of Trust identity.
29 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
31 public class Identity {
33 /** The ID of the identity. */
34 private final String id;
36 /** The nickname of the identity. */
37 private final String nickname;
39 /** The request URI of the identity. */
40 private final String requestUri;
42 /** The contexts of the identity. */
43 protected final Set<String> contexts = Collections.synchronizedSet(new HashSet<String>());
45 /** The properties of the identity. */
46 private final Map<String, String> properties = Collections.synchronizedMap(new HashMap<String, String>());
49 * Creates a new identity.
52 * The ID of the identity
54 * The nickname of the identity
56 * The request URI of the identity
58 public Identity(String id, String nickname, String requestUri) {
60 this.nickname = nickname;
61 this.requestUri = requestUri;
69 * Returns the ID of the identity.
71 * @return The ID of the identity
73 public String getId() {
78 * Returns the nickname of the identity.
80 * @return The nickname of the identity
82 public String getNickname() {
87 * Returns the request URI of the identity.
89 * @return The request URI of the identity
91 public String getRequestUri() {
96 * Returns the contexts of the identity.
98 * @return The contexts of the identity
100 public Set<String> getContexts() {
101 return Collections.unmodifiableSet(contexts);
105 * Returns whether the identity contains the given context.
108 * The context to check for
109 * @return {@code true} if this identity has the given context,
110 * {@code false} otherwise
112 public boolean hasContext(String context) {
113 return contexts.contains(context);
117 * Returns the properties of the identity.
119 * @return The properties of the identity
121 public Map<String, String> getProperties() {
122 return Collections.unmodifiableMap(properties);
126 * Returns the value of the property with the given name.
129 * The name of the property
130 * @return The value of the property, or {@code null} if there is no such
133 public String getProperty(String name) {
134 return properties.get(name);
138 * Sets the property with the given name to the given value.
141 * The name of the property to set
143 * The new value of the property
145 public void setProperty(String name, String value) {
146 properties.put(name, value);
147 /* TODO - set property. */
151 * Removes the property with the given name.
154 * The name of the property to remove
156 public void removeProperty(String name) {
157 properties.remove(name);
158 /* TODO - remove property. */
169 public int hashCode() {
170 return id.hashCode();
177 public boolean equals(Object object) {
178 if (!(object instanceof Identity)) {
181 Identity identity = (Identity) object;
182 return identity.id.equals(id);