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