Add stub of Web of Trust plugin connector.
[Sone.git] / src / main / java / net / pterodactylus / sone / freenet / wot / Identity.java
1 /*
2  * Sone - Identity.java - Copyright © 2010 David Roden
3  *
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.
8  *
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.
13  *
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/>.
16  */
17
18 package net.pterodactylus.sone.freenet.wot;
19
20 import java.util.Collections;
21 import java.util.HashMap;
22 import java.util.HashSet;
23 import java.util.Map;
24 import java.util.Set;
25
26 /**
27  * A Web of Trust identity.
28  *
29  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
30  */
31 public class Identity {
32
33         /** The ID of the identity. */
34         private final String id;
35
36         /** The nickname of the identity. */
37         private final String nickname;
38
39         /** The request URI of the identity. */
40         private final String requestUri;
41
42         /** The contexts of the identity. */
43         protected final Set<String> contexts = Collections.synchronizedSet(new HashSet<String>());
44
45         /** The properties of the identity. */
46         private final Map<String, String> properties = Collections.synchronizedMap(new HashMap<String, String>());
47
48         /**
49          * Creates a new identity.
50          *
51          * @param id
52          *            The ID of the identity
53          * @param nickname
54          *            The nickname of the identity
55          * @param requestUri
56          *            The request URI of the identity
57          */
58         public Identity(String id, String nickname, String requestUri) {
59                 this.id = id;
60                 this.nickname = nickname;
61                 this.requestUri = requestUri;
62         }
63
64         //
65         // ACCESSORS
66         //
67
68         /**
69          * Returns the ID of the identity.
70          *
71          * @return The ID of the identity
72          */
73         public String getId() {
74                 return id;
75         }
76
77         /**
78          * Returns the nickname of the identity.
79          *
80          * @return The nickname of the identity
81          */
82         public String getNickname() {
83                 return nickname;
84         }
85
86         /**
87          * Returns the request URI of the identity.
88          *
89          * @return The request URI of the identity
90          */
91         public String getRequestUri() {
92                 return requestUri;
93         }
94
95         /**
96          * Returns the contexts of the identity.
97          *
98          * @return The contexts of the identity
99          */
100         public Set<String> getContexts() {
101                 return Collections.unmodifiableSet(contexts);
102         }
103
104         /**
105          * Returns whether the identity contains the given context.
106          *
107          * @param context
108          *            The context to check for
109          * @return {@code true} if this identity has the given context,
110          *         {@code false} otherwise
111          */
112         public boolean hasContext(String context) {
113                 return contexts.contains(context);
114         }
115
116         /**
117          * Returns the properties of the identity.
118          *
119          * @return The properties of the identity
120          */
121         public Map<String, String> getProperties() {
122                 return Collections.unmodifiableMap(properties);
123         }
124
125         /**
126          * Returns the value of the property with the given name.
127          *
128          * @param name
129          *            The name of the property
130          * @return The value of the property, or {@code null} if there is no such
131          *         property
132          */
133         public String getProperty(String name) {
134                 return properties.get(name);
135         }
136
137         /**
138          * Sets the property with the given name to the given value.
139          *
140          * @param name
141          *            The name of the property to set
142          * @param value
143          *            The new value of the property
144          */
145         public void setProperty(String name, String value) {
146                 properties.put(name, value);
147                 /* TODO - set property. */
148         }
149
150         /**
151          * Removes the property with the given name.
152          *
153          * @param name
154          *            The name of the property to remove
155          */
156         public void removeProperty(String name) {
157                 properties.remove(name);
158                 /* TODO - remove property. */
159         }
160
161         //
162         // OBJECT METHODS
163         //
164
165         /**
166          * {@inheritDoc}
167          */
168         @Override
169         public int hashCode() {
170                 return id.hashCode();
171         }
172
173         /**
174          * {@inheritDoc}
175          */
176         @Override
177         public boolean equals(Object object) {
178                 if (!(object instanceof Identity)) {
179                         return false;
180                 }
181                 Identity identity = (Identity) object;
182                 return identity.id.equals(id);
183         }
184
185 }