From c23edf2cb92825dafa138382916b39112b8d4a91 Mon Sep 17 00:00:00 2001 From: Joshua Kissoon Date: Tue, 13 May 2014 09:54:52 +0530 Subject: [PATCH] Statistician - Added some handling for 0 based values --- src/kademlia/Statistician.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/kademlia/Statistician.java b/src/kademlia/Statistician.java index b8f27f4..c875e2d 100644 --- a/src/kademlia/Statistician.java +++ b/src/kademlia/Statistician.java @@ -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));