forked from I2P_Developers/i2p.i2p
* stats.jsp: Sort groups by translated name
This commit is contained in:
@ -3,10 +3,14 @@ package net.i2p.router.web;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
|
import java.text.Collator;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.SortedSet;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
|
||||||
import net.i2p.data.DataHelper;
|
import net.i2p.data.DataHelper;
|
||||||
import net.i2p.router.RouterContext;
|
import net.i2p.router.RouterContext;
|
||||||
@ -14,18 +18,15 @@ import net.i2p.stat.Frequency;
|
|||||||
import net.i2p.stat.FrequencyStat;
|
import net.i2p.stat.FrequencyStat;
|
||||||
import net.i2p.stat.Rate;
|
import net.i2p.stat.Rate;
|
||||||
import net.i2p.stat.RateStat;
|
import net.i2p.stat.RateStat;
|
||||||
import net.i2p.util.Log;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dump the stats to the web admin interface
|
* Dump the stats to the web admin interface
|
||||||
*/
|
*/
|
||||||
public class StatsGenerator {
|
public class StatsGenerator {
|
||||||
private Log _log;
|
|
||||||
private RouterContext _context;
|
private RouterContext _context;
|
||||||
|
|
||||||
public StatsGenerator(RouterContext context) {
|
public StatsGenerator(RouterContext context) {
|
||||||
_context = context;
|
_context = context;
|
||||||
_log = context.logManager().getLog(StatsGenerator.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void generateStatsPage(Writer out, boolean showAll) throws IOException {
|
public void generateStatsPage(Writer out, boolean showAll) throws IOException {
|
||||||
@ -35,10 +36,10 @@ public class StatsGenerator {
|
|||||||
out.write(buf.toString());
|
out.write(buf.toString());
|
||||||
buf.setLength(0);
|
buf.setLength(0);
|
||||||
|
|
||||||
Map groups = _context.statManager().getStatsByGroup();
|
Map<String, SortedSet<String>> unsorted = _context.statManager().getStatsByGroup();
|
||||||
for (Iterator iter = groups.entrySet().iterator(); iter.hasNext(); ) {
|
Map<String, Set<String>> groups = new TreeMap(new AlphaComparator());
|
||||||
Map.Entry entry = (Map.Entry)iter.next();
|
groups.putAll(unsorted);
|
||||||
String group = (String)entry.getKey();
|
for (String group : groups.keySet()) {
|
||||||
buf.append("<option value=\"#").append(group).append("\">");
|
buf.append("<option value=\"#").append(group).append("\">");
|
||||||
buf.append(_(group)).append("</option>\n");
|
buf.append(_(group)).append("</option>\n");
|
||||||
// let's just do the groups
|
// let's just do the groups
|
||||||
@ -66,9 +67,9 @@ public class StatsGenerator {
|
|||||||
out.write(buf.toString());
|
out.write(buf.toString());
|
||||||
buf.setLength(0);
|
buf.setLength(0);
|
||||||
|
|
||||||
for (Iterator iter = groups.keySet().iterator(); iter.hasNext(); ) {
|
for (Map.Entry<String, Set<String>> entry : groups.entrySet()) {
|
||||||
String group = (String)iter.next();
|
String group = entry.getKey();
|
||||||
Set stats = (Set)groups.get(group);
|
Set<String> stats = entry.getValue();
|
||||||
buf.append("<h3><a name=\"");
|
buf.append("<h3><a name=\"");
|
||||||
buf.append(group);
|
buf.append(group);
|
||||||
buf.append("\">");
|
buf.append("\">");
|
||||||
@ -77,8 +78,7 @@ public class StatsGenerator {
|
|||||||
buf.append("<ul>");
|
buf.append("<ul>");
|
||||||
out.write(buf.toString());
|
out.write(buf.toString());
|
||||||
buf.setLength(0);
|
buf.setLength(0);
|
||||||
for (Iterator statIter = stats.iterator(); statIter.hasNext(); ) {
|
for (String stat : stats) {
|
||||||
String stat = (String)statIter.next();
|
|
||||||
buf.append("<li><b><a name=\"");
|
buf.append("<li><b><a name=\"");
|
||||||
buf.append(stat);
|
buf.append(stat);
|
||||||
buf.append("\">");
|
buf.append("\">");
|
||||||
@ -250,6 +250,18 @@ public class StatsGenerator {
|
|||||||
private final static DecimalFormat _pct = new DecimalFormat("#0.00%");
|
private final static DecimalFormat _pct = new DecimalFormat("#0.00%");
|
||||||
private final static String pct(double num) { synchronized (_pct) { return _pct.format(num); } }
|
private final static String pct(double num) { synchronized (_pct) { return _pct.format(num); } }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Translated sort
|
||||||
|
* @since 0.9.3
|
||||||
|
*/
|
||||||
|
private class AlphaComparator implements Comparator<String> {
|
||||||
|
public int compare(String lhs, String rhs) {
|
||||||
|
String lname = _(lhs);
|
||||||
|
String rname = _(rhs);
|
||||||
|
return Collator.getInstance().compare(lname, rname);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** translate a string */
|
/** translate a string */
|
||||||
private String _(String s) {
|
private String _(String s) {
|
||||||
return Messages.getString(s, _context);
|
return Messages.getString(s, _context);
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
package net.i2p.stat;
|
package net.i2p.stat;
|
||||||
|
|
||||||
import java.text.Collator;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.TreeMap;
|
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
@ -212,19 +211,28 @@ public class StatManager {
|
|||||||
return _frequencyStats.containsKey(statName);
|
return _frequencyStats.containsKey(statName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Group name (String) to a Set of stat names, ordered alphabetically */
|
/**
|
||||||
|
* Group name (untranslated String) to a SortedSet of untranslated stat names.
|
||||||
|
* Map is unsorted.
|
||||||
|
*/
|
||||||
public Map<String, SortedSet<String>> getStatsByGroup() {
|
public Map<String, SortedSet<String>> getStatsByGroup() {
|
||||||
Map<String, SortedSet<String>> groups = new TreeMap(Collator.getInstance());
|
Map<String, SortedSet<String>> groups = new HashMap(32);
|
||||||
for (Iterator<FrequencyStat> iter = _frequencyStats.values().iterator(); iter.hasNext();) {
|
for (FrequencyStat stat : _frequencyStats.values()) {
|
||||||
FrequencyStat stat = iter.next();
|
String gname = stat.getGroupName();
|
||||||
if (!groups.containsKey(stat.getGroupName())) groups.put(stat.getGroupName(), new TreeSet());
|
SortedSet<String> names = groups.get(gname);
|
||||||
Set<String> names = groups.get(stat.getGroupName());
|
if (names == null) {
|
||||||
|
names = new TreeSet();
|
||||||
|
groups.put(gname, names);
|
||||||
|
}
|
||||||
names.add(stat.getName());
|
names.add(stat.getName());
|
||||||
}
|
}
|
||||||
for (Iterator<RateStat> iter = _rateStats.values().iterator(); iter.hasNext();) {
|
for (RateStat stat : _rateStats.values()) {
|
||||||
RateStat stat = iter.next();
|
String gname = stat.getGroupName();
|
||||||
if (!groups.containsKey(stat.getGroupName())) groups.put(stat.getGroupName(), new TreeSet());
|
SortedSet<String> names = groups.get(gname);
|
||||||
Set<String> names = groups.get(stat.getGroupName());
|
if (names == null) {
|
||||||
|
names = new TreeSet();
|
||||||
|
groups.put(gname, names);
|
||||||
|
}
|
||||||
names.add(stat.getName());
|
names.add(stat.getName());
|
||||||
}
|
}
|
||||||
return groups;
|
return groups;
|
||||||
|
Reference in New Issue
Block a user