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