Skip to content

Commit 4dc996e

Browse files
committed
Use final.
1 parent 8c9974d commit 4dc996e

7 files changed

Lines changed: 18 additions & 18 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -875,8 +875,8 @@ public String format(final Object... values) {
875875
final StringWriter out = new StringWriter();
876876
try (CSVPrinter csvPrinter = new CSVPrinter(out, this)) {
877877
csvPrinter.printRecord(values);
878-
String res = out.toString();
879-
int len = recordSeparator != null ? res.length() - recordSeparator.length() : res.length();
878+
final String res = out.toString();
879+
final int len = recordSeparator != null ? res.length() - recordSeparator.length() : res.length();
880880
return res.substring(0, len);
881881
} catch (final IOException e) {
882882
// should not happen because a StringWriter does not do IO.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void testCSVFile(final File testFile) throws Exception {
9393
try (final CSVParser parser = CSVParser.parse(new File(BASE, split[0]), Charset.defaultCharset(), format)) {
9494
for (final CSVRecord record : parser) {
9595
String parsed = Arrays.toString(record.values());
96-
String comment = record.getComment();
96+
final String comment = record.getComment();
9797
if (checkComments && comment != null) {
9898
parsed += "#" + comment.replace("\n", "\\n");
9999
}
@@ -138,7 +138,7 @@ public void testCSVUrl(final File testFile) throws Exception {
138138
try (final CSVParser parser = CSVParser.parse(resource, Charset.forName("UTF-8"), format)) {
139139
for (final CSVRecord record : parser) {
140140
String parsed = Arrays.toString(record.values());
141-
String comment = record.getComment();
141+
final String comment = record.getComment();
142142
if (checkComments && comment != null) {
143143
parsed += "#" + comment.replace("\n", "\\n");
144144
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,22 +1216,22 @@ public void testDelimiterSameAsRecordSeparatorThrowsException() {
12161216
@Test
12171217
public void testWithHeaderEnumNull() {
12181218
final CSVFormat format = CSVFormat.DEFAULT;
1219-
Class<Enum<?>> simpleName = null;
1219+
final Class<Enum<?>> simpleName = null;
12201220
format.withHeader(simpleName);
12211221
}
12221222

12231223
@Test
12241224
public void testWithHeaderResultSetNull() throws SQLException {
12251225
final CSVFormat format = CSVFormat.DEFAULT;
1226-
ResultSet resultSet = null;
1226+
final ResultSet resultSet = null;
12271227
format.withHeader(resultSet);
12281228
}
12291229

12301230
@Test
12311231
public void testPrintWithQuoteModeIsNONE() throws IOException {
12321232
final Reader in = new StringReader("a,b,c");
12331233
final Appendable out = new StringBuilder();
1234-
CSVFormat format = CSVFormat.RFC4180.withDelimiter(',').withQuote('"').withEscape('?').withQuoteMode(QuoteMode.NONE);
1234+
final CSVFormat format = CSVFormat.RFC4180.withDelimiter(',').withQuote('"').withEscape('?').withQuoteMode(QuoteMode.NONE);
12351235
format.print(in, out, true);
12361236
assertEquals("a?,b?,c", out.toString());
12371237
}
@@ -1240,7 +1240,7 @@ public void testPrintWithQuoteModeIsNONE() throws IOException {
12401240
public void testPrintWithQuotes() throws IOException {
12411241
final Reader in = new StringReader("\"a,b,c\r\nx,y,z");
12421242
final Appendable out = new StringBuilder();
1243-
CSVFormat format = CSVFormat.RFC4180.withDelimiter(',').withQuote('"').withEscape('?').withQuoteMode(QuoteMode.NON_NUMERIC);
1243+
final CSVFormat format = CSVFormat.RFC4180.withDelimiter(',').withQuote('"').withEscape('?').withQuoteMode(QuoteMode.NON_NUMERIC);
12441244
format.print(in, out, true);
12451245
assertEquals("\"\"\"\"a,b,c\r\nx,y,z\"", out.toString());
12461246
}
@@ -1249,14 +1249,14 @@ public void testPrintWithQuotes() throws IOException {
12491249
public void testPrintWithoutQuotes() throws IOException {
12501250
final Reader in = new StringReader("");
12511251
final Appendable out = new StringBuilder();
1252-
CSVFormat format = CSVFormat.RFC4180.withDelimiter(',').withQuote('"').withEscape('?').withQuoteMode(QuoteMode.NON_NUMERIC);
1252+
final CSVFormat format = CSVFormat.RFC4180.withDelimiter(',').withQuote('"').withEscape('?').withQuoteMode(QuoteMode.NON_NUMERIC);
12531253
format.print(in, out, true);
12541254
assertEquals("\"\"", out.toString());
12551255
}
12561256

12571257
@Test
12581258
public void testTrim() throws IOException {
1259-
CSVFormat formatWithTrim = CSVFormat.DEFAULT.withDelimiter(',').withTrim().withQuote(null).withRecordSeparator(CRLF);
1259+
final CSVFormat formatWithTrim = CSVFormat.DEFAULT.withDelimiter(',').withTrim().withQuote(null).withRecordSeparator(CRLF);
12601260

12611261
CharSequence in = "a,b,c";
12621262
final StringBuilder out = new StringBuilder();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1343,7 +1343,7 @@ public void testPrintRecordsWithCSVRecord() throws IOException {
13431343
final CharArrayWriter charArrayWriter = new CharArrayWriter(0);
13441344
try (final CSVParser parser = CSVFormat.DEFAULT.parse(new StringReader(rowData));
13451345
CSVPrinter csvPrinter = CSVFormat.INFORMIX_UNLOAD.print(charArrayWriter)) {
1346-
for (CSVRecord record : parser) {
1346+
for (final CSVRecord record : parser) {
13471347
csvPrinter.printRecord(record);
13481348
}
13491349
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ public enum EnumHeader {
5151
SECOND("second"),
5252
THIRD("third");
5353

54-
private String number;
54+
private final String number;
5555

56-
EnumHeader(String number) {
56+
EnumHeader(final String number) {
5757
this.number = number;
5858
}
5959

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public void testJiraCsv149EndWithEOL() throws IOException {
3535
testJiraCsv149EndWithEolAtEof(true);
3636
}
3737

38-
private void testJiraCsv149EndWithEolAtEof(boolean eolAtEof) throws IOException {
38+
private void testJiraCsv149EndWithEolAtEof(final boolean eolAtEof) throws IOException {
3939
String source = "A,B,C,D" + CR_LF + "a1,b1,c1,d1" + CR_LF + "a2,b2,c2,d2";
4040
if (eolAtEof) {
4141
source += CR_LF;
@@ -44,7 +44,7 @@ private void testJiraCsv149EndWithEolAtEof(boolean eolAtEof) throws IOException
4444
final CSVFormat format = CSVFormat.RFC4180.withFirstRecordAsHeader().withQuote('"');
4545
int lineCounter = 2;
4646
try (final CSVParser parser = new CSVParser(records, format)) {
47-
for (CSVRecord record : parser) {
47+
for (final CSVRecord record : parser) {
4848
assertEquals(lineCounter++, parser.getCurrentLineNumber());
4949
}
5050
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ public void testJiraCsv211Format() throws IOException {
3333
final String[] values = new String[] { "1", "Jane Doe", "USA", "" };
3434

3535
final CSVFormat printFormat = CSVFormat.DEFAULT.withDelimiter('\t').withHeader("ID", "Name", "Country", "Age");
36-
String formatted = printFormat.format(values);
36+
final String formatted = printFormat.format(values);
3737
assertEquals("ID\tName\tCountry\tAge\r\n1\tJane Doe\tUSA\t", formatted);
3838

3939
final CSVFormat parseFormat = CSVFormat.DEFAULT.withDelimiter('\t').withFirstRecordAsHeader();
40-
CSVParser parser = parseFormat.parse(new StringReader(formatted));
41-
for (CSVRecord record : parser) {
40+
final CSVParser parser = parseFormat.parse(new StringReader(formatted));
41+
for (final CSVRecord record : parser) {
4242
assertEquals("1", record.get(0));
4343
assertEquals("Jane Doe", record.get(1));
4444
assertEquals("USA", record.get(2));

0 commit comments

Comments
 (0)