Skip to content

Commit 7126929

Browse files
committed
Review fixes, make constructor private
1 parent d47b3d6 commit 7126929

File tree

3 files changed

+14
-19
lines changed

3 files changed

+14
-19
lines changed

libs/exponential-histogram/src/main/java/org/elasticsearch/exponentialhistogram/ExponentialHistogram.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,14 @@ static ExponentialHistogram empty() {
206206
return EmptyExponentialHistogram.INSTANCE;
207207
}
208208

209-
static ExponentialHistogramBuilder builder(ExponentialHistogramCircuitBreaker breaker) {
210-
return new ExponentialHistogramBuilder(breaker);
209+
/**
210+
* Create a builder for an exponential histogram with the given scale.
211+
* @param scale the scale of the histogram to build
212+
* @param breaker the circuit breaker to use
213+
* @return a new builder
214+
*/
215+
static ExponentialHistogramBuilder builder(int scale, ExponentialHistogramCircuitBreaker breaker) {
216+
return new ExponentialHistogramBuilder(scale, breaker);
211217
}
212218

213219
/**

libs/exponential-histogram/src/main/java/org/elasticsearch/exponentialhistogram/ExponentialHistogramBuilder.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class ExponentialHistogramBuilder {
3333

3434
private final ExponentialHistogramCircuitBreaker breaker;
3535

36-
private int scale;
36+
private final int scale;
3737
private ZeroBucket zeroBucket = ZeroBucket.minimalEmpty();
3838
private Double sum;
3939
private Double min;
@@ -42,18 +42,9 @@ public class ExponentialHistogramBuilder {
4242
private final TreeMap<Long, Long> negativeBuckets = new TreeMap<>();
4343
private final TreeMap<Long, Long> positiveBuckets = new TreeMap<>();
4444

45-
public ExponentialHistogramBuilder(ExponentialHistogramCircuitBreaker breaker) {
45+
ExponentialHistogramBuilder(int scale, ExponentialHistogramCircuitBreaker breaker) {
4646
this.breaker = breaker;
47-
}
48-
49-
/**
50-
* Sets the scale of the histogram.
51-
* @param scale the scale to set
52-
* @return the builder
53-
*/
54-
public ExponentialHistogramBuilder scale(int scale) {
5547
this.scale = scale;
56-
return this;
5748
}
5849

5950
public ExponentialHistogramBuilder zeroBucket(ZeroBucket zeroBucket) {

libs/exponential-histogram/src/test/java/org/elasticsearch/exponentialhistogram/ExponentialHistogramBuilderTests.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ public class ExponentialHistogramBuilderTests extends ExponentialHistogramTestCa
2929

3030
public void testBuildWithAllFieldsSet() {
3131
ZeroBucket zeroBucket = ZeroBucket.create(1, 2);
32-
ExponentialHistogramBuilder builder = ExponentialHistogram.builder(breaker())
33-
.scale(3)
32+
ExponentialHistogramBuilder builder = ExponentialHistogram.builder(3, breaker())
3433
.zeroBucket(zeroBucket)
3534
.sum(100.0)
3635
.min(1.0)
@@ -53,8 +52,7 @@ public void testBuildWithAllFieldsSet() {
5352
}
5453

5554
public void testBuildWithEstimation() {
56-
ExponentialHistogramBuilder builder = ExponentialHistogram.builder(breaker())
57-
.scale(0)
55+
ExponentialHistogramBuilder builder = ExponentialHistogram.builder(0, breaker())
5856
.addPositiveBucket(0, 1)
5957
.addPositiveBucket(1, 1)
6058
.addNegativeBucket(0, 4);
@@ -71,13 +69,13 @@ public void testBuildWithEstimation() {
7169
}
7270

7371
public void testAddDuplicatePositiveBucketThrows() {
74-
ExponentialHistogramBuilder builder = ExponentialHistogram.builder(breaker());
72+
ExponentialHistogramBuilder builder = ExponentialHistogram.builder(0, breaker());
7573
builder.addPositiveBucket(1, 10);
7674
expectThrows(IllegalArgumentException.class, () -> builder.addPositiveBucket(1, 5));
7775
}
7876

7977
public void testAddDuplicateNegativeBucketThrows() {
80-
ExponentialHistogramBuilder builder = ExponentialHistogram.builder(breaker());
78+
ExponentialHistogramBuilder builder = ExponentialHistogram.builder(0, breaker());
8179
builder.addNegativeBucket(-1, 10);
8280
expectThrows(IllegalArgumentException.class, () -> builder.addNegativeBucket(-1, 5));
8381
}

0 commit comments

Comments
 (0)