FileDocCategorySizeDatePackage
UpRatioItem.javaAPI DocAzureus 3.0.3.42553Sun Sep 23 04:55:00 BST 2007org.gudy.azureus2.ui.swt.views.tableitems.peers

UpRatioItem

public class UpRatioItem extends org.gudy.azureus2.ui.swt.views.table.utils.CoreTableColumn implements TableCellRefreshListener
author
TuxPaper

Fields Summary
Constructors Summary
public UpRatioItem(String table_id)
Default Constructor

    super("UpRatio", ALIGN_TRAIL, POSITION_INVISIBLE, 70, table_id);
    setRefreshInterval(INTERVAL_LIVE);
  
Methods Summary
public voidrefresh(TableCell cell)

    PEPeer peer = (PEPeer)cell.getDataSource();
    float value = 0;
    long lDivisor = 0;
    long lDivident = 0;
    if (peer != null) {
      lDivisor = peer.getStats().getTotalBytesDownloadedByPeer() - peer.getStats().getTotalDataBytesSent();
      lDivident = peer.getStats().getTotalDataBytesSent();
      // skip if divisor is small (most likely handshake) or 0 (DivisionByZero)
      if (lDivisor > 1024) {
        value = lDivident / (float)lDivisor;
        if (value == 0)
          value = -1;
      } else if (lDivident > 0)
        value = Constants.INFINITY_AS_INT;
    }

    if (!cell.setSortValue((long)(value * 1000)) && cell.isValid())
      return;

    String s;
    if (lDivisor <= 0) 
      s = "";
    else if (value == Constants.INFINITY_AS_INT)
      s = Constants.INFINITY_STRING + ":1";
    else if (value == -1)
      s = "1:" + Constants.INFINITY_STRING;
    else
      s = DisplayFormatters.formatDecimal(value, 2) + ":1";

    cell.setText(s);