Add identity manager changes from the refactoring branch.
[Sone.git] / src / main / java / net / pterodactylus / sone / freenet / wot / Identity.java
index bc594f8..4554f40 100644 (file)
 package net.pterodactylus.sone.freenet.wot;
 
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Map;
 import java.util.Set;
 
+import javax.annotation.Nullable;
+
+import com.google.common.base.Function;
+
 /**
  * Interface for web of trust identities, defining all functions that can be
  * performed on an identity. An identity is only a container for identity data
@@ -30,6 +35,20 @@ import java.util.Set;
  */
 public interface Identity {
 
+       final Function<Identity, Collection<String>> TO_CONTEXTS = new Function<Identity, Collection<String>>() {
+               @Override
+               public Collection<String> apply(@Nullable Identity identity) {
+                       return (identity == null) ? Collections.<String>emptyList() : identity.getContexts();
+               }
+       };
+
+       final Function<Identity, Map<String, String>> TO_PROPERTIES = new Function<Identity, Map<String, String>>() {
+               @Override
+               public Map<String, String> apply(@Nullable Identity identity) {
+                       return (identity == null) ? Collections.<String, String>emptyMap() : identity.getProperties();
+               }
+       };
+
        /**
         * Returns the ID of the identity.
         *