Add CSVRecord.isSet(int) method (#52)

* Add CSVRecord.isSet(int) method

* Remove unnecessary unboxing

* Revert: Remove unnecessary unboxing
This commit is contained in:
0x100 2019-12-26 01:12:05 +03:00 committed by Gary Gregory
parent 129641ead4
commit 4033a0199e
2 changed files with 22 additions and 1 deletions

View File

@ -214,6 +214,17 @@ public final class CSVRecord implements Serializable, Iterable<String> {
return isMapped(name) && getHeaderMapRaw().get(name).intValue() < values.length;
}
/**
* Checks whether a column with given index has a value.
*
* @param i
* a column index (0-based)
* @return whether a column with given index has a value
*/
public boolean isSet(final int i) {
return 0 <= i && i < values.length;
}
/**
* Returns an iterator over the values of this record.
*

View File

@ -134,12 +134,22 @@ public class CSVRecordTest {
}
@Test
public void testIsSet() {
public void testIsSetString() {
assertFalse(record.isSet("first"));
assertTrue(recordWithHeader.isSet("first"));
assertFalse(recordWithHeader.isSet("fourth"));
}
@Test
public void testIsSetInt() {
assertFalse(record.isSet(-1));
assertTrue(record.isSet(0));
assertTrue(record.isSet(2));
assertFalse(record.isSet(3));
assertTrue(recordWithHeader.isSet(1));
assertFalse(recordWithHeader.isSet(1000));
}
@Test
public void testIterator() {
int i = 0;