*/
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, Map<String, String>> TO_PROPERTIES = new Function<Identity, Map<String, String>>() {
- @Override
- public Map<String, String> apply(Identity input) {
- return (input == null) ? Collections.<String, String>emptyMap() : input.getProperties();
- }
- };
-
/**
* Returns the ID of the identity.
*
import static com.google.common.base.Optional.fromNullable;
import static com.google.common.base.Predicates.not;
import static com.google.common.collect.FluentIterable.from;
-import static net.pterodactylus.sone.freenet.wot.Identity.TO_CONTEXTS;
-import static net.pterodactylus.sone.freenet.wot.Identity.TO_PROPERTIES;
import java.util.Collection;
import java.util.Map;
}
private static boolean identityHasNewContexts(Identity oldIdentity, Identity newIdentity) {
- return from(TO_CONTEXTS.apply(newIdentity)).anyMatch(notAContextOf(oldIdentity));
+ return newIdentity.getContexts().stream().anyMatch(notAContextOf(oldIdentity)::apply);
}
private static boolean identityHasRemovedContexts(Identity oldIdentity, Identity newIdentity) {
- return from(TO_CONTEXTS.apply(oldIdentity)).anyMatch(notAContextOf(newIdentity));
+ return oldIdentity.getContexts().stream().anyMatch(notAContextOf(newIdentity)::apply);
}
private static boolean identityHasNewProperties(Identity oldIdentity, Identity newIdentity) {
- return from(TO_PROPERTIES.apply(newIdentity).entrySet()).anyMatch(notAPropertyOf(oldIdentity));
+ return newIdentity.getProperties().entrySet().stream().anyMatch(notAPropertyOf(oldIdentity)::apply);
}
private static boolean identityHasRemovedProperties(Identity oldIdentity, Identity newIdentity) {
- return from(TO_PROPERTIES.apply(oldIdentity).entrySet()).anyMatch(notAPropertyOf(newIdentity));
+ return oldIdentity.getProperties().entrySet().stream().anyMatch(notAPropertyOf(newIdentity)::apply);
}
private static boolean identityHasChangedProperties(Identity oldIdentity, Identity newIdentity) {
- return from(TO_PROPERTIES.apply(oldIdentity).entrySet()).anyMatch(hasADifferentValueThanIn(newIdentity));
+ return oldIdentity.getProperties().entrySet().stream().anyMatch(hasADifferentValueThanIn(newIdentity)::apply);
}
private static Predicate<Identity> containedIn(final Map<String, Identity> identities) {