Statistician

- Added some handling for 0 based values
This commit is contained in:
Joshua Kissoon 2014-05-13 09:54:52 +05:30
parent a25b88a9bb
commit c23edf2cb9

View File

@ -45,6 +45,11 @@ public class Statistician implements KadStatistician
@Override
public long getTotalDataSent()
{
if (this.totalDataSent == 0)
{
return 0L;
}
return this.totalDataSent / 1000L;
}
@ -58,6 +63,10 @@ public class Statistician implements KadStatistician
@Override
public long getTotalDataReceived()
{
if (this.totalDataReceived == 0)
{
return 0L;
}
return this.totalDataReceived / 1000L;
}
@ -109,6 +118,11 @@ public class Statistician implements KadStatistician
@Override
public double averageContentLookupTime()
{
if (this.numContentLookups == 0)
{
return 0D;
}
double avg = (double) ((double) this.totalContentLookupTime / (double) this.numContentLookups) / 1000000D;
DecimalFormat df = new DecimalFormat("#.00");
return new Double(df.format(avg));
@ -117,6 +131,10 @@ public class Statistician implements KadStatistician
@Override
public double averageContentLookupRouteLength()
{
if (this.numContentLookups == 0)
{
return 0D;
}
double avg = (double) ((double) this.totalRouteLength / (double) this.numContentLookups);
DecimalFormat df = new DecimalFormat("#.00");
return new Double(df.format(avg));