diff --git a/apps/routerconsole/java/src/net/i2p/router/web/helpers/SybilRenderer.java b/apps/routerconsole/java/src/net/i2p/router/web/helpers/SybilRenderer.java
index f3ae3a6e56..29adad623f 100644
--- a/apps/routerconsole/java/src/net/i2p/router/web/helpers/SybilRenderer.java
+++ b/apps/routerconsole/java/src/net/i2p/router/web/helpers/SybilRenderer.java
@@ -269,11 +269,11 @@ private void renderOverview(Writer out, StringBuilder buf, String nonce, Analysi
first = false;
}
buf.append('>').append(DataHelper.formatTime(date.longValue())).append("\n");
- }
+ }
buf.append("\n" +
"" +
"\n");
- }
+ }
writeBuf(out, buf);
}
@@ -543,10 +543,10 @@ private void renderThreatsHTML(Writer out, StringBuilder buf, long date, MapThreat Points: " + fmt.format(p) + "
");
- List reasons = pp.getReasons();
+ Map reasons = pp.getReasons();
if (reasons.size() > 1)
- Collections.sort(reasons, rcomp);
- for (String s : reasons) {
+ //Collections.sort(reasons, rcomp);
+ for (String s : reasons.keySet()) {
int c = s.indexOf(':');
if (c <= 0)
continue;
diff --git a/router/java/src/net/i2p/router/sybil/Points.java b/router/java/src/net/i2p/router/sybil/Points.java
index decb78970d..5a5bdff133 100644
--- a/router/java/src/net/i2p/router/sybil/Points.java
+++ b/router/java/src/net/i2p/router/sybil/Points.java
@@ -3,6 +3,8 @@
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
import net.i2p.data.DataHelper;
@@ -12,14 +14,12 @@
* @since 0.9.38 moved from SybilRenderer
*/
public class Points implements Comparable {
- private double points;
- private final List reasons;
-
+ private final Map reasons;
/**
* @since 0.9.38
*/
private Points() {
- reasons = new ArrayList(4);
+ reasons = new ConcurrentHashMap(4);
}
/**
@@ -30,17 +30,25 @@ public Points(double d, String reason) {
addPoints(d, reason);
}
+ private double points() {
+ double rv = 0;
+ for (String reason: reasons.keySet()){
+ rv += reasons.get(reason);
+ }
+ return rv;
+ }
+
/**
* @since 0.9.38
*/
public double getPoints() {
- return points;
+ return points();
}
/**
* @since 0.9.38
*/
- public List getReasons() {
+ public Map getReasons() {
return reasons;
}
@@ -49,14 +57,20 @@ public List getReasons() {
* @since 0.9.38
*/
public void addPoints(double d, String reason) {
- points += d;
DecimalFormat format = new DecimalFormat("#0.00");
String rsn = format.format(d) + ": " + reason;
- reasons.add(rsn);
+ Double rp = reasons.get(rsn);
+ if (rp == null) {
+ // reason was not yet present in the map, create a new entry for it.
+ reasons.put(rsn, d);
+ }else{
+ // reason was present in the map, add the points to it.
+ rp += d;
+ }
}
public int compareTo(Points r) {
- return Double.compare(points, r.points);
+ return Double.compare(points(), r.points());
}
/**
@@ -79,8 +93,8 @@ public String toString() {
* @since 0.9.38
*/
public void toString(StringBuilder buf) {
- buf.append(points);
- for (String r : reasons) {
+ buf.append(points());
+ for (String r : reasons.keySet()) {
buf.append('%').append(r.replace("%", "%"));
}
}
@@ -102,9 +116,8 @@ public static Points fromString(String s) {
}
Points rv = new Points();
for (int i = 1; i < ss.length; i++) {
- rv.reasons.add(ss[i]);
+ rv.reasons.put(ss[i], d);
}
- rv.points = d;
return rv;
}
}