2 * Sone - Identity.java - Copyright © 2010–2019 David Roden
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.
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.
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/>.
18 package net.pterodactylus.sone.freenet.wot;
20 import java.util.Collection;
21 import java.util.Collections;
25 import com.google.common.base.Function;
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.
32 public interface Identity {
34 public static final Function<Identity, Set<String>> TO_CONTEXTS = new Function<Identity, Set<String>>() {
36 public Set<String> apply(Identity identity) {
37 return (identity == null) ? Collections.<String>emptySet() : identity.getContexts();
41 public static final Function<Identity, Map<String, String>> TO_PROPERTIES = new Function<Identity, Map<String, String>>() {
43 public Map<String, String> apply(Identity input) {
44 return (input == null) ? Collections.<String, String>emptyMap() : input.getProperties();
49 * Returns the ID of the identity.
51 * @return The ID of the identity
53 public String getId();
56 * Returns the nickname of the identity.
58 * @return The nickname of the identity
60 public String getNickname();
63 * Returns the request URI of the identity.
65 * @return The request URI of the identity
67 public String getRequestUri();
70 * Returns all contexts of this identity.
72 * @return All contexts of this identity
74 public Set<String> getContexts();
77 * Returns whether this identity has the given context.
80 * The context to check for
81 * @return {@code true} if this identity has the given context,
82 * {@code false} otherwise
84 public boolean hasContext(String context);
87 * Adds the given context to this identity.
92 public Identity addContext(String context);
95 * Sets all contexts of this identity.
98 * All contexts of the identity
100 public void setContexts(Collection<String> contexts);
103 * Removes the given context from this identity.
106 * The context to remove
108 public Identity removeContext(String context);
111 * Returns all properties of this identity.
113 * @return All properties of this identity
115 public Map<String, String> getProperties();
118 * Returns the value of the property with the given name.
121 * The name of the property
122 * @return The value of the property
124 public String getProperty(String name);
127 * Sets the property with the given name to the given value.
130 * The name of the property
132 * The value of the property
134 public Identity setProperty(String name, String value);
137 * Sets all properties of this identity.
140 * The new properties of this identity
142 public void setProperties(Map<String, String> properties);
145 * Removes the property with the given name.
148 * The name of the property to remove
150 public Identity removeProperty(String name);
153 * Retrieves the trust that this identity receives from the given own
154 * identity. If this identity is not in the own identity’s trust tree, a
155 * {@link Trust} is returned that has all its elements set to {@code null}.
156 * If the trust can not be retrieved, {@code null} is returned.
159 * The own identity to get the trust for
160 * @return The trust assigned to this identity, or {@code null} if the trust
161 * could not be retrieved
163 public Trust getTrust(OwnIdentity ownIdentity);
166 * Sets the trust given by an own identity to this identity.
169 * The own identity that gave trust to this identity
171 * The trust given by the given own identity
173 public Identity setTrust(OwnIdentity ownIdentity, Trust trust);
176 * Removes trust assignment from the given own identity for this identity.
179 * The own identity that removed the trust assignment for this
182 public Identity removeTrust(OwnIdentity ownIdentity);