|
8 | 8 | import java.text.ParseException; |
9 | 9 | import java.util.ArrayList; |
10 | 10 | import java.util.Arrays; |
| 11 | +import java.util.Collection; |
11 | 12 | import java.util.HashMap; |
12 | 13 | import java.util.HashSet; |
13 | 14 | import java.util.List; |
@@ -59,42 +60,35 @@ public ReservedColumnException(String column) { |
59 | 60 | private final TreeMap<Long, Map<String, Object>> rows = new TreeMap<Long, Map<String, Object>>(); |
60 | 61 |
|
61 | 62 | /** |
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. |
63 | 64 | * Note: Duplicates will be removed and a warning will be logged. |
64 | 65 | * |
65 | 66 | * @param columns Set of field names to track in this batch. |
66 | 67 | */ |
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); |
73 | 70 | 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 | + } |
74 | 75 | } |
75 | 76 |
|
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) { |
83 | 82 | for (String c : columns) { |
| 83 | + if (c == null || c.isEmpty()) { |
| 84 | + throw new IllegalArgumentException("Column cannot be null or empty string."); |
| 85 | + } |
84 | 86 | if (Arrays.asList(RESERVED_COLS).contains(c.toLowerCase())) { |
85 | 87 | throw new ReservedColumnException(c); |
86 | 88 | } |
87 | 89 | } |
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 | | - } |
93 | 90 | } |
94 | 91 |
|
95 | | - public DataStore(String... columns) { |
96 | | - this(Arrays.asList(columns)); |
97 | | - } |
98 | 92 |
|
99 | 93 | /** |
100 | 94 | * Add a data row to the batch at a particular timestamp. |
|
0 commit comments