Skip to content

Commit

Permalink
Rename DoubleFormat.decimalOrWhole() (#673)
Browse files Browse the repository at this point in the history
Co-Authored-By: Tommy Ludwig <[email protected]>
  • Loading branch information
izeye and shakuzen committed Jun 17, 2019
1 parent 2ff60fc commit 19047f1
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ protected io.micrometer.core.instrument.DistributionSummary newDistributionSumma
percentile -> Tags.concat(id.getTags(), "percentile", DoubleFormat.decimalOrNan(percentile.percentile())),
ValueAtPercentile::value,
bucket -> id.getName(),
bucket -> Tags.concat(id.getTags(), "sla", DoubleFormat.decimalOrWhole(bucket.bucket())));
bucket -> Tags.concat(id.getTags(), "sla", DoubleFormat.wholeOrDecimal(bucket.bucket())));

return summary;
}
Expand All @@ -150,7 +150,7 @@ protected Timer newTimer(Meter.Id id, DistributionStatisticConfig distributionSt
percentile -> Tags.concat(id.getTags(), "percentile", DoubleFormat.decimalOrNan(percentile.percentile())),
percentile -> percentile.value(timer.baseTimeUnit()),
bucket -> id.getName(),
bucket -> Tags.concat(id.getTags(), "sla", DoubleFormat.decimalOrWhole(bucket.bucket(timer.baseTimeUnit()))));
bucket -> Tags.concat(id.getTags(), "sla", DoubleFormat.wholeOrDecimal(bucket.bucket(timer.baseTimeUnit()))));

return timer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ private String event(Meter.Id id, Iterable<Tag> extraTags, Attribute... attribut
}

return "{\"eventType\":\"" + getConventionName(id) + "\"" +
Arrays.stream(attributes).map(attr -> ",\"" + attr.getName() + "\":" + DoubleFormat.decimalOrWhole(attr.getValue().doubleValue()))
Arrays.stream(attributes).map(attr -> ",\"" + attr.getName() + "\":" + DoubleFormat.wholeOrDecimal(attr.getValue().doubleValue()))
.collect(Collectors.joining("")) + tagsJson.toString() + "}";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public static HistogramGauges registerWithCommonFormat(Timer timer, MeterRegistr
bucket -> id.getName() + ".histogram",
// We look for Long.MAX_VALUE to ensure a sensible tag on our +Inf bucket
bucket -> Tags.concat(id.getTags(), "le", bucket.bucket() != Long.MAX_VALUE
? DoubleFormat.decimalOrWhole(bucket.bucket(timer.baseTimeUnit())) : "+Inf"));
? DoubleFormat.wholeOrDecimal(bucket.bucket(timer.baseTimeUnit())) : "+Inf"));
}

public static HistogramGauges registerWithCommonFormat(DistributionSummary summary, MeterRegistry registry) {
Expand All @@ -62,7 +62,7 @@ public static HistogramGauges registerWithCommonFormat(DistributionSummary summa
bucket -> id.getName() + ".histogram",
// We look for Long.MAX_VALUE to ensure a sensible tag on our +Inf bucket
bucket -> Tags.concat(id.getTags(), "le", bucket.bucket() != Long.MAX_VALUE
? DoubleFormat.decimalOrWhole(bucket.bucket()) : "+Inf"));
? DoubleFormat.wholeOrDecimal(bucket.bucket()) : "+Inf"));
}

public static HistogramGauges register(HistogramSupport meter, MeterRegistry registry,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,19 @@ public static String decimalOrNan(double d) {
* @param d Number to format.
* @return A stringified version of the number that only uses a decimal representation if the number is not
* whole.
* @deprecated since 1.0.11 in favour of {@link #wholeOrDecimal(double)}
*/
@Deprecated
public static String decimalOrWhole(double d) {
return WHOLE_OR_DECIMAL.get().format(d);
}

/**
* @param d Number to format.
* @return A stringified version of the number that only uses a decimal representation if the number is not
* whole.
*/
public static String wholeOrDecimal(double d) {
return WHOLE_OR_DECIMAL.get().format(d);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ void decimalOrNan() {
}

@Test
void decimalOrWhole() {
assertThat(DoubleFormat.decimalOrWhole(123456.1234567)).isEqualTo("123456.123457");
assertThat(DoubleFormat.decimalOrWhole(1)).isEqualTo("1");
void wholeOrDecimal() {
assertThat(DoubleFormat.wholeOrDecimal(123456.1234567)).isEqualTo("123456.123457");
assertThat(DoubleFormat.wholeOrDecimal(1)).isEqualTo("1");
}

@Issue("#539")
@Test
void noScientificNotation() {
assertThat(DoubleFormat.decimalOrWhole(4.6875392E7)).isEqualTo("46875392");
assertThat(DoubleFormat.wholeOrDecimal(4.6875392E7)).isEqualTo("46875392");
assertThat(DoubleFormat.decimalOrNan(4.6875392E7)).isEqualTo("46875392");
}
}
}

0 comments on commit 19047f1

Please sign in to comment.