Skip to content

Commit

Permalink
allow to figure out, whether the Point.Builder has any fields
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
kub committed Mar 25, 2018
1 parent 77b5f37 commit 997992e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/main/java/org/influxdb/dto/Point.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,15 @@ public Builder time(final long timeToSet, final TimeUnit precisionToSet) {
return this;
}

/**
* Does this builder contain any fields?
*
* @return true, if the builder contains any fields, false otherwise.
*/
public boolean hasFields() {
return !fields.isEmpty();
}

/**
* Create a new Point.
*
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/org/influxdb/dto/PointTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -330,4 +330,13 @@ public void testUnEquals() throws Exception {
// THEN equals returns true
assertThat(equals).isEqualTo(false);
}

@Test
public void testBuilderHasFields() {
Point.Builder pointBuilder = Point.measurement("nulltest").time(1, TimeUnit.NANOSECONDS).tag("foo", "bar");
assertThat(pointBuilder.hasFields()).isFalse();

pointBuilder.addField("testfield", 256);
assertThat(pointBuilder.hasFields()).isTrue();
}
}

0 comments on commit 997992e

Please sign in to comment.