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 2013/08/01 23:57:46 UTC

svn commit: r1509450 - in /commons/proper/csv/trunk/src: main/java/org/apache/commons/csv/CSVRecord.java test/java/org/apache/commons/csv/CSVRecordIntTest.java

Author: ggregory
Date: Thu Aug  1 21:57:46 2013
New Revision: 1509450

URL: http://svn.apache.org/r1509450
Log:
Add CSVRecord#getInt(String) API and tests.

Added:
    commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVRecordIntTest.java   (with props)
Modified:
    commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVRecord.java

Modified: commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVRecord.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVRecord.java?rev=1509450&r1=1509449&r2=1509450&view=diff
==============================================================================
--- commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVRecord.java (original)
+++ commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVRecord.java Thu Aug  1 21:57:46 2013
@@ -146,6 +146,23 @@ public class CSVRecord implements Serial
      *             if the record is inconsistent
      * @see #isConsistent()
      */
+    public int getInt(String name) {
+        String s = this.get(name);
+        return s != null ? Integer.parseInt(s) : 0;
+    }
+
+    /**
+     * Returns a value by name.
+     *
+     * @param name
+     *            the name of the column to be retrieved.
+     * @return the column value
+     * @throws IllegalStateException
+     *             if no header mapping was provided
+     * @throws IllegalArgumentException
+     *             if the record is inconsistent
+     * @see #isConsistent()
+     */
     public long getLong(String name) {
         String s = this.get(name);
         return s != null ? Long.parseLong(s) : 0;

Added: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVRecordIntTest.java
URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVRecordIntTest.java?rev=1509450&view=auto
==============================================================================
--- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVRecordIntTest.java (added)
+++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVRecordIntTest.java Thu Aug  1 21:57:46 2013
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.csv;
+
+import java.io.IOException;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class CSVRecordIntTest {
+
+    private CSVRecord record;
+
+    /**
+     * @return
+     * @throws IOException
+     */
+    private CSVRecord createTestRecord() throws IOException {
+        String csv = "A, B, C, D, E\n-1, 0, 1, " + Integer.MAX_VALUE + ", " + Integer.MIN_VALUE;
+        CSVRecord record = CSVParser.parseString(csv, CSVFormat.DEFAULT.withHeader().withIgnoreSurroundingSpaces(true))
+                .iterator().next();
+        return record;
+    }
+
+    @Before
+    public void setUp() throws IOException {
+        this.record = createTestRecord();
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testGetIntegerByMissingString() {
+        Assert.assertEquals(null, Integer.valueOf(record.getInt("ABSENT")));
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testGetIntegerByNullString() {
+        Assert.assertEquals(null, Integer.valueOf(record.getInt(null)));
+    }
+
+    @Test
+    public void testGetIntegerByString() {
+        Assert.assertEquals(-1, record.getInt("A"));
+        Assert.assertEquals(0, record.getInt("B"));
+        Assert.assertEquals(1, record.getInt("C"));
+        Assert.assertEquals(Integer.MAX_VALUE, record.getInt("D"));
+        Assert.assertEquals(Integer.MIN_VALUE, record.getInt("E"));
+    }
+
+}

Propchange: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVRecordIntTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVRecordIntTest.java
------------------------------------------------------------------------------
    svn:keywords = Id



Re: svn commit: r1509450 - in /commons/proper/csv/trunk/src: main/java/org/apache/commons/csv/CSVRecord.java test/java/org/apache/commons/csv/CSVRecordIntTest.java

Posted by James Carman <ja...@carmanconsulting.com>.
How about we put it to a vote?  Would you withdraw your veto if a
majority votes against it?

On Thu, Aug 1, 2013 at 7:55 PM, sebb <se...@gmail.com> wrote:
> On 2 August 2013 00:44, James Carman <ja...@carmanconsulting.com> wrote:
>> You are -1ing a code modification, which means this counts as a veto.
>> Are you sure you want to veto this?
>
> Yes.
>
> We don't have agreement that CSV should include these methods.
>
>> On Thu, Aug 1, 2013 at 7:28 PM, sebb <se...@gmail.com> wrote:
>>> On 1 August 2013 22:57,  <gg...@apache.org> wrote:
>>>> Author: ggregory
>>>> Date: Thu Aug  1 21:57:46 2013
>>>> New Revision: 1509450
>>>>
>>>> URL: http://svn.apache.org/r1509450
>>>> Log:
>>>> Add CSVRecord#getInt(String) API and tests.
>>>
>>> -1
>>>
>>> I think this is out of scope for CSV.
>>>
>>>> Added:
>>>>     commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVRecordIntTest.java   (with props)
>>>> Modified:
>>>>     commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVRecord.java
>>>>
>>>> Modified: commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVRecord.java
>>>> URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVRecord.java?rev=1509450&r1=1509449&r2=1509450&view=diff
>>>> ==============================================================================
>>>> --- commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVRecord.java (original)
>>>> +++ commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVRecord.java Thu Aug  1 21:57:46 2013
>>>> @@ -146,6 +146,23 @@ public class CSVRecord implements Serial
>>>>       *             if the record is inconsistent
>>>>       * @see #isConsistent()
>>>>       */
>>>> +    public int getInt(String name) {
>>>> +        String s = this.get(name);
>>>> +        return s != null ? Integer.parseInt(s) : 0;
>>>> +    }
>>>> +
>>>> +    /**
>>>> +     * Returns a value by name.
>>>> +     *
>>>> +     * @param name
>>>> +     *            the name of the column to be retrieved.
>>>> +     * @return the column value
>>>> +     * @throws IllegalStateException
>>>> +     *             if no header mapping was provided
>>>> +     * @throws IllegalArgumentException
>>>> +     *             if the record is inconsistent
>>>> +     * @see #isConsistent()
>>>> +     */
>>>>      public long getLong(String name) {
>>>>          String s = this.get(name);
>>>>          return s != null ? Long.parseLong(s) : 0;
>>>>
>>>> Added: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVRecordIntTest.java
>>>> URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVRecordIntTest.java?rev=1509450&view=auto
>>>> ==============================================================================
>>>> --- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVRecordIntTest.java (added)
>>>> +++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVRecordIntTest.java Thu Aug  1 21:57:46 2013
>>>> @@ -0,0 +1,64 @@
>>>> +/*
>>>> + * Licensed to the Apache Software Foundation (ASF) under one or more
>>>> + * contributor license agreements.  See the NOTICE file distributed with
>>>> + * this work for additional information regarding copyright ownership.
>>>> + * The ASF licenses this file to You under the Apache License, Version 2.0
>>>> + * (the "License"); you may not use this file except in compliance with
>>>> + * the License.  You may obtain a copy of the License at
>>>> + *
>>>> + *      http://www.apache.org/licenses/LICENSE-2.0
>>>> + *
>>>> + * Unless required by applicable law or agreed to in writing, software
>>>> + * distributed under the License is distributed on an "AS IS" BASIS,
>>>> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
>>>> + * See the License for the specific language governing permissions and
>>>> + * limitations under the License.
>>>> + */
>>>> +package org.apache.commons.csv;
>>>> +
>>>> +import java.io.IOException;
>>>> +
>>>> +import org.junit.Assert;
>>>> +import org.junit.Before;
>>>> +import org.junit.Test;
>>>> +
>>>> +public class CSVRecordIntTest {
>>>> +
>>>> +    private CSVRecord record;
>>>> +
>>>> +    /**
>>>> +     * @return
>>>> +     * @throws IOException
>>>> +     */
>>>> +    private CSVRecord createTestRecord() throws IOException {
>>>> +        String csv = "A, B, C, D, E\n-1, 0, 1, " + Integer.MAX_VALUE + ", " + Integer.MIN_VALUE;
>>>> +        CSVRecord record = CSVParser.parseString(csv, CSVFormat.DEFAULT.withHeader().withIgnoreSurroundingSpaces(true))
>>>> +                .iterator().next();
>>>> +        return record;
>>>> +    }
>>>> +
>>>> +    @Before
>>>> +    public void setUp() throws IOException {
>>>> +        this.record = createTestRecord();
>>>> +    }
>>>> +
>>>> +    @Test(expected = IllegalArgumentException.class)
>>>> +    public void testGetIntegerByMissingString() {
>>>> +        Assert.assertEquals(null, Integer.valueOf(record.getInt("ABSENT")));
>>>> +    }
>>>> +
>>>> +    @Test(expected = IllegalArgumentException.class)
>>>> +    public void testGetIntegerByNullString() {
>>>> +        Assert.assertEquals(null, Integer.valueOf(record.getInt(null)));
>>>> +    }
>>>> +
>>>> +    @Test
>>>> +    public void testGetIntegerByString() {
>>>> +        Assert.assertEquals(-1, record.getInt("A"));
>>>> +        Assert.assertEquals(0, record.getInt("B"));
>>>> +        Assert.assertEquals(1, record.getInt("C"));
>>>> +        Assert.assertEquals(Integer.MAX_VALUE, record.getInt("D"));
>>>> +        Assert.assertEquals(Integer.MIN_VALUE, record.getInt("E"));
>>>> +    }
>>>> +
>>>> +}
>>>>
>>>> Propchange: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVRecordIntTest.java
>>>> ------------------------------------------------------------------------------
>>>>     svn:eol-style = native
>>>>
>>>> Propchange: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVRecordIntTest.java
>>>> ------------------------------------------------------------------------------
>>>>     svn:keywords = Id
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>>> For additional commands, e-mail: dev-help@commons.apache.org
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: svn commit: r1509450 - in /commons/proper/csv/trunk/src: main/java/org/apache/commons/csv/CSVRecord.java test/java/org/apache/commons/csv/CSVRecordIntTest.java

Posted by sebb <se...@gmail.com>.
On 2 August 2013 00:44, James Carman <ja...@carmanconsulting.com> wrote:
> You are -1ing a code modification, which means this counts as a veto.
> Are you sure you want to veto this?

Yes.

We don't have agreement that CSV should include these methods.

> On Thu, Aug 1, 2013 at 7:28 PM, sebb <se...@gmail.com> wrote:
>> On 1 August 2013 22:57,  <gg...@apache.org> wrote:
>>> Author: ggregory
>>> Date: Thu Aug  1 21:57:46 2013
>>> New Revision: 1509450
>>>
>>> URL: http://svn.apache.org/r1509450
>>> Log:
>>> Add CSVRecord#getInt(String) API and tests.
>>
>> -1
>>
>> I think this is out of scope for CSV.
>>
>>> Added:
>>>     commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVRecordIntTest.java   (with props)
>>> Modified:
>>>     commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVRecord.java
>>>
>>> Modified: commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVRecord.java
>>> URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVRecord.java?rev=1509450&r1=1509449&r2=1509450&view=diff
>>> ==============================================================================
>>> --- commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVRecord.java (original)
>>> +++ commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVRecord.java Thu Aug  1 21:57:46 2013
>>> @@ -146,6 +146,23 @@ public class CSVRecord implements Serial
>>>       *             if the record is inconsistent
>>>       * @see #isConsistent()
>>>       */
>>> +    public int getInt(String name) {
>>> +        String s = this.get(name);
>>> +        return s != null ? Integer.parseInt(s) : 0;
>>> +    }
>>> +
>>> +    /**
>>> +     * Returns a value by name.
>>> +     *
>>> +     * @param name
>>> +     *            the name of the column to be retrieved.
>>> +     * @return the column value
>>> +     * @throws IllegalStateException
>>> +     *             if no header mapping was provided
>>> +     * @throws IllegalArgumentException
>>> +     *             if the record is inconsistent
>>> +     * @see #isConsistent()
>>> +     */
>>>      public long getLong(String name) {
>>>          String s = this.get(name);
>>>          return s != null ? Long.parseLong(s) : 0;
>>>
>>> Added: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVRecordIntTest.java
>>> URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVRecordIntTest.java?rev=1509450&view=auto
>>> ==============================================================================
>>> --- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVRecordIntTest.java (added)
>>> +++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVRecordIntTest.java Thu Aug  1 21:57:46 2013
>>> @@ -0,0 +1,64 @@
>>> +/*
>>> + * Licensed to the Apache Software Foundation (ASF) under one or more
>>> + * contributor license agreements.  See the NOTICE file distributed with
>>> + * this work for additional information regarding copyright ownership.
>>> + * The ASF licenses this file to You under the Apache License, Version 2.0
>>> + * (the "License"); you may not use this file except in compliance with
>>> + * the License.  You may obtain a copy of the License at
>>> + *
>>> + *      http://www.apache.org/licenses/LICENSE-2.0
>>> + *
>>> + * Unless required by applicable law or agreed to in writing, software
>>> + * distributed under the License is distributed on an "AS IS" BASIS,
>>> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
>>> + * See the License for the specific language governing permissions and
>>> + * limitations under the License.
>>> + */
>>> +package org.apache.commons.csv;
>>> +
>>> +import java.io.IOException;
>>> +
>>> +import org.junit.Assert;
>>> +import org.junit.Before;
>>> +import org.junit.Test;
>>> +
>>> +public class CSVRecordIntTest {
>>> +
>>> +    private CSVRecord record;
>>> +
>>> +    /**
>>> +     * @return
>>> +     * @throws IOException
>>> +     */
>>> +    private CSVRecord createTestRecord() throws IOException {
>>> +        String csv = "A, B, C, D, E\n-1, 0, 1, " + Integer.MAX_VALUE + ", " + Integer.MIN_VALUE;
>>> +        CSVRecord record = CSVParser.parseString(csv, CSVFormat.DEFAULT.withHeader().withIgnoreSurroundingSpaces(true))
>>> +                .iterator().next();
>>> +        return record;
>>> +    }
>>> +
>>> +    @Before
>>> +    public void setUp() throws IOException {
>>> +        this.record = createTestRecord();
>>> +    }
>>> +
>>> +    @Test(expected = IllegalArgumentException.class)
>>> +    public void testGetIntegerByMissingString() {
>>> +        Assert.assertEquals(null, Integer.valueOf(record.getInt("ABSENT")));
>>> +    }
>>> +
>>> +    @Test(expected = IllegalArgumentException.class)
>>> +    public void testGetIntegerByNullString() {
>>> +        Assert.assertEquals(null, Integer.valueOf(record.getInt(null)));
>>> +    }
>>> +
>>> +    @Test
>>> +    public void testGetIntegerByString() {
>>> +        Assert.assertEquals(-1, record.getInt("A"));
>>> +        Assert.assertEquals(0, record.getInt("B"));
>>> +        Assert.assertEquals(1, record.getInt("C"));
>>> +        Assert.assertEquals(Integer.MAX_VALUE, record.getInt("D"));
>>> +        Assert.assertEquals(Integer.MIN_VALUE, record.getInt("E"));
>>> +    }
>>> +
>>> +}
>>>
>>> Propchange: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVRecordIntTest.java
>>> ------------------------------------------------------------------------------
>>>     svn:eol-style = native
>>>
>>> Propchange: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVRecordIntTest.java
>>> ------------------------------------------------------------------------------
>>>     svn:keywords = Id
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
>> For additional commands, e-mail: dev-help@commons.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: svn commit: r1509450 - in /commons/proper/csv/trunk/src: main/java/org/apache/commons/csv/CSVRecord.java test/java/org/apache/commons/csv/CSVRecordIntTest.java

Posted by James Carman <ja...@carmanconsulting.com>.
You are -1ing a code modification, which means this counts as a veto.
Are you sure you want to veto this?

On Thu, Aug 1, 2013 at 7:28 PM, sebb <se...@gmail.com> wrote:
> On 1 August 2013 22:57,  <gg...@apache.org> wrote:
>> Author: ggregory
>> Date: Thu Aug  1 21:57:46 2013
>> New Revision: 1509450
>>
>> URL: http://svn.apache.org/r1509450
>> Log:
>> Add CSVRecord#getInt(String) API and tests.
>
> -1
>
> I think this is out of scope for CSV.
>
>> Added:
>>     commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVRecordIntTest.java   (with props)
>> Modified:
>>     commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVRecord.java
>>
>> Modified: commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVRecord.java
>> URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVRecord.java?rev=1509450&r1=1509449&r2=1509450&view=diff
>> ==============================================================================
>> --- commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVRecord.java (original)
>> +++ commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVRecord.java Thu Aug  1 21:57:46 2013
>> @@ -146,6 +146,23 @@ public class CSVRecord implements Serial
>>       *             if the record is inconsistent
>>       * @see #isConsistent()
>>       */
>> +    public int getInt(String name) {
>> +        String s = this.get(name);
>> +        return s != null ? Integer.parseInt(s) : 0;
>> +    }
>> +
>> +    /**
>> +     * Returns a value by name.
>> +     *
>> +     * @param name
>> +     *            the name of the column to be retrieved.
>> +     * @return the column value
>> +     * @throws IllegalStateException
>> +     *             if no header mapping was provided
>> +     * @throws IllegalArgumentException
>> +     *             if the record is inconsistent
>> +     * @see #isConsistent()
>> +     */
>>      public long getLong(String name) {
>>          String s = this.get(name);
>>          return s != null ? Long.parseLong(s) : 0;
>>
>> Added: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVRecordIntTest.java
>> URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVRecordIntTest.java?rev=1509450&view=auto
>> ==============================================================================
>> --- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVRecordIntTest.java (added)
>> +++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVRecordIntTest.java Thu Aug  1 21:57:46 2013
>> @@ -0,0 +1,64 @@
>> +/*
>> + * Licensed to the Apache Software Foundation (ASF) under one or more
>> + * contributor license agreements.  See the NOTICE file distributed with
>> + * this work for additional information regarding copyright ownership.
>> + * The ASF licenses this file to You under the Apache License, Version 2.0
>> + * (the "License"); you may not use this file except in compliance with
>> + * the License.  You may obtain a copy of the License at
>> + *
>> + *      http://www.apache.org/licenses/LICENSE-2.0
>> + *
>> + * Unless required by applicable law or agreed to in writing, software
>> + * distributed under the License is distributed on an "AS IS" BASIS,
>> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
>> + * See the License for the specific language governing permissions and
>> + * limitations under the License.
>> + */
>> +package org.apache.commons.csv;
>> +
>> +import java.io.IOException;
>> +
>> +import org.junit.Assert;
>> +import org.junit.Before;
>> +import org.junit.Test;
>> +
>> +public class CSVRecordIntTest {
>> +
>> +    private CSVRecord record;
>> +
>> +    /**
>> +     * @return
>> +     * @throws IOException
>> +     */
>> +    private CSVRecord createTestRecord() throws IOException {
>> +        String csv = "A, B, C, D, E\n-1, 0, 1, " + Integer.MAX_VALUE + ", " + Integer.MIN_VALUE;
>> +        CSVRecord record = CSVParser.parseString(csv, CSVFormat.DEFAULT.withHeader().withIgnoreSurroundingSpaces(true))
>> +                .iterator().next();
>> +        return record;
>> +    }
>> +
>> +    @Before
>> +    public void setUp() throws IOException {
>> +        this.record = createTestRecord();
>> +    }
>> +
>> +    @Test(expected = IllegalArgumentException.class)
>> +    public void testGetIntegerByMissingString() {
>> +        Assert.assertEquals(null, Integer.valueOf(record.getInt("ABSENT")));
>> +    }
>> +
>> +    @Test(expected = IllegalArgumentException.class)
>> +    public void testGetIntegerByNullString() {
>> +        Assert.assertEquals(null, Integer.valueOf(record.getInt(null)));
>> +    }
>> +
>> +    @Test
>> +    public void testGetIntegerByString() {
>> +        Assert.assertEquals(-1, record.getInt("A"));
>> +        Assert.assertEquals(0, record.getInt("B"));
>> +        Assert.assertEquals(1, record.getInt("C"));
>> +        Assert.assertEquals(Integer.MAX_VALUE, record.getInt("D"));
>> +        Assert.assertEquals(Integer.MIN_VALUE, record.getInt("E"));
>> +    }
>> +
>> +}
>>
>> Propchange: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVRecordIntTest.java
>> ------------------------------------------------------------------------------
>>     svn:eol-style = native
>>
>> Propchange: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVRecordIntTest.java
>> ------------------------------------------------------------------------------
>>     svn:keywords = Id
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: svn commit: r1509450 - in /commons/proper/csv/trunk/src: main/java/org/apache/commons/csv/CSVRecord.java test/java/org/apache/commons/csv/CSVRecordIntTest.java

Posted by sebb <se...@gmail.com>.
On 1 August 2013 22:57,  <gg...@apache.org> wrote:
> Author: ggregory
> Date: Thu Aug  1 21:57:46 2013
> New Revision: 1509450
>
> URL: http://svn.apache.org/r1509450
> Log:
> Add CSVRecord#getInt(String) API and tests.

-1

I think this is out of scope for CSV.

> Added:
>     commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVRecordIntTest.java   (with props)
> Modified:
>     commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVRecord.java
>
> Modified: commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVRecord.java
> URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVRecord.java?rev=1509450&r1=1509449&r2=1509450&view=diff
> ==============================================================================
> --- commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVRecord.java (original)
> +++ commons/proper/csv/trunk/src/main/java/org/apache/commons/csv/CSVRecord.java Thu Aug  1 21:57:46 2013
> @@ -146,6 +146,23 @@ public class CSVRecord implements Serial
>       *             if the record is inconsistent
>       * @see #isConsistent()
>       */
> +    public int getInt(String name) {
> +        String s = this.get(name);
> +        return s != null ? Integer.parseInt(s) : 0;
> +    }
> +
> +    /**
> +     * Returns a value by name.
> +     *
> +     * @param name
> +     *            the name of the column to be retrieved.
> +     * @return the column value
> +     * @throws IllegalStateException
> +     *             if no header mapping was provided
> +     * @throws IllegalArgumentException
> +     *             if the record is inconsistent
> +     * @see #isConsistent()
> +     */
>      public long getLong(String name) {
>          String s = this.get(name);
>          return s != null ? Long.parseLong(s) : 0;
>
> Added: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVRecordIntTest.java
> URL: http://svn.apache.org/viewvc/commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVRecordIntTest.java?rev=1509450&view=auto
> ==============================================================================
> --- commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVRecordIntTest.java (added)
> +++ commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVRecordIntTest.java Thu Aug  1 21:57:46 2013
> @@ -0,0 +1,64 @@
> +/*
> + * Licensed to the Apache Software Foundation (ASF) under one or more
> + * contributor license agreements.  See the NOTICE file distributed with
> + * this work for additional information regarding copyright ownership.
> + * The ASF licenses this file to You under the Apache License, Version 2.0
> + * (the "License"); you may not use this file except in compliance with
> + * the License.  You may obtain a copy of the License at
> + *
> + *      http://www.apache.org/licenses/LICENSE-2.0
> + *
> + * Unless required by applicable law or agreed to in writing, software
> + * distributed under the License is distributed on an "AS IS" BASIS,
> + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> + * See the License for the specific language governing permissions and
> + * limitations under the License.
> + */
> +package org.apache.commons.csv;
> +
> +import java.io.IOException;
> +
> +import org.junit.Assert;
> +import org.junit.Before;
> +import org.junit.Test;
> +
> +public class CSVRecordIntTest {
> +
> +    private CSVRecord record;
> +
> +    /**
> +     * @return
> +     * @throws IOException
> +     */
> +    private CSVRecord createTestRecord() throws IOException {
> +        String csv = "A, B, C, D, E\n-1, 0, 1, " + Integer.MAX_VALUE + ", " + Integer.MIN_VALUE;
> +        CSVRecord record = CSVParser.parseString(csv, CSVFormat.DEFAULT.withHeader().withIgnoreSurroundingSpaces(true))
> +                .iterator().next();
> +        return record;
> +    }
> +
> +    @Before
> +    public void setUp() throws IOException {
> +        this.record = createTestRecord();
> +    }
> +
> +    @Test(expected = IllegalArgumentException.class)
> +    public void testGetIntegerByMissingString() {
> +        Assert.assertEquals(null, Integer.valueOf(record.getInt("ABSENT")));
> +    }
> +
> +    @Test(expected = IllegalArgumentException.class)
> +    public void testGetIntegerByNullString() {
> +        Assert.assertEquals(null, Integer.valueOf(record.getInt(null)));
> +    }
> +
> +    @Test
> +    public void testGetIntegerByString() {
> +        Assert.assertEquals(-1, record.getInt("A"));
> +        Assert.assertEquals(0, record.getInt("B"));
> +        Assert.assertEquals(1, record.getInt("C"));
> +        Assert.assertEquals(Integer.MAX_VALUE, record.getInt("D"));
> +        Assert.assertEquals(Integer.MIN_VALUE, record.getInt("E"));
> +    }
> +
> +}
>
> Propchange: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVRecordIntTest.java
> ------------------------------------------------------------------------------
>     svn:eol-style = native
>
> Propchange: commons/proper/csv/trunk/src/test/java/org/apache/commons/csv/CSVRecordIntTest.java
> ------------------------------------------------------------------------------
>     svn:keywords = Id
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: svn commit: r1509450 - in /commons/proper/csv/trunk/src: main/java/org/apache/commons/csv/CSVRecord.java test/java/org/apache/commons/csv/CSVRecordIntTest.java

Posted by Emmanuel Bourg <eb...@apache.org>.
Le 01/08/2013 23:57, ggregory@apache.org a écrit :

> Add CSVRecord#getInt(String) API and tests.

All of these methods are already implemented in [configuration] with
pretty much all the types you might need (Enums, URLs, colors, emails,
dates, calendars, primitives, arrays, etc). If CSVRecord could return a
map this could be done with:

    Configuration config = new MapConfiguration(record.toMap());
    config.getInt("column1");
    config.getLong("column2", defaultValue);


Emmanuel Bourg


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org