Turn (Own)Identity into mere caches of values from the WebOfTrust.
[Sone.git] / src / main / java / net / pterodactylus / sone / freenet / wot / Identity.java
1 /*
2  * Sone - Identity.java - Copyright © 2010–2012 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.Collection;
21 import java.util.Map;
22 import java.util.Set;
23
24 /**
25  * Interface for web of trust identities, defining all functions that can be
26  * performed on an identity. An identity is only a container for identity data
27  * and will not perform any updating in the WebOfTrust plugin itself.
28  *
29  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
30  */
31 public interface Identity {
32
33         /**
34          * Returns the ID of the identity.
35          *
36          * @return The ID of the identity
37          */
38         public String getId();
39
40         /**
41          * Returns the nickname of the identity.
42          *
43          * @return The nickname of the identity
44          */
45         public String getNickname();
46
47         /**
48          * Returns the request URI of the identity.
49          *
50          * @return The request URI of the identity
51          */
52         public String getRequestUri();
53
54         /**
55          * Returns all contexts of this identity.
56          *
57          * @return All contexts of this identity
58          */
59         public Set<String> getContexts();
60
61         /**
62          * Returns whether this identity has the given context.
63          *
64          * @param context
65          *            The context to check for
66          * @return {@code true} if this identity has the given context,
67          *         {@code false} otherwise
68          */
69         public boolean hasContext(String context);
70
71         /**
72          * Adds the given context to this identity.
73          *
74          * @param context
75          *            The context to add
76          */
77         public void addContext(String context);
78
79         /**
80          * Sets all contexts of this identity.
81          *
82          * @param contexts
83          *            All contexts of the identity
84          */
85         public void setContexts(Collection<String> contexts);
86
87         /**
88          * Removes the given context from this identity.
89          *
90          * @param context
91          *            The context to remove
92          */
93         public void removeContext(String context);
94
95         /**
96          * Returns all properties of this identity.
97          *
98          * @return All properties of this identity
99          */
100         public Map<String, String> getProperties();
101
102         /**
103          * Returns the value of the property with the given name.
104          *
105          * @param name
106          *            The name of the property
107          * @return The value of the property
108          */
109         public String getProperty(String name);
110
111         /**
112          * Sets the property with the given name to the given value.
113          *
114          * @param name
115          *            The name of the property
116          * @param value
117          *            The value of the property
118          */
119         public void setProperty(String name, String value);
120
121         /**
122          * Sets all properties of this identity.
123          *
124          * @param properties
125          *            The new properties of this identity
126          */
127         public void setProperties(Map<String, String> properties);
128
129         /**
130          * Removes the property with the given name.
131          *
132          * @param name
133          *            The name of the property to remove
134          */
135         public void removeProperty(String name);
136
137         /**
138          * Retrieves the trust that this identity receives from the given own
139          * identity. If this identity is not in the own identity’s trust tree, a
140          * {@link Trust} is returned that has all its elements set to {@code null}.
141          * If the trust can not be retrieved, {@code null} is returned.
142          *
143          * @param ownIdentity
144          *            The own identity to get the trust for
145          * @return The trust assigned to this identity, or {@code null} if the trust
146          *         could not be retrieved
147          */
148         public Trust getTrust(OwnIdentity ownIdentity);
149
150         /**
151          * Sets the trust given by an own identity to this identity.
152          *
153          * @param ownIdentity
154          *            The own identity that gave trust to this identity
155          * @param trust
156          *            The trust given by the given own identity
157          */
158         public void setTrust(OwnIdentity ownIdentity, Trust trust);
159
160         /**
161          * Removes trust assignment from the given own identity for this identity.
162          *
163          * @param ownIdentity
164          *            The own identity that removed the trust assignment for this
165          *            identity
166          */
167         public void removeTrust(OwnIdentity ownIdentity);
168
169 }