Skip to content

Commit 4dc7789

Browse files
committed
CSV-134: code refactor
1 parent f2e3665 commit 4dc7789

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,7 @@ private CSVFormat(final char delimiter, final Character quoteChar,
345345
final boolean ignoreEmptyLines, final String recordSeparator,
346346
final String nullString, final Object[] headerComments, final String[] header,
347347
final boolean skipHeaderRecord, final boolean allowMissingColumnNames) {
348-
if (isLineBreak(delimiter)) {
349-
throw new IllegalArgumentException("The delimiter cannot be a line break");
350-
}
348+
351349
this.delimiter = delimiter;
352350
this.quoteCharacter = quoteChar;
353351
this.quoteMode = quoteMode;
@@ -362,13 +360,6 @@ private CSVFormat(final char delimiter, final Character quoteChar,
362360
if (header == null) {
363361
this.header = null;
364362
} else {
365-
final Set<String> dupCheck = new HashSet<String>();
366-
for (final String hdr : header) {
367-
if (!dupCheck.add(hdr)) {
368-
throw new IllegalArgumentException("The header contains a duplicate entry: '" + hdr + "' in " +
369-
Arrays.toString(header));
370-
}
371-
}
372363
this.header = header.clone();
373364
}
374365
this.skipHeaderRecord = skipHeaderRecord;
@@ -742,6 +733,19 @@ public String toString() {
742733
* @throws IllegalArgumentException
743734
*/
744735
private void validate() throws IllegalArgumentException {
736+
737+
if (isLineBreak(delimiter)) {
738+
throw new IllegalArgumentException("The delimiter cannot be a line break");
739+
}
740+
741+
final Set<String> dupCheck = new HashSet<String>();
742+
for (final String hdr : header) {
743+
if (!dupCheck.add(hdr)) {
744+
throw new IllegalArgumentException("The header contains a duplicate entry: '" + hdr + "' in " +
745+
Arrays.toString(header));
746+
}
747+
}
748+
745749
if (quoteCharacter != null && delimiter == quoteCharacter.charValue()) {
746750
throw new IllegalArgumentException(
747751
"The quoteChar character and the delimiter cannot be the same ('" + quoteCharacter + "')");

0 commit comments

Comments
 (0)