Refactor and reuse constant.

This commit is contained in:
Gary Gregory 2021-02-22 20:32:34 -05:00
parent 6eef85a663
commit 0b01ea8211
3 changed files with 5 additions and 5 deletions

View File

@ -706,8 +706,8 @@ public final class CSVParser implements Iterable<CSVRecord>, Closeable {
if (!this.recordList.isEmpty()) {
this.recordNumber++;
final String comment = sb == null ? null : sb.toString();
result = new CSVRecord(this, this.recordList.toArray(new String[this.recordList.size()]),
comment, this.recordNumber, startCharPosition);
result = new CSVRecord(this, this.recordList.toArray(Constants.EMPTY_STRING_ARRAY), comment,
this.recordNumber, startCharPosition);
}
return result;
}

View File

@ -40,8 +40,6 @@ import java.util.Objects;
*/
public final class CSVRecord implements Serializable, Iterable<String> {
private static final String[] EMPTY_STRING_ARRAY = new String[0];
private static final long serialVersionUID = 1L;
private final long characterPosition;
@ -61,7 +59,7 @@ public final class CSVRecord implements Serializable, Iterable<String> {
CSVRecord(final CSVParser parser, final String[] values, final String comment, final long recordNumber,
final long characterPosition) {
this.recordNumber = recordNumber;
this.values = values != null ? values : EMPTY_STRING_ARRAY;
this.values = values != null ? values : Constants.EMPTY_STRING_ARRAY;
this.parser = parser;
this.comment = comment;
this.characterPosition = characterPosition;

View File

@ -79,4 +79,6 @@ final class Constants {
/** ASCII unit separator */
static final char US = 31;
static final String[] EMPTY_STRING_ARRAY = new String[0];
}