Sort RouterAddress options on peers.jsp and netdb.jsp

This commit is contained in:
zzz
2010-10-02 15:51:48 +00:00
parent ec0c678cc9
commit 53847dc3ad
2 changed files with 30 additions and 13 deletions

View File

@ -19,6 +19,8 @@ import java.util.Comparator;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
@ -34,6 +36,7 @@ import net.i2p.router.TunnelPoolSettings;
import net.i2p.router.networkdb.kademlia.HashDistance; // debug import net.i2p.router.networkdb.kademlia.HashDistance; // debug
import net.i2p.util.HexDump; // debug import net.i2p.util.HexDump; // debug
import net.i2p.util.ObjectCounter; import net.i2p.util.ObjectCounter;
import net.i2p.util.OrderedProperties;
import net.i2p.util.VersionComparator; import net.i2p.util.VersionComparator;
public class NetDbRenderer { public class NetDbRenderer {
@ -371,9 +374,11 @@ public class NetDbRenderer {
int cost = addr.getCost(); int cost = addr.getCost();
if (!((style.equals("SSU") && cost == 5) || (style.equals("NTCP") && cost == 10))) if (!((style.equals("SSU") && cost == 5) || (style.equals("NTCP") && cost == 10)))
buf.append('[').append(_("cost")).append('=').append("" + cost).append("] "); buf.append('[').append(_("cost")).append('=').append("" + cost).append("] ");
for (Iterator optIter = addr.getOptions().keySet().iterator(); optIter.hasNext(); ) { Properties p = new OrderedProperties();
String name = (String)optIter.next(); p.putAll(addr.getOptions());
String val = addr.getOptions().getProperty(name); for (Map.Entry e : p.entrySet()) {
String name = (String) e.getKey();
String val = (String) e.getValue();
buf.append('[').append(_(DataHelper.stripHTML(name))).append('=').append(DataHelper.stripHTML(val)).append("] "); buf.append('[').append(_(DataHelper.stripHTML(name))).append('=').append(DataHelper.stripHTML(val)).append("] ");
} }
} }

View File

@ -14,8 +14,11 @@ import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Date; import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map;
import java.util.Properties; import java.util.Properties;
import net.i2p.util.OrderedProperties;
/** /**
* Defines a method of communicating with a router * Defines a method of communicating with a router
* *
@ -28,7 +31,7 @@ public class RouterAddress extends DataStructureImpl {
private Properties _options; private Properties _options;
public RouterAddress() { public RouterAddress() {
setCost(-1); _cost = -1;
} }
/** /**
@ -134,19 +137,28 @@ public class RouterAddress extends DataStructureImpl {
return DataHelper.hashCode(_transportStyle); return DataHelper.hashCode(_transportStyle);
} }
/**
* This is used on peers.jsp so sort options so it looks better.
* We don't just use OrderedProperties for _options because DataHelper.writeProperties()
* sorts also.
*/
@Override @Override
public String toString() { public String toString() {
StringBuilder buf = new StringBuilder(64); StringBuilder buf = new StringBuilder(128);
buf.append("[RouterAddress: "); buf.append("[RouterAddress: ");
buf.append("\n\tTransportStyle: ").append(getTransportStyle()); buf.append("\n\tTransportStyle: ").append(_transportStyle);
buf.append("\n\tCost: ").append(getCost()); buf.append("\n\tCost: ").append(_cost);
buf.append("\n\tExpiration: ").append(getExpiration()); buf.append("\n\tExpiration: ").append(_expiration);
buf.append("\n\tOptions: #: ").append(getOptions().size()); if (_options != null) {
for (Iterator iter = getOptions().keySet().iterator(); iter.hasNext();) { buf.append("\n\tOptions: #: ").append(_options.size());
String key = (String) iter.next(); Properties p = new OrderedProperties();
String val = getOptions().getProperty(key); p.putAll(_options);
for (Map.Entry e : p.entrySet()) {
String key = (String) e.getKey();
String val = (String) e.getValue();
buf.append("\n\t\t[").append(key).append("] = [").append(val).append("]"); buf.append("\n\t\t[").append(key).append("] = [").append(val).append("]");
} }
}
buf.append("]"); buf.append("]");
return buf.toString(); return buf.toString();
} }