Skip to content

Commit 64bae17

Browse files
CSV-267 - Minor improvement (apache#126)
1 parent e5fbba3 commit 64bae17

9 files changed

Lines changed: 16 additions & 15 deletions

File tree

src/main/java/org/apache/commons/csv/CSVFormat.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ public boolean getTrailingDelimiter() {
10511051
/**
10521052
* Returns whether to trim leading and trailing blanks.
10531053
* This is used by {@link #print(Object, Appendable, boolean)}
1054-
* Also by {@link CSVParser#addRecordValue(boolean)}
1054+
* Also by {CSVParser#addRecordValue(boolean)}
10551055
*
10561056
* @return whether to trim leading and trailing blanks.
10571057
*/
@@ -1322,8 +1322,7 @@ public void printRecord(final Appendable out, final Object... values) throws IOE
13221322
private void printWithEscapes(final CharSequence value, final Appendable out) throws IOException {
13231323
int start = 0;
13241324
int pos = 0;
1325-
final int len = value.length();
1326-
final int end = len;
1325+
final int end = value.length();
13271326

13281327
final char delim = getDelimiter();
13291328
final char escape = getEscapeCharacter().charValue();

src/test/java/org/apache/commons/csv/CSVPrinterTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ private String randStr() {
179179
final char[] buf = new char[sz];
180180
for (int i = 0; i < sz; i++) {
181181
// stick in special chars with greater frequency
182-
char ch;
182+
final char ch;
183183
final int what = r.nextInt(20);
184184
switch (what) {
185185
case 0:
@@ -1342,7 +1342,7 @@ public void testPrintRecordsWithCSVRecord() throws IOException {
13421342
final String rowData = StringUtils.join(values, ',');
13431343
final CharArrayWriter charArrayWriter = new CharArrayWriter(0);
13441344
try (final CSVParser parser = CSVFormat.DEFAULT.parse(new StringReader(rowData));
1345-
CSVPrinter csvPrinter = CSVFormat.INFORMIX_UNLOAD.print(charArrayWriter)) {
1345+
final CSVPrinter csvPrinter = CSVFormat.INFORMIX_UNLOAD.print(charArrayWriter)) {
13461346
for (final CSVRecord record : parser) {
13471347
csvPrinter.printRecord(record);
13481348
}

src/test/java/org/apache/commons/csv/CSVRecordTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import java.io.StringReader;
3232
import java.util.ArrayList;
3333
import java.util.Collections;
34-
import java.util.HashMap;
3534
import java.util.Map;
3635
import java.util.TreeMap;
3736
import java.util.concurrent.ConcurrentHashMap;
@@ -213,7 +212,7 @@ public void testRemoveAndAddColumns() throws IOException {
213212

214213
@Test
215214
public void testSerialization() throws IOException, ClassNotFoundException {
216-
CSVRecord shortRec;
215+
final CSVRecord shortRec;
217216
try (final CSVParser parser = CSVParser.parse("A,B\n#my comment\nOne,Two", CSVFormat.DEFAULT.withHeader().withCommentMarker('#'))) {
218217
shortRec = parser.iterator().next();
219218
}

src/test/java/org/apache/commons/csv/PerformanceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public static void main(final String [] args) throws Exception {
8888
max = Integer.parseInt(args[0]);
8989
}
9090

91-
String tests[];
91+
final String[] tests;
9292
if (argc > 1) {
9393
tests = new String[argc - 1];
9494
for (int i = 1; i < argc; i++) {

src/test/java/org/apache/commons/csv/Utils.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ private Utils() {
3939
* @param actual the List of {@link CSVRecord} entries, each containing an array of values
4040
*/
4141
public static void compare(final String message, final String[][] expected, final List<CSVRecord> actual) {
42-
assertEquals(expected.length, actual.size(), message + " - outer array size");
43-
for (int i = 0; i < expected.length; i++) {
42+
final int expectedLength = expected.length;
43+
assertEquals(expectedLength, actual.size(), message + " - outer array size");
44+
for (int i = 0; i < expectedLength; i++) {
4445
assertArrayEquals(expected[i], actual.get(i).values(), message + " (entry " + i + ")");
4546
}
4647
}

src/test/java/org/apache/commons/csv/issues/JiraCsv198Test.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.io.InputStream;
2323
import java.io.InputStreamReader;
2424
import java.io.UnsupportedEncodingException;
25+
import java.nio.charset.StandardCharsets;
2526

2627
import org.apache.commons.csv.CSVFormat;
2728
import org.apache.commons.csv.CSVParser;
@@ -37,7 +38,7 @@ public void test() throws UnsupportedEncodingException, IOException {
3738
final InputStream pointsOfReference = getClass().getResourceAsStream("/org/apache/commons/csv/CSV-198/optd_por_public.csv");
3839
assertNotNull(pointsOfReference);
3940
try (@SuppressWarnings("resource")
40-
CSVParser parser = CSV_FORMAT.parse(new InputStreamReader(pointsOfReference, "UTF-8"))) {
41+
CSVParser parser = CSV_FORMAT.parse(new InputStreamReader(pointsOfReference, StandardCharsets.UTF_8))) {
4142
for (final CSVRecord record : parser) {
4243
final String locationType = record.get("location_type");
4344
assertNotNull(locationType);

src/test/java/org/apache/commons/csv/issues/JiraCsv248Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public void testJiraCsv248() throws IOException, ClassNotFoundException {
4646
// CSVRecord rec = parser.iterator().next();
4747
//}
4848
try (InputStream in = getTestInput();
49-
ObjectInputStream ois = new ObjectInputStream(in)) {
49+
final ObjectInputStream ois = new ObjectInputStream(in)) {
5050
final Object object = ois.readObject();
5151
assertTrue(object instanceof CSVRecord);
5252
final CSVRecord rec = (CSVRecord) object;

src/test/java/org/apache/commons/csv/issues/JiraCsv249Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void testJiraCsv249() throws IOException {
4040
printer.printRecord("foo \\", "bar");
4141
}
4242
final StringReader stringReader = new StringReader(stringWriter.toString());
43-
List<CSVRecord> records;
43+
final List<CSVRecord> records;
4444
try (CSVParser parser = new CSVParser(stringReader, csvFormat)) {
4545
records = parser.getRecords();
4646
}

src/test/resources/org/apache/commons/csv/CSVPrinter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,12 @@ public void printComment(final String comment) throws IOException {
203203
}
204204
out.append(format.getCommentMarker().charValue());
205205
out.append(SP);
206-
for (int i = 0; i < comment.length(); i++) {
206+
final int commentLength = comment.length();
207+
for (int i = 0; i < commentLength; i++) {
207208
final char c = comment.charAt(i);
208209
switch (c) {
209210
case CR:
210-
if (i + 1 < comment.length() && comment.charAt(i + 1) == LF) {
211+
if (i + 1 < commentLength && comment.charAt(i + 1) == LF) {
211212
i++;
212213
}
213214
//$FALL-THROUGH$ break intentionally excluded.

0 commit comments

Comments
 (0)