Skip to content

Commit 997992e

Browse files
author
kub
committed
allow to figure out, whether the Point.Builder has any fields
since the build mehtod contains validation for fields emptiness, there should be also way, how to figure out, whether the Builder contains any fields (to prevent the build method from throwing an exception)
1 parent 77b5f37 commit 997992e

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/main/java/org/influxdb/dto/Point.java

+9
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,15 @@ public Builder time(final long timeToSet, final TimeUnit precisionToSet) {
187187
return this;
188188
}
189189

190+
/**
191+
* Does this builder contain any fields?
192+
*
193+
* @return true, if the builder contains any fields, false otherwise.
194+
*/
195+
public boolean hasFields() {
196+
return !fields.isEmpty();
197+
}
198+
190199
/**
191200
* Create a new Point.
192201
*

src/test/java/org/influxdb/dto/PointTest.java

+9
Original file line numberDiff line numberDiff line change
@@ -330,4 +330,13 @@ public void testUnEquals() throws Exception {
330330
// THEN equals returns true
331331
assertThat(equals).isEqualTo(false);
332332
}
333+
334+
@Test
335+
public void testBuilderHasFields() {
336+
Point.Builder pointBuilder = Point.measurement("nulltest").time(1, TimeUnit.NANOSECONDS).tag("foo", "bar");
337+
assertThat(pointBuilder.hasFields()).isFalse();
338+
339+
pointBuilder.addField("testfield", 256);
340+
assertThat(pointBuilder.hasFields()).isTrue();
341+
}
333342
}

0 commit comments

Comments
 (0)