Skip to content

Commit 0b0003e

Browse files
committed
Simplify new API name and parameter names
1 parent c75601d commit 0b0003e

File tree

4 files changed

+24
-24
lines changed

4 files changed

+24
-24
lines changed

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public static class Builder extends AbstractStreamBuilder<CSVParser, Builder> {
155155
private CSVFormat format;
156156
private long characterOffset;
157157
private long recordNumber = 1;
158-
private boolean enableByteTracking;
158+
private boolean trackBytes;
159159

160160
/**
161161
* Constructs a new instance.
@@ -167,7 +167,7 @@ protected Builder() {
167167
@SuppressWarnings("resource")
168168
@Override
169169
public CSVParser get() throws IOException {
170-
return new CSVParser(getReader(), format != null ? format : CSVFormat.DEFAULT, characterOffset, recordNumber, getCharset(), enableByteTracking);
170+
return new CSVParser(getReader(), format != null ? format : CSVFormat.DEFAULT, characterOffset, recordNumber, getCharset(), trackBytes);
171171
}
172172

173173
/**
@@ -181,18 +181,6 @@ public Builder setCharacterOffset(final long characterOffset) {
181181
return asThis();
182182
}
183183

184-
/**
185-
* Sets whether to enable byte tracking for the parser.
186-
*
187-
* @param enableByteTracking {@code true} to enable byte tracking; {@code false} to disable it.
188-
* @return this instance.
189-
* @since 1.13.0
190-
*/
191-
public Builder setEnableByteTracking(final boolean enableByteTracking) {
192-
this.enableByteTracking = enableByteTracking;
193-
return asThis();
194-
}
195-
196184
/**
197185
* Sets the CSV format. A copy of the given format is kept.
198186
*
@@ -215,6 +203,18 @@ public Builder setRecordNumber(final long recordNumber) {
215203
return asThis();
216204
}
217205

206+
/**
207+
* Sets whether to enable byte tracking for the parser.
208+
*
209+
* @param trackBytes {@code true} to enable byte tracking; {@code false} to disable it.
210+
* @return this instance.
211+
* @since 1.13.0
212+
*/
213+
public Builder setTrackBytes(final boolean trackBytes) {
214+
this.trackBytes = trackBytes;
215+
return asThis();
216+
}
217+
218218
}
219219

220220
final class CSVRecordIterator implements Iterator<CSVRecord> {
@@ -544,7 +544,7 @@ public CSVParser(final Reader reader, final CSVFormat format, final long charact
544544
* The next record number to assign.
545545
* @param charset
546546
* The character encoding to be used for the reader when enableByteTracking is true.
547-
* @param enableByteTracking
547+
* @param trackBytes
548548
* {@code true} to enable byte tracking for the parser; {@code false} to disable it.
549549
* @throws IllegalArgumentException
550550
* If the parameters of the format are inconsistent or if either the reader or format is null.
@@ -553,12 +553,12 @@ public CSVParser(final Reader reader, final CSVFormat format, final long charact
553553
* @throws CSVException Thrown on invalid input.
554554
*/
555555
private CSVParser(final Reader reader, final CSVFormat format, final long characterOffset, final long recordNumber,
556-
final Charset charset, final boolean enableByteTracking)
556+
final Charset charset, final boolean trackBytes)
557557
throws IOException {
558558
Objects.requireNonNull(reader, "reader");
559559
Objects.requireNonNull(format, "format");
560560
this.format = format.copy();
561-
this.lexer = new Lexer(format, new ExtendedBufferedReader(reader, charset, enableByteTracking));
561+
this.lexer = new Lexer(format, new ExtendedBufferedReader(reader, charset, trackBytes));
562562
this.csvRecordIterator = new CSVRecordIterator();
563563
this.headers = createHeaders();
564564
this.characterOffset = characterOffset;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ final class ExtendedBufferedReader extends UnsynchronizedBufferedReader {
7676
*
7777
* @param reader the reader supports a look-ahead option.
7878
* @param charset the character set for encoding, or {@code null} if not applicable.
79-
* @param enableByteTracking {@code true} to enable byte tracking; {@code false} to disable it.
79+
* @param trackBytes {@code true} to enable byte tracking; {@code false} to disable it.
8080
*/
81-
ExtendedBufferedReader(final Reader reader, final Charset charset, final boolean enableByteTracking) {
81+
ExtendedBufferedReader(final Reader reader, final Charset charset, final boolean trackBytes) {
8282
super(reader);
83-
if (charset != null && enableByteTracking) {
83+
if (charset != null && trackBytes) {
8484
encoder = charset.newEncoder();
8585
}
8686
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ public void testGetRecordFourBytesRead() throws Exception {
818818
.setDelimiter(',')
819819
.setQuote('\'')
820820
.get();
821-
try (CSVParser parser = CSVParser.builder().setReader(new StringReader(code)).setFormat(format).setCharset(UTF_8).setEnableByteTracking(true).get()) {
821+
try (CSVParser parser = CSVParser.builder().setReader(new StringReader(code)).setFormat(format).setCharset(UTF_8).setTrackBytes(true).get()) {
822822
CSVRecord record = new CSVRecord(parser, null, null, 1L, 0L, 0L);
823823

824824
assertEquals(0, parser.getRecordNumber());
@@ -897,7 +897,7 @@ public void testGetRecordThreeBytesRead() throws Exception {
897897
.setDelimiter(',')
898898
.setQuote('\'')
899899
.get();
900-
try (CSVParser parser = CSVParser.builder().setReader(new StringReader(code)).setFormat(format).setCharset(UTF_8).setEnableByteTracking(true).get() ) {
900+
try (CSVParser parser = CSVParser.builder().setReader(new StringReader(code)).setFormat(format).setCharset(UTF_8).setTrackBytes(true).get() ) {
901901
CSVRecord record = new CSVRecord(parser, null, null, 1L, 0L, 0L);
902902

903903
assertEquals(0, parser.getRecordNumber());

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ private Reader getTestInput(final String path) {
3737
public void testParseFourBytes() throws IOException {
3838
final CSVFormat format = CSVFormat.Builder.create().setDelimiter(',').setQuote('\'').get();
3939
try (CSVParser parser = new CSVParser.Builder().setFormat(format).setReader(getTestInput("org/apache/commons/csv/CSV-196/emoji.csv"))
40-
.setCharset(StandardCharsets.UTF_8).setEnableByteTracking(true).get()) {
40+
.setCharset(StandardCharsets.UTF_8).setTrackBytes(true).get()) {
4141
final long[] charByteKey = { 0, 84, 701, 1318, 1935 };
4242
int idx = 0;
4343
for (CSVRecord record : parser) {
@@ -50,7 +50,7 @@ public void testParseFourBytes() throws IOException {
5050
public void testParseThreeBytes() throws IOException {
5151
final CSVFormat format = CSVFormat.Builder.create().setDelimiter(',').setQuote('\'').get();
5252
try (CSVParser parser = new CSVParser.Builder().setFormat(format).setReader(getTestInput("org/apache/commons/csv/CSV-196/japanese.csv"))
53-
.setCharset(StandardCharsets.UTF_8).setEnableByteTracking(true).get()) {
53+
.setCharset(StandardCharsets.UTF_8).setTrackBytes(true).get()) {
5454
final long[] charByteKey = { 0, 89, 242, 395 };
5555
int idx = 0;
5656
for (CSVRecord record : parser) {

0 commit comments

Comments
 (0)