From 0b01ea82111daf48779159746b76ef27d0d7eac7 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Mon, 22 Feb 2021 20:32:34 -0500 Subject: [PATCH] Refactor and reuse constant. --- src/main/java/org/apache/commons/csv/CSVParser.java | 4 ++-- src/main/java/org/apache/commons/csv/CSVRecord.java | 4 +--- src/main/java/org/apache/commons/csv/Constants.java | 2 ++ 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/apache/commons/csv/CSVParser.java b/src/main/java/org/apache/commons/csv/CSVParser.java index bf6eb6d6..286901a2 100644 --- a/src/main/java/org/apache/commons/csv/CSVParser.java +++ b/src/main/java/org/apache/commons/csv/CSVParser.java @@ -706,8 +706,8 @@ public final class CSVParser implements Iterable, 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; } diff --git a/src/main/java/org/apache/commons/csv/CSVRecord.java b/src/main/java/org/apache/commons/csv/CSVRecord.java index f3b023f6..96582e59 100644 --- a/src/main/java/org/apache/commons/csv/CSVRecord.java +++ b/src/main/java/org/apache/commons/csv/CSVRecord.java @@ -40,8 +40,6 @@ import java.util.Objects; */ public final class CSVRecord implements Serializable, Iterable { - 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 { 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; diff --git a/src/main/java/org/apache/commons/csv/Constants.java b/src/main/java/org/apache/commons/csv/Constants.java index b7dc770a..10c20062 100644 --- a/src/main/java/org/apache/commons/csv/Constants.java +++ b/src/main/java/org/apache/commons/csv/Constants.java @@ -79,4 +79,6 @@ final class Constants { /** ASCII unit separator */ static final char US = 31; + static final String[] EMPTY_STRING_ARRAY = new String[0]; + }