You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2019/12/25 22:12:14 UTC

[commons-csv] branch master updated: Add CSVRecord.isSet(int) method (#52)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-csv.git


The following commit(s) were added to refs/heads/master by this push:
     new 4033a01  Add CSVRecord.isSet(int) method (#52)
4033a01 is described below

commit 4033a0199e2d0086afeeb07870a687e3b0caf4bf
Author: 0x100 <ly...@gmail.com>
AuthorDate: Thu Dec 26 01:12:05 2019 +0300

    Add CSVRecord.isSet(int) method (#52)
    
    * Add CSVRecord.isSet(int) method
    
    * Remove unnecessary unboxing
    
    * Revert: Remove unnecessary unboxing
---
 src/main/java/org/apache/commons/csv/CSVRecord.java     | 11 +++++++++++
 src/test/java/org/apache/commons/csv/CSVRecordTest.java | 12 +++++++++++-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/csv/CSVRecord.java b/src/main/java/org/apache/commons/csv/CSVRecord.java
index b1b3f99..e063edc 100644
--- a/src/main/java/org/apache/commons/csv/CSVRecord.java
+++ b/src/main/java/org/apache/commons/csv/CSVRecord.java
@@ -215,6 +215,17 @@ public final class CSVRecord implements Serializable, Iterable<String> {
     }
 
     /**
+     * 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.
      *
      * @return an iterator over the values of this record.
diff --git a/src/test/java/org/apache/commons/csv/CSVRecordTest.java b/src/test/java/org/apache/commons/csv/CSVRecordTest.java
index 6831002..06e771c 100644
--- a/src/test/java/org/apache/commons/csv/CSVRecordTest.java
+++ b/src/test/java/org/apache/commons/csv/CSVRecordTest.java
@@ -134,13 +134,23 @@ 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;
         for (final String value : record) {