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

View File

@ -14,8 +14,11 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.util.Date;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import net.i2p.util.OrderedProperties;
/**
* Defines a method of communicating with a router
*
@ -28,7 +31,7 @@ public class RouterAddress extends DataStructureImpl {
private Properties _options;
public RouterAddress() {
setCost(-1);
_cost = -1;
}
/**
@ -134,18 +137,27 @@ public class RouterAddress extends DataStructureImpl {
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
public String toString() {
StringBuilder buf = new StringBuilder(64);
StringBuilder buf = new StringBuilder(128);
buf.append("[RouterAddress: ");
buf.append("\n\tTransportStyle: ").append(getTransportStyle());
buf.append("\n\tCost: ").append(getCost());
buf.append("\n\tExpiration: ").append(getExpiration());
buf.append("\n\tOptions: #: ").append(getOptions().size());
for (Iterator iter = getOptions().keySet().iterator(); iter.hasNext();) {
String key = (String) iter.next();
String val = getOptions().getProperty(key);
buf.append("\n\t\t[").append(key).append("] = [").append(val).append("]");
buf.append("\n\tTransportStyle: ").append(_transportStyle);
buf.append("\n\tCost: ").append(_cost);
buf.append("\n\tExpiration: ").append(_expiration);
if (_options != null) {
buf.append("\n\tOptions: #: ").append(_options.size());
Properties p = new OrderedProperties();
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("]");
return buf.toString();