Skip to content

Commit 0e1c006

Browse files
committed
Reject empty series names.
1 parent 076217a commit 0e1c006

2 files changed

Lines changed: 26 additions & 22 deletions

File tree

src/main/java/com/iobeam/api/resource/DataStore.java

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.text.ParseException;
99
import java.util.ArrayList;
1010
import java.util.Arrays;
11+
import java.util.Collection;
1112
import java.util.HashMap;
1213
import java.util.HashSet;
1314
import java.util.List;
@@ -59,42 +60,35 @@ public ReservedColumnException(String column) {
5960
private final TreeMap<Long, Map<String, Object>> rows = new TreeMap<Long, Map<String, Object>>();
6061

6162
/**
62-
* Constructs a DataStore, using the list to construct a _set_ of columns.
63+
* Constructs a DataStore, using a collection to construct a _set_ of columns.
6364
* Note: Duplicates will be removed and a warning will be logged.
6465
*
6566
* @param columns Set of field names to track in this batch.
6667
*/
67-
public DataStore(Set<String> columns) {
68-
for (String c : columns) {
69-
if (Arrays.asList(RESERVED_COLS).contains(c.toLowerCase())) {
70-
throw new ReservedColumnException(c);
71-
}
72-
}
68+
public DataStore(Collection<String> columns) {
69+
checkColumns(columns);
7370
this.columns = new TreeSet<String>(columns);
71+
if (columns.size() != this.columns.size()) {
72+
logger.warning("Size mismatch in provided list of columns and resulting set of " +
73+
"columns; list may have contained duplicates.");
74+
}
7475
}
7576

76-
/**
77-
* Constructs a DataStore, using the list to construct a _set_ of columns.
78-
* Note: Duplicates will be removed and a warning will be logged.
79-
*
80-
* @param columns List of field names to track in this batch.
81-
*/
82-
public DataStore(List<String> columns) {
77+
public DataStore(String... columns) {
78+
this(Arrays.asList(columns));
79+
}
80+
81+
private void checkColumns(Collection<String> columns) {
8382
for (String c : columns) {
83+
if (c == null || c.isEmpty()) {
84+
throw new IllegalArgumentException("Column cannot be null or empty string.");
85+
}
8486
if (Arrays.asList(RESERVED_COLS).contains(c.toLowerCase())) {
8587
throw new ReservedColumnException(c);
8688
}
8789
}
88-
this.columns = new TreeSet<String>(columns);
89-
if (columns.size() != this.columns.size()) {
90-
logger.warning("Size mismatch in provided list of columns and resulting set of columns;" +
91-
" list may have contained duplicates.");
92-
}
9390
}
9491

95-
public DataStore(String... columns) {
96-
this(Arrays.asList(columns));
97-
}
9892

9993
/**
10094
* Add a data row to the batch at a particular timestamp.

src/test/java/com/iobeam/api/resource/DataStoreTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,17 @@ public void testReservedColumnDifferentCase() throws Exception {
163163
ds.clear();
164164
}
165165

166+
@Test(expected = IllegalArgumentException.class)
167+
public void testNullColumn() throws Exception {
168+
DataStore ds = new DataStore("good", null);
169+
ds.clear();
170+
}
166171

172+
@Test(expected = IllegalArgumentException.class)
173+
public void testEmptyColumn() throws Exception {
174+
DataStore ds = new DataStore("good", "");
175+
ds.clear();
176+
}
167177

168178
@Test
169179
public void testToJson() throws Exception {

0 commit comments

Comments
 (0)