Skip to content

Commit 0b01ea8

Browse files
committed
Refactor and reuse constant.
1 parent 6eef85a commit 0b01ea8

3 files changed

Lines changed: 5 additions & 5 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -706,8 +706,8 @@ CSVRecord nextRecord() throws IOException {
706706
if (!this.recordList.isEmpty()) {
707707
this.recordNumber++;
708708
final String comment = sb == null ? null : sb.toString();
709-
result = new CSVRecord(this, this.recordList.toArray(new String[this.recordList.size()]),
710-
comment, this.recordNumber, startCharPosition);
709+
result = new CSVRecord(this, this.recordList.toArray(Constants.EMPTY_STRING_ARRAY), comment,
710+
this.recordNumber, startCharPosition);
711711
}
712712
return result;
713713
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@
4040
*/
4141
public final class CSVRecord implements Serializable, Iterable<String> {
4242

43-
private static final String[] EMPTY_STRING_ARRAY = new String[0];
44-
4543
private static final long serialVersionUID = 1L;
4644

4745
private final long characterPosition;
@@ -61,7 +59,7 @@ public final class CSVRecord implements Serializable, Iterable<String> {
6159
CSVRecord(final CSVParser parser, final String[] values, final String comment, final long recordNumber,
6260
final long characterPosition) {
6361
this.recordNumber = recordNumber;
64-
this.values = values != null ? values : EMPTY_STRING_ARRAY;
62+
this.values = values != null ? values : Constants.EMPTY_STRING_ARRAY;
6563
this.parser = parser;
6664
this.comment = comment;
6765
this.characterPosition = characterPosition;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,6 @@ final class Constants {
7979
/** ASCII unit separator */
8080
static final char US = 31;
8181

82+
static final String[] EMPTY_STRING_ARRAY = new String[0];
83+
8284
}

0 commit comments

Comments
 (0)