Renamed CSVParser.getAllValues() to getRecords()
git-svn-id: https://svn.apache.org/repos/asf/commons/sandbox/csv/trunk@1199997 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
16bfec07ff
commit
a7bd28c496
|
@ -33,13 +33,13 @@ import static org.apache.commons.csv.CSVParser.Token.Type.*;
|
|||
* <p>Parsing of a csv-string having tabs as separators,
|
||||
* '"' as an optional value encapsulator, and comments starting with '#':</p>
|
||||
* <pre>
|
||||
* String[][] data =
|
||||
* String[][] record =
|
||||
* (new CSVParser(new StringReader("a\tb\nc\td"), new CSVFormat('\t','"','#'))).getAllValues();
|
||||
* </pre>
|
||||
*
|
||||
* <p>Parsing of a csv-string in Excel CSV format</p>
|
||||
* <pre>
|
||||
* String[][] data =
|
||||
* String[][] record =
|
||||
* (new CSVParser(new StringReader("a;b\nc;d"), CSVFormat.EXCEL)).getAllValues();
|
||||
* </pre>
|
||||
*
|
||||
|
@ -150,7 +150,7 @@ public class CSVParser {
|
|||
* @return matrix of records x values ('null' when end of file)
|
||||
* @throws IOException on parse error or input read-failure
|
||||
*/
|
||||
public String[][] getAllValues() throws IOException {
|
||||
public String[][] getRecords() throws IOException {
|
||||
List<String[]> records = new ArrayList<String[]>();
|
||||
String[] values;
|
||||
String[][] ret = null;
|
||||
|
|
|
@ -88,7 +88,7 @@ public class CSVUtils {
|
|||
if (s == null) {
|
||||
throw new IllegalArgumentException("Null argument not allowed.");
|
||||
}
|
||||
String[][] result = (new CSVParser(new StringReader(s))).getAllValues();
|
||||
String[][] result = (new CSVParser(new StringReader(s))).getRecords();
|
||||
if (result == null) {
|
||||
// since CSVFormat ignores empty lines an empty array is returned
|
||||
// (i.e. not "result = new String[][] {{""}};")
|
||||
|
|
|
@ -221,7 +221,7 @@ public class CSVParserTest extends TestCase {
|
|||
|
||||
public void testGetAllValues() throws IOException {
|
||||
CSVParser parser = new CSVParser(new StringReader(code));
|
||||
String[][] tmp = parser.getAllValues();
|
||||
String[][] tmp = parser.getRecords();
|
||||
assertEquals(res.length, tmp.length);
|
||||
assertTrue(tmp.length > 0);
|
||||
for (int i = 0; i < res.length; i++) {
|
||||
|
@ -241,7 +241,7 @@ public class CSVParserTest extends TestCase {
|
|||
{"\"hello\"", " \"world\"", "abc\ndef", ""}
|
||||
};
|
||||
CSVParser parser = new CSVParser(new StringReader(code), CSVFormat.EXCEL);
|
||||
String[][] tmp = parser.getAllValues();
|
||||
String[][] tmp = parser.getRecords();
|
||||
assertEquals(res.length, tmp.length);
|
||||
assertTrue(tmp.length > 0);
|
||||
for (int i = 0; i < res.length; i++) {
|
||||
|
@ -259,7 +259,7 @@ public class CSVParserTest extends TestCase {
|
|||
{"world", ""}
|
||||
};
|
||||
CSVParser parser = new CSVParser(new StringReader(code), CSVFormat.EXCEL);
|
||||
String[][] tmp = parser.getAllValues();
|
||||
String[][] tmp = parser.getRecords();
|
||||
assertEquals(res.length, tmp.length);
|
||||
assertTrue(tmp.length > 0);
|
||||
for (int i = 0; i < res.length; i++) {
|
||||
|
@ -286,7 +286,7 @@ public class CSVParserTest extends TestCase {
|
|||
|
||||
for (String code : codes) {
|
||||
CSVParser parser = new CSVParser(new StringReader(code), CSVFormat.EXCEL);
|
||||
String[][] tmp = parser.getAllValues();
|
||||
String[][] tmp = parser.getRecords();
|
||||
assertEquals(res.length, tmp.length);
|
||||
assertTrue(tmp.length > 0);
|
||||
for (int i = 0; i < res.length; i++) {
|
||||
|
@ -314,7 +314,7 @@ public class CSVParserTest extends TestCase {
|
|||
for (int codeIndex = 0; codeIndex < codes.length; codeIndex++) {
|
||||
code = codes[codeIndex];
|
||||
CSVParser parser = new CSVParser(new StringReader(code));
|
||||
String[][] tmp = parser.getAllValues();
|
||||
String[][] tmp = parser.getRecords();
|
||||
assertEquals(res.length, tmp.length);
|
||||
assertTrue(tmp.length > 0);
|
||||
for (int i = 0; i < res.length; i++) {
|
||||
|
@ -339,7 +339,7 @@ public class CSVParserTest extends TestCase {
|
|||
for (int codeIndex = 0; codeIndex < codes.length; codeIndex++) {
|
||||
code = codes[codeIndex];
|
||||
CSVParser parser = new CSVParser(new StringReader(code), CSVFormat.EXCEL);
|
||||
String[][] tmp = parser.getAllValues();
|
||||
String[][] tmp = parser.getRecords();
|
||||
assertEquals(res.length, tmp.length);
|
||||
assertTrue(tmp.length > 0);
|
||||
for (int i = 0; i < res.length; i++) {
|
||||
|
@ -362,7 +362,7 @@ public class CSVParserTest extends TestCase {
|
|||
for (int codeIndex = 0; codeIndex < codes.length; codeIndex++) {
|
||||
code = codes[codeIndex];
|
||||
CSVParser parser = new CSVParser(new StringReader(code));
|
||||
String[][] tmp = parser.getAllValues();
|
||||
String[][] tmp = parser.getRecords();
|
||||
assertEquals(res.length, tmp.length);
|
||||
assertTrue(tmp.length > 0);
|
||||
for (int i = 0; i < res.length; i++) {
|
||||
|
@ -394,7 +394,7 @@ public class CSVParserTest extends TestCase {
|
|||
{"a\\\\,b"} // backslash in quotes only escapes a delimiter (",")
|
||||
};
|
||||
CSVParser parser = new CSVParser(new StringReader(code));
|
||||
String[][] tmp = parser.getAllValues();
|
||||
String[][] tmp = parser.getRecords();
|
||||
assertEquals(res.length, tmp.length);
|
||||
assertTrue(tmp.length > 0);
|
||||
for (int i = 0; i < res.length; i++) {
|
||||
|
@ -437,7 +437,7 @@ public class CSVParserTest extends TestCase {
|
|||
CSVFormat format = new CSVFormat(',', '\'', CSVFormat.COMMENTS_DISABLED, '/', false, false, true, true);
|
||||
|
||||
CSVParser parser = new CSVParser(new StringReader(code), format);
|
||||
String[][] tmp = parser.getAllValues();
|
||||
String[][] tmp = parser.getRecords();
|
||||
assertTrue(tmp.length > 0);
|
||||
for (int i = 0; i < res.length; i++) {
|
||||
assertTrue(Arrays.equals(res[i], tmp[i]));
|
||||
|
@ -465,7 +465,7 @@ public class CSVParserTest extends TestCase {
|
|||
CSVFormat format = new CSVFormat(',', CSVFormat.ENCAPSULATOR_DISABLED, CSVFormat.COMMENTS_DISABLED, '/', false, false, true, true);
|
||||
|
||||
CSVParser parser = new CSVParser(new StringReader(code), format);
|
||||
String[][] tmp = parser.getAllValues();
|
||||
String[][] tmp = parser.getRecords();
|
||||
assertTrue(tmp.length > 0);
|
||||
|
||||
if (!CSVPrinterTest.equals(res, tmp)) {
|
||||
|
@ -492,7 +492,7 @@ public class CSVParserTest extends TestCase {
|
|||
assertEquals(CSVFormat.COMMENTS_DISABLED, format.getCommentStart());
|
||||
|
||||
CSVParser parser = new CSVParser(new StringReader(code), format);
|
||||
String[][] tmp = parser.getAllValues();
|
||||
String[][] tmp = parser.getRecords();
|
||||
assertTrue(tmp.length > 0);
|
||||
|
||||
if (!CSVPrinterTest.equals(res, tmp)) {
|
||||
|
@ -507,7 +507,7 @@ public class CSVParserTest extends TestCase {
|
|||
|
||||
format = new CSVFormat(',', '"', '#');
|
||||
parser = new CSVParser(new StringReader(code), format);
|
||||
tmp = parser.getAllValues();
|
||||
tmp = parser.getRecords();
|
||||
|
||||
if (!CSVPrinterTest.equals(res_comments, tmp)) {
|
||||
assertTrue(false);
|
||||
|
@ -527,21 +527,21 @@ public class CSVParserTest extends TestCase {
|
|||
public void testCarriageReturnLineFeedEndings() throws IOException {
|
||||
String code = "foo\r\nbaar,\r\nhello,world\r\n,kanu";
|
||||
CSVParser parser = new CSVParser(new StringReader(code));
|
||||
String[][] data = parser.getAllValues();
|
||||
String[][] data = parser.getRecords();
|
||||
assertEquals(4, data.length);
|
||||
}
|
||||
|
||||
public void testCarriageReturnEndings() throws IOException {
|
||||
String code = "foo\rbaar,\rhello,world\r,kanu";
|
||||
CSVParser parser = new CSVParser(new StringReader(code));
|
||||
String[][] data = parser.getAllValues();
|
||||
String[][] data = parser.getRecords();
|
||||
assertEquals(4, data.length);
|
||||
}
|
||||
|
||||
public void testLineFeedEndings() throws IOException {
|
||||
String code = "foo\nbaar,\nhello,world\n,kanu";
|
||||
CSVParser parser = new CSVParser(new StringReader(code));
|
||||
String[][] data = parser.getAllValues();
|
||||
String[][] data = parser.getRecords();
|
||||
assertEquals(4, data.length);
|
||||
}
|
||||
|
||||
|
@ -550,7 +550,7 @@ public class CSVParserTest extends TestCase {
|
|||
//String code = "world\r\n\n";
|
||||
//String code = "foo;baar\r\n\r\nhello;\r\n\r\nworld;\r\n";
|
||||
CSVParser parser = new CSVParser(new StringReader(code));
|
||||
String[][] data = parser.getAllValues();
|
||||
String[][] data = parser.getRecords();
|
||||
assertEquals(3, data.length);
|
||||
}
|
||||
|
||||
|
|
|
@ -152,7 +152,7 @@ public class CSVPrinterTest extends TestCase {
|
|||
StringReader reader = new StringReader(result);
|
||||
|
||||
CSVParser parser = new CSVParser(reader, format);
|
||||
String[][] parseResult = parser.getAllValues();
|
||||
String[][] parseResult = parser.getRecords();
|
||||
|
||||
if (!equals(lines, parseResult)) {
|
||||
System.out.println("Printer output :" + printable(result));
|
||||
|
|
Loading…
Reference in New Issue