Skip to content

Commit 30aecd9

Browse files
committed
Move validation to setter
Signed-off-by: Jean Kim <[email protected]>
1 parent ad4eaec commit 30aecd9

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

server/src/main/java/org/opensearch/index/translog/TranslogStats.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -193,26 +193,41 @@ public static class Builder {
193193
public Builder() {}
194194

195195
public Builder numberOfOperations(int operations) {
196+
if (operations < 0) {
197+
throw new IllegalArgumentException("numberOfOperations must be >= 0");
198+
}
196199
this.numberOfOperations = operations;
197200
return this;
198201
}
199202

200203
public Builder translogSizeInBytes(long size) {
204+
if (size < 0) {
205+
throw new IllegalArgumentException("translogSizeInBytes must be >= 0");
206+
}
201207
this.translogSizeInBytes = size;
202208
return this;
203209
}
204210

205211
public Builder uncommittedOperations(int operations) {
212+
if (operations < 0) {
213+
throw new IllegalArgumentException("uncommittedOperations must be >= 0");
214+
}
206215
this.uncommittedOperations = operations;
207216
return this;
208217
}
209218

210219
public Builder uncommittedSizeInBytes(long bytes) {
220+
if (bytes < 0) {
221+
throw new IllegalArgumentException("uncommittedSizeInBytes must be >= 0");
222+
}
211223
this.uncommittedSizeInBytes = bytes;
212224
return this;
213225
}
214226

215227
public Builder earliestLastModifiedAge(long age) {
228+
if (age < 0) {
229+
throw new IllegalArgumentException("earliestLastModifiedAge must be >= 0");
230+
}
216231
this.earliestLastModifiedAge = age;
217232
return this;
218233
}
@@ -222,21 +237,6 @@ public Builder earliestLastModifiedAge(long age) {
222237
* @return A new TranslogStats instance.
223238
*/
224239
public TranslogStats build() {
225-
if (numberOfOperations < 0) {
226-
throw new IllegalArgumentException("numberOfOperations must be >= 0");
227-
}
228-
if (translogSizeInBytes < 0) {
229-
throw new IllegalArgumentException("translogSizeInBytes must be >= 0");
230-
}
231-
if (uncommittedOperations < 0) {
232-
throw new IllegalArgumentException("uncommittedOperations must be >= 0");
233-
}
234-
if (uncommittedSizeInBytes < 0) {
235-
throw new IllegalArgumentException("uncommittedSizeInBytes must be >= 0");
236-
}
237-
if (earliestLastModifiedAge < 0) {
238-
throw new IllegalArgumentException("earliestLastModifiedAge must be >= 0");
239-
}
240240
return new TranslogStats(this);
241241
}
242242
}

0 commit comments

Comments
 (0)