FileDocCategorySizeDatePackage
SeedToPeerRatioItem.javaAPI DocAzureus 3.0.3.42948Mon Feb 19 14:24:06 GMT 2007org.gudy.azureus2.ui.swt.views.tableitems.mytorrents

SeedToPeerRatioItem

public class SeedToPeerRatioItem extends org.gudy.azureus2.ui.swt.views.table.utils.CoreTableColumn implements TableCellRefreshListener

Fields Summary
Constructors Summary
public SeedToPeerRatioItem(String sTableID)

    super("seed_to_peer_ratio", ALIGN_TRAIL, POSITION_INVISIBLE, 70, sTableID);
    setRefreshInterval(INTERVAL_LIVE);
    setMinWidthAuto(true);
  
Methods Summary
public voidrefresh(TableCell cell)

    float ratio = -1;
    

    DownloadManager dm = (DownloadManager)cell.getDataSource();
    if( dm != null ) {
      TRTrackerScraperResponse response = dm.getTrackerScrapeResponse();
      int seeds;
      int peers;
      
      if( response != null && response.isValid() ) {
        seeds = Math.max( dm.getNbSeeds(), response.getSeeds() );
        
        int trackerPeerCount = response.getPeers();
        peers = dm.getNbPeers();
        if (peers == 0 || trackerPeerCount > peers) {
        	if (trackerPeerCount <= 0) {
          	peers = dm.getActivationCount();
        	} else {
        		peers = trackerPeerCount;
        	}
        }
      }
      else {
        seeds = dm.getNbSeeds();
        peers = dm.getNbPeers();
      }
      
      if (peers < 0 || seeds < 0) {
      	ratio = 0;
      } else {
	      if (peers == 0) {
	      	if (seeds == 0)
	      		ratio = 0;
	      	else
	        	ratio = Float.POSITIVE_INFINITY;
	      } else {
	      	ratio = (float)seeds / peers;
	      }
      }
    }

    if( !cell.setSortValue( ratio ) && cell.isValid() ) {
      return;
    }
    
    if (ratio == -1) {
			cell.setText("");
		} else if (ratio == 0) {
			cell.setText("??");
		} else {
			cell.setText(DisplayFormatters.formatDecimal(ratio, 3));
		}