Add class that compares two lists of identities.
[Sone.git] / src / main / java / net / pterodactylus / sone / freenet / wot / Identity.java
index 2849da9..ff87fcd 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Sone - Identity.java - Copyright © 2010–2012 David Roden
+ * Sone - Identity.java - Copyright © 2010–2013 David Roden
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 package net.pterodactylus.sone.freenet.wot;
 
 import java.util.Collection;
+import java.util.Collections;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Set;
 
+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 +34,20 @@ import java.util.Set;
  */
 public interface Identity {
 
+       public static final Function<Identity, Set<String>> TO_CONTEXTS = new Function<Identity, Set<String>>() {
+               @Override
+               public Set<String> apply(Identity identity) {
+                       return (identity == null) ? Collections.<String>emptySet() : identity.getContexts();
+               }
+       };
+
+       public static final Function<Identity, Collection<Map.Entry<String, String>>> TO_PROPERTIES = new Function<Identity, Collection<Entry<String, String>>>() {
+               @Override
+               public Collection<Entry<String, String>> apply(Identity input) {
+                       return (input == null) ? Collections.<Map.Entry<String, String>>emptySet() : input.getProperties().entrySet();
+               }
+       };
+
        /**
         * Returns the ID of the identity.
         *