X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ffreenet%2Fwot%2FWebOfTrustConnector.java;h=7938a0969ef365aa4642b3daf3ec4e05444d8b50;hb=e7e16a55d9ce8bb104b3bd1260875ede6fd921e5;hp=d3e8747fe521807c5dbfea8f5718f2a3010531e1;hpb=d5efb086bee8f103cbe90c7a953ffbb7ff27b689;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/freenet/wot/WebOfTrustConnector.java b/src/main/java/net/pterodactylus/sone/freenet/wot/WebOfTrustConnector.java index d3e8747..7938a09 100644 --- a/src/main/java/net/pterodactylus/sone/freenet/wot/WebOfTrustConnector.java +++ b/src/main/java/net/pterodactylus/sone/freenet/wot/WebOfTrustConnector.java @@ -29,11 +29,11 @@ import net.pterodactylus.sone.freenet.plugin.PluginConnector; import net.pterodactylus.sone.freenet.plugin.PluginException; import net.pterodactylus.sone.freenet.plugin.event.ReceivedReplyEvent; import net.pterodactylus.util.logging.Logging; +import net.pterodactylus.util.number.Numbers; import com.google.common.base.Optional; import com.google.common.collect.MapMaker; import com.google.common.eventbus.Subscribe; -import com.google.common.primitives.Ints; import com.google.inject.Inject; import freenet.support.SimpleFieldSet; @@ -138,8 +138,8 @@ public class WebOfTrustConnector { * @throws PluginException * if an error occured talking to the Web of Trust plugin */ - public Set loadTrustedIdentities(OwnIdentity ownIdentity, String context) throws PluginException { - Reply reply = performRequest(SimpleFieldSetConstructor.create().put("Message", "GetIdentitiesByScore").put("Truster", ownIdentity.getId()).put("Selection", "+").put("Context", (context == null) ? "" : context).put("WantTrustValues", "true").get()); + public Set loadTrustedIdentities(OwnIdentity ownIdentity, Optional context) throws PluginException { + Reply reply = performRequest(SimpleFieldSetConstructor.create().put("Message", "GetIdentitiesByScore").put("Truster", ownIdentity.getId()).put("Selection", "+").put("Context", context.or("")).put("WantTrustValues", "true").get()); SimpleFieldSet fields = reply.getFields(); Set identities = new HashSet(); int identityCounter = -1; @@ -153,9 +153,9 @@ public class WebOfTrustConnector { DefaultIdentity identity = new DefaultIdentity(id, nickname, requestUri); identity.setContexts(parseContexts("Contexts" + identityCounter + ".", fields)); identity.setProperties(parseProperties("Properties" + identityCounter + ".", fields)); - Integer trust = Ints.tryParse(fields.get("Trust" + identityCounter)); - int score = Optional.fromNullable(Ints.tryParse(fields.get("Score" + identityCounter))).or(0); - int rank = Optional.fromNullable(Ints.tryParse(fields.get("Rank" + identityCounter))).or(0); + Integer trust = Numbers.safeParseInteger(fields.get("Trust" + identityCounter), null); + int score = Numbers.safeParseInteger(fields.get("Score" + identityCounter), 0); + int rank = Numbers.safeParseInteger(fields.get("Rank" + identityCounter), 0); identity.setTrust(ownIdentity, new Trust(trust, score, rank)); identities.add(identity); } @@ -567,8 +567,7 @@ public class WebOfTrustConnector { * @return The created simple field set constructor */ public static SimpleFieldSetConstructor create(boolean shortLived) { - SimpleFieldSetConstructor simpleFieldSetConstructor = new SimpleFieldSetConstructor(shortLived); - return simpleFieldSetConstructor; + return new SimpleFieldSetConstructor(shortLived); } }