Skip to content

Commit

Permalink
- Changed Average.toString(): better legibility
Browse files Browse the repository at this point in the history
  • Loading branch information
belaban committed Apr 8, 2024
1 parent ddd4d64 commit eca40d5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/org/jgroups/util/Average.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.io.IOException;
import java.util.concurrent.TimeUnit;

import static org.jgroups.util.Util.printTime;

/**
* Maintains an approximation of an average of values. Done by keeping track of the number of samples, and computing
* the new average as (count*avg + new-sample) / ++count. We reset the count if count*avg would lead to an overflow.<p/>
Expand Down Expand Up @@ -65,7 +67,13 @@ public void clear() {
}

public String toString() {
return String.format("%,.2f %s", avg, unit == null? "" : Util.suffix(unit));
return unit != null? toString(unit) : String.format("%,.2f %s", avg, unit == null? "" : Util.suffix(unit));
}

public String toString(TimeUnit u) {
if(count == 0)
return "n/a";
return String.format("%s", printTime(getAverage(), u));
}

@Override
Expand Down
1 change: 1 addition & 0 deletions src/org/jgroups/util/AverageMinMax.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public String percentiles() {

public String toString() {
return count == 0? "n/a" :
unit != null? toString(unit) :
String.format("min/avg/max=%,d/%,.2f/%,d%s",
min, getAverage(), max, unit == null? "" : " " + Util.suffix(unit));
}
Expand Down

0 comments on commit eca40d5

Please sign in to comment.