Skip to content

Commit 0c216e7

Browse files
committed
Use final.
1 parent b4a084e commit 0c216e7

9 files changed

Lines changed: 83 additions & 83 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ private CSVFormat(final char delimiter, final Character quoteChar, final QuoteMo
630630
final boolean ignoreEmptyLines, final String recordSeparator, final String nullString,
631631
final Object[] headerComments, final String[] header, final boolean skipHeaderRecord,
632632
final boolean allowMissingColumnNames, final boolean ignoreHeaderCase, final boolean trim,
633-
final boolean trailingDelimiter, boolean autoFlush) {
633+
final boolean trailingDelimiter, final boolean autoFlush) {
634634
this.delimiter = delimiter;
635635
this.quoteCharacter = quoteChar;
636636
this.quoteMode = quoteMode;
@@ -1026,7 +1026,7 @@ public CSVPrinter printer() throws IOException {
10261026
* @since 1.5
10271027
*/
10281028
@SuppressWarnings("resource")
1029-
public CSVPrinter print(final File out, Charset charset) throws IOException {
1029+
public CSVPrinter print(final File out, final Charset charset) throws IOException {
10301030
// The writer will be closed when close() is called.
10311031
return new CSVPrinter(new OutputStreamWriter(new FileOutputStream(out), charset), this);
10321032
}
@@ -1047,7 +1047,7 @@ public CSVPrinter print(final File out, Charset charset) throws IOException {
10471047
* thrown if the optional header cannot be printed.
10481048
* @since 1.5
10491049
*/
1050-
public CSVPrinter print(final Path out, Charset charset) throws IOException {
1050+
public CSVPrinter print(final Path out, final Charset charset) throws IOException {
10511051
return print(Files.newBufferedWriter(out, charset));
10521052
}
10531053

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public static CSVParser parse(final Path path, final Charset charset, final CSVF
225225
* If there is a problem reading the header or skipping the first record
226226
* @since 1.5
227227
*/
228-
public static CSVParser parse(Reader reader, final CSVFormat format) throws IOException {
228+
public static CSVParser parse(final Reader reader, final CSVFormat format) throws IOException {
229229
return new CSVParser(reader, format);
230230
}
231231

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public void close() throws IOException {
9292
* If an I/O error occurs
9393
* @since 1.6
9494
*/
95-
public void close(boolean flush) throws IOException {
95+
public void close(final boolean flush) throws IOException {
9696
if (flush || format.getAutoFlush()) {
9797
if (out instanceof Flushable) {
9898
((Flushable) out).flush();

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,8 @@ public void testWithFirstRecordAsHeader() throws Exception {
462462
@Test
463463
public void testToStringAndWithCommentMarkerTakingCharacter() {
464464

465-
CSVFormat.Predefined cSVFormat_Predefined = CSVFormat.Predefined.Default;
466-
CSVFormat cSVFormat = cSVFormat_Predefined.getFormat();
465+
final CSVFormat.Predefined cSVFormat_Predefined = CSVFormat.Predefined.Default;
466+
final CSVFormat cSVFormat = cSVFormat_Predefined.getFormat();
467467

468468
assertNull(cSVFormat.getEscapeCharacter());
469469
assertTrue(cSVFormat.isQuoteCharacterSet());
@@ -492,9 +492,9 @@ public void testToStringAndWithCommentMarkerTakingCharacter() {
492492
assertTrue(cSVFormat.getIgnoreEmptyLines());
493493
assertEquals('\"', (char)cSVFormat.getQuoteCharacter());
494494

495-
Character character = Character.valueOf('n');
495+
final Character character = Character.valueOf('n');
496496

497-
CSVFormat cSVFormatTwo = cSVFormat.withCommentMarker(character);
497+
final CSVFormat cSVFormatTwo = cSVFormat.withCommentMarker(character);
498498

499499
assertNull(cSVFormat.getEscapeCharacter());
500500
assertTrue(cSVFormat.isQuoteCharacterSet());
@@ -625,7 +625,7 @@ public void testToStringAndWithCommentMarkerTakingCharacter() {
625625
@Test
626626
public void testNewFormat() {
627627

628-
CSVFormat cSVFormat = CSVFormat.newFormat('X');
628+
final CSVFormat cSVFormat = CSVFormat.newFormat('X');
629629

630630
assertFalse(cSVFormat.getSkipHeaderRecord());
631631
assertFalse(cSVFormat.isEscapeCharacterSet());
@@ -687,7 +687,7 @@ public void testNewFormat() {
687687
@Test
688688
public void testWithHeaderComments() {
689689

690-
CSVFormat cSVFormat = CSVFormat.DEFAULT;
690+
final CSVFormat cSVFormat = CSVFormat.DEFAULT;
691691

692692
assertEquals('\"', (char)cSVFormat.getQuoteCharacter());
693693
assertFalse(cSVFormat.isCommentMarkerSet());
@@ -716,8 +716,8 @@ public void testWithHeaderComments() {
716716
assertFalse(cSVFormat.getIgnoreSurroundingSpaces());
717717
assertNull(cSVFormat.getEscapeCharacter());
718718

719-
Object[] objectArray = new Object[8];
720-
CSVFormat cSVFormatTwo = cSVFormat.withHeaderComments(objectArray);
719+
final Object[] objectArray = new Object[8];
720+
final CSVFormat cSVFormatTwo = cSVFormat.withHeaderComments(objectArray);
721721

722722
assertEquals('\"', (char)cSVFormat.getQuoteCharacter());
723723
assertFalse(cSVFormat.isCommentMarkerSet());
@@ -778,7 +778,7 @@ public void testWithHeaderComments() {
778778

779779
assertTrue(cSVFormatTwo.equals(cSVFormat));
780780

781-
String string = cSVFormatTwo.format(objectArray);
781+
final String string = cSVFormatTwo.format(objectArray);
782782

783783
assertEquals('\"', (char)cSVFormat.getQuoteCharacter());
784784
assertFalse(cSVFormat.isCommentMarkerSet());
@@ -849,12 +849,12 @@ public void testWithHeaderComments() {
849849
@Test //I assume this to be a defect.
850850
public void testFormatThrowsNullPointerException() {
851851

852-
CSVFormat cSVFormat = CSVFormat.MYSQL;
852+
final CSVFormat cSVFormat = CSVFormat.MYSQL;
853853

854854
try {
855855
cSVFormat.format(null);
856856
fail("Expecting exception: NullPointerException");
857-
} catch(NullPointerException e) {
857+
} catch(final NullPointerException e) {
858858
assertEquals(CSVFormat.class.getName(), e.getStackTrace()[0].getClassName());
859859
}
860860

@@ -864,8 +864,8 @@ public void testFormatThrowsNullPointerException() {
864864
@Test
865865
public void testEqualsOne() {
866866

867-
CSVFormat cSVFormatOne = CSVFormat.INFORMIX_UNLOAD;
868-
CSVFormat cSVFormatTwo = CSVFormat.MYSQL;
867+
final CSVFormat cSVFormatOne = CSVFormat.INFORMIX_UNLOAD;
868+
final CSVFormat cSVFormatTwo = CSVFormat.MYSQL;
869869

870870

871871
assertEquals('\\', (char)cSVFormatOne.getEscapeCharacter());
@@ -994,7 +994,7 @@ public void testEqualsOne() {
994994
@Test
995995
public void testEqualsWithNull() {
996996

997-
CSVFormat cSVFormat = CSVFormat.POSTGRESQL_TEXT;
997+
final CSVFormat cSVFormat = CSVFormat.POSTGRESQL_TEXT;
998998

999999
assertEquals('\"', (char)cSVFormat.getEscapeCharacter());
10001000
assertFalse(cSVFormat.getIgnoreSurroundingSpaces());
@@ -1058,8 +1058,8 @@ public void testEqualsWithNull() {
10581058
@Test
10591059
public void testToString() {
10601060

1061-
CSVFormat cSVFormat = CSVFormat.POSTGRESQL_TEXT;
1062-
String string = cSVFormat.INFORMIX_UNLOAD.toString();
1061+
final CSVFormat cSVFormat = CSVFormat.POSTGRESQL_TEXT;
1062+
final String string = cSVFormat.INFORMIX_UNLOAD.toString();
10631063

10641064
assertEquals("Delimiter=<|> Escape=<\\> QuoteChar=<\"> RecordSeparator=<\n> EmptyLines:ignored SkipHeaderRecord:false", string);
10651065

@@ -1069,8 +1069,8 @@ public void testToString() {
10691069
@Test
10701070
public void testHashCodeAndWithIgnoreHeaderCase() {
10711071

1072-
CSVFormat cSVFormat = CSVFormat.INFORMIX_UNLOAD_CSV;
1073-
CSVFormat cSVFormatTwo = cSVFormat.withIgnoreHeaderCase();
1072+
final CSVFormat cSVFormat = CSVFormat.INFORMIX_UNLOAD_CSV;
1073+
final CSVFormat cSVFormatTwo = cSVFormat.withIgnoreHeaderCase();
10741074
cSVFormatTwo.hashCode();
10751075

10761076
assertTrue(cSVFormatTwo.getIgnoreHeaderCase());

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public class CSVParserTest {
7474
private static final String[][] RESULT = { { "a", "b", "c", "d" }, { "a", "b", "1 2" }, { "foo baar", "b", "" },
7575
{ "foo\n,,\n\",,\n\"", "d", "e" } };
7676

77-
private BOMInputStream createBOMInputStream(String resource) throws IOException {
77+
private BOMInputStream createBOMInputStream(final String resource) throws IOException {
7878
final URL url = ClassLoader.getSystemClassLoader().getResource(resource);
7979
return new BOMInputStream(url.openStream());
8080
}

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

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ public void testEOLQuoted() throws IOException {
304304

305305
@Test
306306
public void testEscapeBackslash1() throws IOException {
307-
StringWriter sw = new StringWriter();
307+
final StringWriter sw = new StringWriter();
308308
try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(QUOTE_CH))) {
309309
printer.print("\\");
310310
}
@@ -313,7 +313,7 @@ public void testEscapeBackslash1() throws IOException {
313313

314314
@Test
315315
public void testEscapeBackslash2() throws IOException {
316-
StringWriter sw = new StringWriter();
316+
final StringWriter sw = new StringWriter();
317317
try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(QUOTE_CH))) {
318318
printer.print("\\\r");
319319
}
@@ -322,7 +322,7 @@ public void testEscapeBackslash2() throws IOException {
322322

323323
@Test
324324
public void testEscapeBackslash3() throws IOException {
325-
StringWriter sw = new StringWriter();
325+
final StringWriter sw = new StringWriter();
326326
try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(QUOTE_CH))) {
327327
printer.print("X\\\r");
328328
}
@@ -331,7 +331,7 @@ public void testEscapeBackslash3() throws IOException {
331331

332332
@Test
333333
public void testEscapeBackslash4() throws IOException {
334-
StringWriter sw = new StringWriter();
334+
final StringWriter sw = new StringWriter();
335335
try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(QUOTE_CH))) {
336336
printer.print("\\\\");
337337
}
@@ -340,7 +340,7 @@ public void testEscapeBackslash4() throws IOException {
340340

341341
@Test
342342
public void testEscapeBackslash5() throws IOException {
343-
StringWriter sw = new StringWriter();
343+
final StringWriter sw = new StringWriter();
344344
try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuote(QUOTE_CH))) {
345345
printer.print("\\\\");
346346
}
@@ -349,7 +349,7 @@ public void testEscapeBackslash5() throws IOException {
349349

350350
@Test
351351
public void testEscapeNull1() throws IOException {
352-
StringWriter sw = new StringWriter();
352+
final StringWriter sw = new StringWriter();
353353
try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withEscape(null))) {
354354
printer.print("\\");
355355
}
@@ -358,7 +358,7 @@ public void testEscapeNull1() throws IOException {
358358

359359
@Test
360360
public void testEscapeNull2() throws IOException {
361-
StringWriter sw = new StringWriter();
361+
final StringWriter sw = new StringWriter();
362362
try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withEscape(null))) {
363363
printer.print("\\\r");
364364
}
@@ -367,7 +367,7 @@ public void testEscapeNull2() throws IOException {
367367

368368
@Test
369369
public void testEscapeNull3() throws IOException {
370-
StringWriter sw = new StringWriter();
370+
final StringWriter sw = new StringWriter();
371371
try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withEscape(null))) {
372372
printer.print("X\\\r");
373373
}
@@ -376,7 +376,7 @@ public void testEscapeNull3() throws IOException {
376376

377377
@Test
378378
public void testEscapeNull4() throws IOException {
379-
StringWriter sw = new StringWriter();
379+
final StringWriter sw = new StringWriter();
380380
try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withEscape(null))) {
381381
printer.print("\\\\");
382382
}
@@ -385,7 +385,7 @@ public void testEscapeNull4() throws IOException {
385385

386386
@Test
387387
public void testEscapeNull5() throws IOException {
388-
StringWriter sw = new StringWriter();
388+
final StringWriter sw = new StringWriter();
389389
try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withEscape(null))) {
390390
printer.print("\\\\");
391391
}
@@ -1115,7 +1115,7 @@ public void testPrintOnePositiveInteger() throws IOException {
11151115

11161116
@Test
11171117
public void testPrintToFileWithCharsetUtf16Be() throws IOException {
1118-
File file = File.createTempFile(getClass().getName(), ".csv");
1118+
final File file = File.createTempFile(getClass().getName(), ".csv");
11191119
try (final CSVPrinter printer = CSVFormat.DEFAULT.print(file, StandardCharsets.UTF_16BE)) {
11201120
printer.printRecord("a", "b\\c");
11211121
}
@@ -1124,7 +1124,7 @@ public void testPrintToFileWithCharsetUtf16Be() throws IOException {
11241124

11251125
@Test
11261126
public void testPrintToFileWithDefaultCharset() throws IOException {
1127-
File file = File.createTempFile(getClass().getName(), ".csv");
1127+
final File file = File.createTempFile(getClass().getName(), ".csv");
11281128
try (final CSVPrinter printer = CSVFormat.DEFAULT.print(file, Charset.defaultCharset())) {
11291129
printer.printRecord("a", "b\\c");
11301130
}
@@ -1133,7 +1133,7 @@ public void testPrintToFileWithDefaultCharset() throws IOException {
11331133

11341134
@Test
11351135
public void testPrintToPathWithDefaultCharset() throws IOException {
1136-
File file = File.createTempFile(getClass().getName(), ".csv");
1136+
final File file = File.createTempFile(getClass().getName(), ".csv");
11371137
try (final CSVPrinter printer = CSVFormat.DEFAULT.print(file.toPath(), Charset.defaultCharset())) {
11381138
printer.printRecord("a", "b\\c");
11391139
}
@@ -1282,8 +1282,8 @@ private String[] toFirstRecordValues(final String expected, final CSVFormat form
12821282
@Test
12831283
public void testPrintRecordsWithResultSetOneRow() throws IOException, SQLException {
12841284
try (CSVPrinter csvPrinter = CSVFormat.MYSQL.printer()) {
1285-
Value[] valueArray = new Value[0];
1286-
ValueArray valueArrayTwo = ValueArray.get(valueArray);
1285+
final Value[] valueArray = new Value[0];
1286+
final ValueArray valueArrayTwo = ValueArray.get(valueArray);
12871287
try (ResultSet resultSet = valueArrayTwo.getResultSet()) {
12881288
csvPrinter.printRecords(resultSet);
12891289
assertEquals(0, resultSet.getRow());
@@ -1293,10 +1293,10 @@ public void testPrintRecordsWithResultSetOneRow() throws IOException, SQLExcepti
12931293

12941294
@Test
12951295
public void testPrintRecordsWithObjectArray() throws IOException {
1296-
CharArrayWriter charArrayWriter = new CharArrayWriter(0);
1296+
final CharArrayWriter charArrayWriter = new CharArrayWriter(0);
12971297
try (CSVPrinter csvPrinter = CSVFormat.INFORMIX_UNLOAD.print(charArrayWriter)) {
1298-
HashSet<BatchUpdateException> hashSet = new HashSet<>();
1299-
Object[] objectArray = new Object[6];
1298+
final HashSet<BatchUpdateException> hashSet = new HashSet<>();
1299+
final Object[] objectArray = new Object[6];
13001300
objectArray[3] = hashSet;
13011301
csvPrinter.printRecords(objectArray);
13021302
}
@@ -1308,8 +1308,8 @@ public void testPrintRecordsWithObjectArray() throws IOException {
13081308
@Test
13091309
public void testPrintRecordsWithEmptyVector() throws IOException {
13101310
try (CSVPrinter csvPrinter = CSVFormat.POSTGRESQL_TEXT.printer()) {
1311-
Vector<CSVFormatTest.EmptyEnum> vector = new Vector<>();
1312-
int expectedCapacity = 23;
1311+
final Vector<CSVFormatTest.EmptyEnum> vector = new Vector<>();
1312+
final int expectedCapacity = 23;
13131313
vector.setSize(expectedCapacity);
13141314
csvPrinter.printRecords(vector);
13151315
assertEquals(expectedCapacity, vector.capacity());
@@ -1318,27 +1318,27 @@ public void testPrintRecordsWithEmptyVector() throws IOException {
13181318

13191319
@Test
13201320
public void testCloseWithFlushOn() throws IOException {
1321-
Writer writer = mock(Writer.class);
1322-
CSVFormat csvFormat = CSVFormat.DEFAULT;
1323-
CSVPrinter csvPrinter = new CSVPrinter(writer, csvFormat);
1321+
final Writer writer = mock(Writer.class);
1322+
final CSVFormat csvFormat = CSVFormat.DEFAULT;
1323+
final CSVPrinter csvPrinter = new CSVPrinter(writer, csvFormat);
13241324
csvPrinter.close(true);
13251325
verify(writer, times(1)).flush();
13261326
}
13271327

13281328
@Test
13291329
public void testCloseWithFlushOff() throws IOException {
1330-
Writer writer = mock(Writer.class);
1331-
CSVFormat csvFormat = CSVFormat.DEFAULT;
1332-
CSVPrinter csvPrinter = new CSVPrinter(writer, csvFormat);
1330+
final Writer writer = mock(Writer.class);
1331+
final CSVFormat csvFormat = CSVFormat.DEFAULT;
1332+
final CSVPrinter csvPrinter = new CSVPrinter(writer, csvFormat);
13331333
csvPrinter.close(false);
13341334
verify(writer, never()).flush();
13351335
verify(writer, times(1)).close();
13361336
}
13371337

13381338
@Test
13391339
public void testCloseBackwardCompatibility() throws IOException {
1340-
Writer writer = mock(Writer.class);
1341-
CSVFormat csvFormat = CSVFormat.DEFAULT;
1340+
final Writer writer = mock(Writer.class);
1341+
final CSVFormat csvFormat = CSVFormat.DEFAULT;
13421342
try (CSVPrinter csvPrinter = new CSVPrinter(writer, csvFormat)) {
13431343
}
13441344
verify(writer, never()).flush();
@@ -1348,8 +1348,8 @@ public void testCloseBackwardCompatibility() throws IOException {
13481348
@Test
13491349
public void testCloseWithCsvFormatAutoFlushOn() throws IOException {
13501350
// System.out.println("start method");
1351-
Writer writer = mock(Writer.class);
1352-
CSVFormat csvFormat = CSVFormat.DEFAULT.withAutoFlush(true);
1351+
final Writer writer = mock(Writer.class);
1352+
final CSVFormat csvFormat = CSVFormat.DEFAULT.withAutoFlush(true);
13531353
try (CSVPrinter csvPrinter = new CSVPrinter(writer, csvFormat)) {
13541354
}
13551355
verify(writer, times(1)).flush();
@@ -1358,8 +1358,8 @@ public void testCloseWithCsvFormatAutoFlushOn() throws IOException {
13581358

13591359
@Test
13601360
public void testCloseWithCsvFormatAutoFlushOff() throws IOException {
1361-
Writer writer = mock(Writer.class);
1362-
CSVFormat csvFormat = CSVFormat.DEFAULT.withAutoFlush(false);
1361+
final Writer writer = mock(Writer.class);
1362+
final CSVFormat csvFormat = CSVFormat.DEFAULT.withAutoFlush(false);
13631363
try (CSVPrinter csvPrinter = new CSVPrinter(writer, csvFormat)) {
13641364
}
13651365
verify(writer, never()).flush();

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ public class JiraCsv198Test {
3333

3434
@Test
3535
public void test() throws UnsupportedEncodingException, IOException {
36-
InputStream pointsOfReference = getClass().getResourceAsStream("/CSV-198/optd_por_public.csv");
36+
final InputStream pointsOfReference = getClass().getResourceAsStream("/CSV-198/optd_por_public.csv");
3737
Assert.assertNotNull(pointsOfReference);
3838
try (@SuppressWarnings("resource")
3939
CSVParser parser = CSV_FORMAT.parse(new InputStreamReader(pointsOfReference, "UTF-8"))) {
40-
for (CSVRecord record : parser) {
41-
String locationType = record.get("location_type");
40+
for (final CSVRecord record : parser) {
41+
final String locationType = record.get("location_type");
4242
Assert.assertNotNull(locationType);
4343
}
4444
}

0 commit comments

Comments
 (0)