/*
- * Sone - IdentityChangeDetector.java - Copyright © 2013 David Roden
+ * Sone - IdentityChangeDetector.java - Copyright © 2013–2019 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
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;
* added and removed identities, and for identities that exist in both list
* their contexts and properties are checked for added, removed, or (in case of
* properties) changed values.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
*/
public class IdentityChangeDetector {
return new Predicate<Identity>() {
@Override
public boolean apply(Identity identity) {
- return (identity == null) ? false : identityHasChanged(oldIdentities.get(identity.getId()), identity);
+ return (identity != null) && identityHasChanged(oldIdentities.get(identity.getId()), identity);
}
};
}
}
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) {
return new Predicate<Identity>() {
@Override
public boolean apply(Identity identity) {
- return identities.containsKey(identity.getId());
+ return (identity != null) && identities.containsKey(identity.getId());
}
};
}
return new Predicate<String>() {
@Override
public boolean apply(String context) {
- return (identity == null) ? false : !identity.getContexts().contains(context);
+ return (identity != null) && !identity.getContexts().contains(context);
}
};
}
return new Predicate<Identity>() {
@Override
public boolean apply(Identity identity) {
- return (identity == null) ? false : !newIdentities.contains(identity);
+ return (identity != null) && !newIdentities.contains(identity);
}
};
}
return new Predicate<Entry<String, String>>() {
@Override
public boolean apply(Entry<String, String> property) {
- return (property == null) ? false : !identity.getProperties().containsKey(property.getKey());
+ return (property != null) && !identity.getProperties().containsKey(property.getKey());
}
};
}
return new Predicate<Entry<String, String>>() {
@Override
public boolean apply(Entry<String, String> property) {
- return (property == null) ? false : !newIdentity.getProperty(property.getKey()).equals(property.getValue());
+ return (property != null) && !newIdentity.getProperty(property.getKey()).equals(property.getValue());
}
};
}