I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit 7e21afe6 authored by zzz's avatar zzz
Browse files

sort the summary bar destinations

parent 720aa704
No related branches found
No related tags found
No related merge requests found
package net.i2p.router.web; package net.i2p.router.web;
import java.text.Collator;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Set;
import net.i2p.data.DataHelper; import net.i2p.data.DataHelper;
import net.i2p.data.Destination; import net.i2p.data.Destination;
...@@ -346,20 +350,16 @@ public class SummaryHelper extends HelperBase { ...@@ -346,20 +350,16 @@ public class SummaryHelper extends HelperBase {
* @return html section summary * @return html section summary
*/ */
public String getDestinations() { public String getDestinations() {
Set clients = _context.clientManager().listClients(); // covert the set to a list so we can sort by name and not lose duplicates
List clients = new ArrayList(_context.clientManager().listClients());
Collections.sort(clients, new AlphaComparator());
StringBuffer buf = new StringBuffer(512); StringBuffer buf = new StringBuffer(512);
buf.append("<u><b>Local destinations</b></u><br />"); buf.append("<u><b>Local destinations</b></u><br />");
for (Iterator iter = clients.iterator(); iter.hasNext(); ) { for (Iterator iter = clients.iterator(); iter.hasNext(); ) {
Destination client = (Destination)iter.next(); Destination client = (Destination)iter.next();
TunnelPoolSettings in = _context.tunnelManager().getInboundSettings(client.calculateHash()); String name = getName(client);
TunnelPoolSettings out = _context.tunnelManager().getOutboundSettings(client.calculateHash());
String name = (in != null ? in.getDestinationNickname() : null);
if (name == null)
name = (out != null ? out.getDestinationNickname() : null);
if (name == null)
name = client.calculateHash().toBase64().substring(0,6);
buf.append("<b>*</b> ").append(name).append("<br />\n"); buf.append("<b>*</b> ").append(name).append("<br />\n");
LeaseSet ls = _context.netDb().lookupLeaseSetLocally(client.calculateHash()); LeaseSet ls = _context.netDb().lookupLeaseSetLocally(client.calculateHash());
...@@ -373,14 +373,38 @@ public class SummaryHelper extends HelperBase { ...@@ -373,14 +373,38 @@ public class SummaryHelper extends HelperBase {
buf.append("<i>No leases</i><br />\n"); buf.append("<i>No leases</i><br />\n");
} }
buf.append("<a href=\"tunnels.jsp#").append(client.calculateHash().toBase64().substring(0,4)); buf.append("<a href=\"tunnels.jsp#").append(client.calculateHash().toBase64().substring(0,4));
buf.append("\">Details</a> "); buf.append("\" target=\"_top\">Details</a> ");
buf.append("<a href=\"configtunnels.jsp#").append(client.calculateHash().toBase64().substring(0,4)); buf.append("<a href=\"configtunnels.jsp#").append(client.calculateHash().toBase64().substring(0,4));
buf.append("\">Config</a><br />\n"); buf.append("\" target=\"_top\">Config</a><br />\n");
} }
buf.append("<hr />\n"); buf.append("<hr />\n");
return buf.toString(); return buf.toString();
} }
private class AlphaComparator implements Comparator {
public int compare(Object lhs, Object rhs) {
String lname = getName((Destination)lhs);
String rname = getName((Destination)rhs);
if (lname.equals("shared clients"))
return -1;
if (rname.equals("shared clients"))
return 1;
return Collator.getInstance().compare(lname, rname);
}
}
private String getName(Destination d) {
TunnelPoolSettings in = _context.tunnelManager().getInboundSettings(d.calculateHash());
String name = (in != null ? in.getDestinationNickname() : null);
if (name == null) {
TunnelPoolSettings out = _context.tunnelManager().getOutboundSettings(d.calculateHash());
name = (out != null ? out.getDestinationNickname() : null);
if (name == null)
name = d.calculateHash().toBase64().substring(0,6);
}
return name;
}
/** /**
* How many free inbound tunnels we have. * How many free inbound tunnels we have.
* *
...@@ -511,4 +535,5 @@ public class SummaryHelper extends HelperBase { ...@@ -511,4 +535,5 @@ public class SummaryHelper extends HelperBase {
public boolean updateAvailable() { public boolean updateAvailable() {
return NewsFetcher.getInstance(_context).updateAvailable(); return NewsFetcher.getInstance(_context).updateAvailable();
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment