Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BatchPoints.Builder.points(Collection) #561

Merged
merged 3 commits into from
Jan 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
14 changes: 13 additions & 1 deletion src/main/java/org/influxdb/dto/BatchPoints.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -107,14 +108,25 @@ 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) {
this.points.addAll(Arrays.asList(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<Point> pointsToAdd) {
this.points.addAll(pointsToAdd);
return this;
}

/**
* Set the ConsistencyLevel to use. If not given it defaults to {@link ConsistencyLevel#ONE}
*
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/org/influxdb/dto/BatchPointTest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<Point> points = Arrays.asList(p1, p2);
BatchPoints b = BatchPoints.builder().points(points).build();
List<Point> returned = b.getPoints();
assertNotNull(returned);
assertEquals(2, returned.size());
}
}