diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b039e64c..b571a3a96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ - Query and BatchPoints do not mandate a database name, in which case the InfluxDB database would be used [Issue #548](https://github.com/influxdata/influxdb-java/issues/548) +- Add BatchPoints.Builder.points(Collection) + [Issue #451](https://github.com/influxdata/influxdb-java/issues/451) ## 2.14 [2018-10-12] diff --git a/src/main/java/org/influxdb/dto/BatchPoints.java b/src/main/java/org/influxdb/dto/BatchPoints.java index 894e9ac46..8bc033199 100644 --- a/src/main/java/org/influxdb/dto/BatchPoints.java +++ b/src/main/java/org/influxdb/dto/BatchPoints.java @@ -2,6 +2,7 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Objects; @@ -107,7 +108,7 @@ public Builder point(final Point pointToAdd) { /** * Add a set of Points to this set of points. * - * @param pointsToAdd the List if Points to add + * @param pointsToAdd the Points to add * @return the Builder instance */ public Builder points(final Point... pointsToAdd) { @@ -115,6 +116,17 @@ public Builder points(final Point... pointsToAdd) { return this; } + /** + * Add a set of Points to this set of points. + * + * @param pointsToAdd the Points to add + * @return the Builder instance + */ + public Builder points(final Collection pointsToAdd) { + this.points.addAll(pointsToAdd); + return this; + } + /** * Set the ConsistencyLevel to use. If not given it defaults to {@link ConsistencyLevel#ONE} * diff --git a/src/test/java/org/influxdb/dto/BatchPointTest.java b/src/test/java/org/influxdb/dto/BatchPointTest.java index 3291e8856..236e7165d 100644 --- a/src/test/java/org/influxdb/dto/BatchPointTest.java +++ b/src/test/java/org/influxdb/dto/BatchPointTest.java @@ -1,9 +1,13 @@ package org.influxdb.dto; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -106,4 +110,15 @@ public void emptyDatabase() throws Exception { BatchPoints b = BatchPoints.builder().build(); assertNull(b.getDatabase()); } + + @Test + public void pointsCollection() { + Point p1 = Point.measurement("something").addField("one", 1).build(); + Point p2 = Point.measurement("something2").addField("two", 2).build(); + Collection points = Arrays.asList(p1, p2); + BatchPoints b = BatchPoints.builder().points(points).build(); + List returned = b.getPoints(); + assertNotNull(returned); + assertEquals(2, returned.size()); + } }