X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ffreenet%2Fwot%2FIdentityChangeDetector.java;h=c45c0127ad583d5cbf96f64158d859a0f112a15c;hb=636778331c5bd52882a5a2851dbced8a000036d3;hp=9703891990ed0d4b841fed8177fab5277232b43a;hpb=76ed638264e531a26e35647d13702db865a52321;p=Sone.git
diff --git a/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityChangeDetector.java b/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityChangeDetector.java
index 9703891..c45c012 100644
--- a/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityChangeDetector.java
+++ b/src/main/java/net/pterodactylus/sone/freenet/wot/IdentityChangeDetector.java
@@ -1,5 +1,5 @@
/*
- * Sone - IdentityChangeDetector.java - Copyright © 2013â2015 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
@@ -21,8 +21,6 @@ import static com.google.common.base.Optional.absent;
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;
@@ -38,8 +36,6 @@ import com.google.common.collect.ImmutableMap;
* 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 David âBombeâ Roden
*/
public class IdentityChangeDetector {
@@ -105,7 +101,7 @@ public class IdentityChangeDetector {
return new Predicate() {
@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);
}
};
}
@@ -119,23 +115,23 @@ public class IdentityChangeDetector {
}
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 containedIn(final Map identities) {
@@ -151,7 +147,7 @@ public class IdentityChangeDetector {
return new Predicate() {
@Override
public boolean apply(String context) {
- return (identity == null) ? false : !identity.getContexts().contains(context);
+ return (identity != null) && !identity.getContexts().contains(context);
}
};
}
@@ -160,7 +156,7 @@ public class IdentityChangeDetector {
return new Predicate() {
@Override
public boolean apply(Identity identity) {
- return (identity == null) ? false : !newIdentities.contains(identity);
+ return (identity != null) && !newIdentities.contains(identity);
}
};
}
@@ -169,7 +165,7 @@ public class IdentityChangeDetector {
return new Predicate>() {
@Override
public boolean apply(Entry property) {
- return (property == null) ? false : !identity.getProperties().containsKey(property.getKey());
+ return (property != null) && !identity.getProperties().containsKey(property.getKey());
}
};
}
@@ -178,7 +174,7 @@ public class IdentityChangeDetector {
return new Predicate>() {
@Override
public boolean apply(Entry property) {
- return (property == null) ? false : !newIdentity.getProperty(property.getKey()).equals(property.getValue());
+ return (property != null) && !newIdentity.getProperty(property.getKey()).equals(property.getValue());
}
};
}