Skip to content

Commit 4033a01

Browse files
0x100garydgregory
authored andcommitted
Add CSVRecord.isSet(int) method (apache#52)
* Add CSVRecord.isSet(int) method * Remove unnecessary unboxing * Revert: Remove unnecessary unboxing
1 parent 129641e commit 4033a01

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

src/main/java/org/apache/commons/csv/CSVRecord.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,17 @@ public boolean isSet(final String name) {
214214
return isMapped(name) && getHeaderMapRaw().get(name).intValue() < values.length;
215215
}
216216

217+
/**
218+
* Checks whether a column with given index has a value.
219+
*
220+
* @param i
221+
* a column index (0-based)
222+
* @return whether a column with given index has a value
223+
*/
224+
public boolean isSet(final int i) {
225+
return 0 <= i && i < values.length;
226+
}
227+
217228
/**
218229
* Returns an iterator over the values of this record.
219230
*

src/test/java/org/apache/commons/csv/CSVRecordTest.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,22 @@ public void testIsMapped() {
134134
}
135135

136136
@Test
137-
public void testIsSet() {
137+
public void testIsSetString() {
138138
assertFalse(record.isSet("first"));
139139
assertTrue(recordWithHeader.isSet("first"));
140140
assertFalse(recordWithHeader.isSet("fourth"));
141141
}
142142

143+
@Test
144+
public void testIsSetInt() {
145+
assertFalse(record.isSet(-1));
146+
assertTrue(record.isSet(0));
147+
assertTrue(record.isSet(2));
148+
assertFalse(record.isSet(3));
149+
assertTrue(recordWithHeader.isSet(1));
150+
assertFalse(recordWithHeader.isSet(1000));
151+
}
152+
143153
@Test
144154
public void testIterator() {
145155
int i = 0;

0 commit comments

Comments
 (0)