Changeset 5389ee0


Ignore:
Timestamp:
Oct 6, 2010 2:05:26 AM (10 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
5ef9d46
Parents:
e2b7f93d
Message:

sort snark peers by completion %

File:
1 edited

Legend:

Unmodified
Added
Removed
  • apps/i2psnark/java/src/org/klomp/snark/web/I2PSnarkServlet.java

    re2b7f93d r5389ee0  
    99import java.util.ArrayList;
    1010import java.util.Arrays;
     11import java.util.Collections;
    1112import java.util.Comparator;
    1213import java.util.Enumeration;
     
    822823
    823824        if(showPeers && isRunning && curPeers > 0) {
    824             List peers = snark.coordinator.peerList();
    825             Iterator it = peers.iterator();
    826             while (it.hasNext()) {
    827                 Peer peer = (Peer)it.next();
     825            List<Peer> peers = snark.coordinator.peerList();
     826            Collections.sort(peers, new PeerComparator());
     827            for (Peer peer : peers) {
    828828                if (!peer.isConnected())
    829829                    continue;
     
    909909    }
    910910   
     911    /**
     912     *  Sort by completeness (seeds first), then by ID
     913     *  @since 0.8.1
     914     */
     915    private static class PeerComparator implements Comparator<Peer> {
     916        public int compare(Peer l, Peer r) {
     917            int diff = r.completed() - l.completed();      // reverse
     918            if (diff != 0)
     919                return diff;
     920            return l.toString().substring(5, 9).compareTo(r.toString().substring(5, 9));
     921        }
     922    }
     923
    911924    private void writeAddForm(PrintWriter out, HttpServletRequest req) throws IOException {
    912925        String uri = req.getRequestURI();
Note: See TracChangeset for help on using the changeset viewer.