Remove primitive APIs in CSVRecord.

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1510455 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary D. Gregory 2013-08-05 12:43:23 +00:00
parent 6208f0c9af
commit b042bd8522
4 changed files with 0 additions and 242 deletions

View File

@ -107,23 +107,6 @@ public class CSVRecord implements Serializable, Iterable<String> {
}
}
/**
* 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 boolean getBoolean(String name) {
String s = this.get(name);
return s != null ? Boolean.parseBoolean(s) : false;
}
/**
* Returns the comment for this record, if any.
*
@ -134,40 +117,6 @@ public class CSVRecord implements Serializable, Iterable<String> {
return comment;
}
/**
* 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 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;
}
/**
* Returns the number of this record in the parsed CSV file.
*

View File

@ -1,63 +0,0 @@
/*
* 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 CSVRecordBooleanTest {
private CSVRecord record;
/**
* @return
* @throws IOException
*/
private CSVRecord createTestRecord() throws IOException {
String csv = "A,B,C,D\ntrue, TRUE, false, foo";
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 testGetBooleanByMissingString() {
record.getBoolean("ABSENT");
}
@Test(expected = IllegalArgumentException.class)
public void testGetBooleanByNullString() {
record.getBoolean(null);
}
@Test
public void testGetBooleanByString() {
Assert.assertEquals(Boolean.TRUE, Boolean.valueOf(record.getBoolean("A")));
Assert.assertEquals(Boolean.TRUE, Boolean.valueOf(record.getBoolean("B")));
Assert.assertEquals(Boolean.FALSE, Boolean.valueOf(record.getBoolean("C")));
Assert.assertEquals(Boolean.FALSE, Boolean.valueOf(record.getBoolean("D")));
}
}

View File

@ -1,64 +0,0 @@
/*
* 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"));
}
}

View File

@ -1,64 +0,0 @@
/*
* 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 CSVRecordLongTest {
private CSVRecord record;
/**
* @return
* @throws IOException
*/
private CSVRecord createTestRecord() throws IOException {
String csv = "A, B, C, D, E\n-1, 0, 1, " + Long.MAX_VALUE + ", " + Long.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 testGetLongByMissingString() {
Assert.assertEquals(null, Long.valueOf(record.getLong("ABSENT")));
}
@Test(expected = IllegalArgumentException.class)
public void testGetLongByNullString() {
Assert.assertEquals(null, Long.valueOf(record.getLong(null)));
}
@Test
public void testGetLongByString() {
Assert.assertEquals(-1, record.getLong("A"));
Assert.assertEquals(0, record.getLong("B"));
Assert.assertEquals(1, record.getLong("C"));
Assert.assertEquals(Long.MAX_VALUE, record.getLong("D"));
Assert.assertEquals(Long.MIN_VALUE, record.getLong("E"));
}
}