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;
23 * A Web of Trust identity.
25 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
27 public class Identity {
29 /** The Web of Trust connector. */
30 protected final WebOfTrustConnector webOfTrustConnector;
32 /** The ID of the identity. */
33 private final String id;
35 /** The nickname of the identity. */
36 private final String nickname;
38 /** The request URI of the identity. */
39 private final String requestUri;
42 * Creates a new identity.
44 * @param webOfTrustConnector
45 * The Web of Trust connector
47 * The ID of the identity
49 * The nickname of the identity
51 * The request URI of the identity
53 public Identity(WebOfTrustConnector webOfTrustConnector, String id, String nickname, String requestUri) {
54 this.webOfTrustConnector = webOfTrustConnector;
56 this.nickname = nickname;
57 this.requestUri = requestUri;
65 * Returns the ID of the identity.
67 * @return The ID of the identity
69 public String getId() {
74 * Returns the nickname of the identity.
76 * @return The nickname of the identity
78 public String getNickname() {
83 * Returns the request URI of the identity.
85 * @return The request URI of the identity
87 public String getRequestUri() {
92 * Returns the contexts of the identity. If the contexts have not been
93 * loaded yet, they will be loaded. If loading the contexts fails, an empty
96 * @return The contexts of the identity
97 * @throws PluginException
98 * if an error occured communicating with the Web of Trust
101 public Set<String> getContexts() throws PluginException {
102 return webOfTrustConnector.loadIdentityContexts(this);
106 * Returns whether the identity contains the given context.
109 * The context to check for
110 * @return {@code true} if this identity has the given context,
111 * {@code false} otherwise
112 * @throws PluginException
113 * if an error occured communicating with the Web of Trust
116 public boolean hasContext(String context) throws PluginException {
117 return getContexts().contains(context);
121 * Returns the value of the property with the given name.
124 * The name of the property
125 * @return The value of the property, or {@code null} if there is no such
127 * @throws PluginException
128 * if an error occured communicating with the Web of Trust
131 public String getProperty(String name) throws PluginException {
132 return webOfTrustConnector.getProperty(this, name);
143 public int hashCode() {
144 return id.hashCode();
151 public boolean equals(Object object) {
152 if (!(object instanceof Identity)) {
155 Identity identity = (Identity) object;
156 return identity.id.equals(id);