Skip to content

Commit 1682795

Browse files
committed
Minor Improvement:
* Add final * Unnecessary semicolon '' * Use StandardCharsets * Fix javadoc
1 parent 155a769 commit 1682795

6 files changed

Lines changed: 15 additions & 13 deletions

File tree

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,7 +1402,6 @@ private void printWithQuotes(final Object object, final CharSequence value, fina
14021402
int start = 0;
14031403
int pos = 0;
14041404
final int len = value.length();
1405-
final int end = len;
14061405

14071406
final char delimChar = getDelimiter();
14081407
final char quoteChar = getQuoteCharacter().charValue();
@@ -1445,7 +1444,7 @@ private void printWithQuotes(final Object object, final CharSequence value, fina
14451444
// by including the default comment char too.
14461445
quote = true;
14471446
} else {
1448-
while (pos < end) {
1447+
while (pos < len) {
14491448
c = value.charAt(pos);
14501449
if (c == LF || c == CR || c == quoteChar || c == delimChar || c == escapeChar) {
14511450
quote = true;
@@ -1455,7 +1454,7 @@ private void printWithQuotes(final Object object, final CharSequence value, fina
14551454
}
14561455

14571456
if (!quote) {
1458-
pos = end - 1;
1457+
pos = len - 1;
14591458
c = value.charAt(pos);
14601459
// Some other chars at the end caused the parser to fail, so for now
14611460
// encapsulate if we end in anything less than ' '
@@ -1468,7 +1467,7 @@ private void printWithQuotes(final Object object, final CharSequence value, fina
14681467

14691468
if (!quote) {
14701469
// no encapsulation needed - write out the original value
1471-
out.append(value, start, end);
1470+
out.append(value, start, len);
14721471
return;
14731472
}
14741473
break;
@@ -1478,7 +1477,7 @@ private void printWithQuotes(final Object object, final CharSequence value, fina
14781477

14791478
if (!quote) {
14801479
// no encapsulation needed - write out the original value
1481-
out.append(value, start, end);
1480+
out.append(value, start, len);
14821481
return;
14831482
}
14841483

@@ -1487,7 +1486,7 @@ private void printWithQuotes(final Object object, final CharSequence value, fina
14871486

14881487
// Pick up where we left off: pos should be positioned on the first character that caused
14891488
// the need for encapsulation.
1490-
while (pos < end) {
1489+
while (pos < len) {
14911490
final char c = value.charAt(pos);
14921491
if (c == quoteChar || c == escapeChar) {
14931492
// write out the chunk up until this point
@@ -1507,6 +1506,7 @@ private void printWithQuotes(final Object object, final CharSequence value, fina
15071506
* Always use quotes unless QuoteMode is NONE, so we not have to look ahead.
15081507
*
15091508
* @throws IOException
1509+
* If an I/O error occurs
15101510
*/
15111511
private void printWithQuotes(final Reader reader, final Appendable out) throws IOException {
15121512

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.io.IOException;
2424
import java.io.InputStream;
2525
import java.io.StringReader;
26+
import java.nio.charset.StandardCharsets;
2627
import java.util.List;
2728
import java.util.concurrent.TimeUnit;
2829
import java.util.zip.GZIPInputStream;
@@ -63,7 +64,7 @@ public class CSVBenchmark {
6364
public void init() throws IOException {
6465
final File file = new File("src/test/resources/perf/worldcitiespop.txt.gz");
6566
final InputStream in = new GZIPInputStream(new FileInputStream(file));
66-
this.data = IOUtils.toString(in, "ISO-8859-1");
67+
this.data = IOUtils.toString(in, StandardCharsets.ISO_8859_1);
6768
in.close();
6869
}
6970

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.io.IOException;
3030
import java.net.URL;
3131
import java.nio.charset.Charset;
32+
import java.nio.charset.StandardCharsets;
3233
import java.util.Arrays;
3334
import java.util.stream.Stream;
3435

@@ -135,7 +136,7 @@ public void testCSVUrl(final File testFile) throws Exception {
135136

136137
// Now parse the file and compare against the expected results
137138
final URL resource = ClassLoader.getSystemResource("org/apache/commons/csv/CSVFileParser/" + split[0]);
138-
try (final CSVParser parser = CSVParser.parse(resource, Charset.forName("UTF-8"), format)) {
139+
try (final CSVParser parser = CSVParser.parse(resource, StandardCharsets.UTF_8, format)) {
139140
for (final CSVRecord record : parser) {
140141
String parsed = Arrays.toString(record.values());
141142
final String comment = record.getComment();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ public void testGetOneLine() throws IOException {
572572
/**
573573
* Tests reusing a parser to process new string records one at a time as they are being discovered. See [CSV-110].
574574
*
575-
* @throws IOException
575+
* @throws IOException when an I/O error occurs.
576576
*/
577577
@Test
578578
public void testGetOneLineOneParser() throws IOException {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ public void testJdbcPrinter() throws IOException, ClassNotFoundException, SQLExc
635635
public void testJdbcPrinterWithResultSet() throws IOException, ClassNotFoundException, SQLException {
636636
final StringWriter sw = new StringWriter();
637637
Class.forName("org.h2.Driver");
638-
try (final Connection connection = geH2Connection();) {
638+
try (final Connection connection = geH2Connection()) {
639639
setUpTable(connection);
640640
try (final Statement stmt = connection.createStatement();
641641
final ResultSet resultSet = stmt.executeQuery("select ID, NAME, TEXT from TEST");

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public class PerformanceTest {
6464
private static int max = 11; // skip first test
6565

6666
private static int num = 0; // number of elapsed times recorded
67-
private static long[] elapsedTimes = new long[max];
67+
private static final long[] ELAPSED_TIMES = new long[max];
6868

6969
private static final CSVFormat format = CSVFormat.EXCEL;
7070

@@ -149,7 +149,7 @@ private static class Stats {
149149
private static void show(final String msg, final Stats s, final long start) {
150150
final long elapsed = System.currentTimeMillis() - start;
151151
System.out.printf("%-20s: %5dms %d lines %d fields%n", msg, elapsed, s.count, s.fields);
152-
elapsedTimes[num] = elapsed;
152+
ELAPSED_TIMES[num] = elapsed;
153153
num++;
154154
}
155155

@@ -158,7 +158,7 @@ private static void show(){
158158
if (num > 1) {
159159
long tot = 0;
160160
for (int i = 1; i < num; i++) { // skip first test
161-
tot += elapsedTimes[i];
161+
tot += ELAPSED_TIMES[i];
162162
}
163163
System.out.printf("%-20s: %5dms%n%n", "Average(not first)", tot / (num - 1));
164164
}

0 commit comments

Comments
 (0)