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