diff --git a/src/main/java/org/apache/commons/csv/CSVFormat.java b/src/main/java/org/apache/commons/csv/CSVFormat.java index c83a9942..337e64c5 100644 --- a/src/main/java/org/apache/commons/csv/CSVFormat.java +++ b/src/main/java/org/apache/commons/csv/CSVFormat.java @@ -195,23 +195,6 @@ public final class CSVFormat implements Serializable { } }; - private static final long serialVersionUID = 1L; - - private final char delimiter; - private final Character quoteCharacter; // null if quoting is disabled - private final QuoteMode quoteMode; - private final Character commentMarker; // null if commenting is disabled - private final Character escapeCharacter; // null if escaping is disabled - private final boolean ignoreSurroundingSpaces; // Should leading/trailing spaces be ignored around values? - private final boolean allowMissingColumnNames; - private final boolean ignoreEmptyLines; - private final String recordSeparator; // for outputs - private final String nullString; // the string to be used for null values - private final String[] header; // array of header column names - private final String[] headerComments; // array of header comment lines - private final boolean skipHeaderRecord; - private final boolean ignoreHeaderCase; // should ignore header names case - /** * Standard comma separated format, as for {@link #RFC4180} but allowing empty lines. * @@ -229,22 +212,6 @@ public final class CSVFormat implements Serializable { public static final CSVFormat DEFAULT = new CSVFormat(COMMA, DOUBLE_QUOTE_CHAR, null, null, null, false, true, CRLF, null, null, null, false, false, false); - /** - * Comma separated format as defined by RFC 4180. - * - *

- * Settings are: - *

- * - * @see Predefined#RFC4180 - */ - public static final CSVFormat RFC4180 = DEFAULT.withIgnoreEmptyLines(false); - /** * Excel file format (using a comma as the value delimiter). Note that the actual value delimiter used by Excel is * locale dependent, it might be necessary to customize this format to accommodate to your regional settings. @@ -274,23 +241,6 @@ public final class CSVFormat implements Serializable { * @see Predefined#Excel */ public static final CSVFormat EXCEL = DEFAULT.withIgnoreEmptyLines(false).withAllowMissingColumnNames(); - - /** - * Tab-delimited format. - * - *

- * Settings are: - *

- * - * @see Predefined#TDF - */ - public static final CSVFormat TDF = DEFAULT.withDelimiter(TAB).withIgnoreSurroundingSpaces(); - /** * Default MySQL format used by the {@code SELECT INTO OUTFILE} and {@code LOAD DATA INFILE} operations. * @@ -317,7 +267,37 @@ public final class CSVFormat implements Serializable { */ public static final CSVFormat MYSQL = DEFAULT.withDelimiter(TAB).withEscape(BACKSLASH).withIgnoreEmptyLines(false) .withQuote(null).withRecordSeparator(LF).withNullString("\\N"); - + /** + * Comma separated format as defined by RFC 4180. + * + *

+ * Settings are: + *

+ * + * @see Predefined#RFC4180 + */ + public static final CSVFormat RFC4180 = DEFAULT.withIgnoreEmptyLines(false); + private static final long serialVersionUID = 1L; + /** + * Tab-delimited format. + * + *

+ * Settings are: + *

+ * + * @see Predefined#TDF + */ + public static final CSVFormat TDF = DEFAULT.withDelimiter(TAB).withIgnoreSurroundingSpaces(); /** * Returns true if the given character is a line break character. * @@ -329,7 +309,6 @@ public final class CSVFormat implements Serializable { private static boolean isLineBreak(final char c) { return c == LF || c == CR; } - /** * Returns true if the given character is a line break character. * @@ -341,7 +320,6 @@ public final class CSVFormat implements Serializable { private static boolean isLineBreak(final Character c) { return c != null && isLineBreak(c.charValue()); } - /** * Creates a new CSV format with the specified delimiter. * @@ -365,7 +343,6 @@ public final class CSVFormat implements Serializable { public static CSVFormat newFormat(final char delimiter) { return new CSVFormat(delimiter, null, null, null, null, false, false, null, null, null, null, false, false, false); } - /** * Gets one of the predefined formats from {@link CSVFormat.Predefined}. * @@ -377,6 +354,29 @@ public final class CSVFormat implements Serializable { public static CSVFormat valueOf(final String format) { return CSVFormat.Predefined.valueOf(format).getFormat(); } + private final boolean allowMissingColumnNames; + private final Character commentMarker; // null if commenting is disabled + private final char delimiter; + private final Character escapeCharacter; // null if escaping is disabled + private final String[] header; // array of header column names + + private final String[] headerComments; // array of header comment lines + + private final boolean ignoreEmptyLines; + + private final boolean ignoreHeaderCase; // should ignore header names case + + private final boolean ignoreSurroundingSpaces; // Should leading/trailing spaces be ignored around values? + + private final String nullString; // the string to be used for null values + + private final Character quoteCharacter; // null if quoting is disabled + + private final QuoteMode quoteMode; + + private final String recordSeparator; // for outputs + + private final boolean skipHeaderRecord; /** * Creates a customized CSV format. @@ -434,18 +434,6 @@ public final class CSVFormat implements Serializable { validate(); } - private String[] toStringArray(final Object[] values) { - if (values == null) { - return null; - } - final String[] strings = new String[values.length]; - for (int i = 0; i < values.length; i++) { - final Object value = values[i]; - strings[i] = value == null ? null : value.toString(); - } - return strings; - } - @Override public boolean equals(final Object obj) { if (this == obj) { @@ -533,6 +521,16 @@ public final class CSVFormat implements Serializable { } } + /** + * Specifies whether missing column names are allowed when parsing the header line. + * + * @return {@code true} if missing column names are allowed when parsing the header line, {@code false} to throw an + * {@link IllegalArgumentException}. + */ + public boolean getAllowMissingColumnNames() { + return allowMissingColumnNames; + } + /** * Returns the character marking the start of a line comment. * @@ -578,16 +576,6 @@ public final class CSVFormat implements Serializable { return headerComments != null ? headerComments.clone() : null; } - /** - * Specifies whether missing column names are allowed when parsing the header line. - * - * @return {@code true} if missing column names are allowed when parsing the header line, {@code false} to throw an - * {@link IllegalArgumentException}. - */ - public boolean getAllowMissingColumnNames() { - return allowMissingColumnNames; - } - /** * Specifies whether empty lines between records are ignored when parsing input. * @@ -598,15 +586,6 @@ public final class CSVFormat implements Serializable { return ignoreEmptyLines; } - /** - * Specifies whether spaces around values are ignored when parsing input. - * - * @return {@code true} if spaces around values are ignored, {@code false} if they are treated as part of the value. - */ - public boolean getIgnoreSurroundingSpaces() { - return ignoreSurroundingSpaces; - } - /** * Specifies whether header names will be accessed ignoring case. * @@ -616,6 +595,15 @@ public final class CSVFormat implements Serializable { return ignoreHeaderCase; } + /** + * Specifies whether spaces around values are ignored when parsing input. + * + * @return {@code true} if spaces around values are ignored, {@code false} if they are treated as part of the value. + */ + public boolean getIgnoreSurroundingSpaces() { + return ignoreSurroundingSpaces; + } + /** * Gets the String to convert to and from {@code null}. *