diff --git a/src/main/java/org/apache/commons/csv/CSVFormat.java b/src/main/java/org/apache/commons/csv/CSVFormat.java index 63d1c14d..8628bf8b 100644 --- a/src/main/java/org/apache/commons/csv/CSVFormat.java +++ b/src/main/java/org/apache/commons/csv/CSVFormat.java @@ -1096,6 +1096,41 @@ public final class CSVFormat implements Serializable { return withHeader().withSkipHeaderRecord(); } + /** + * Returns a new {@code CSVFormat} with the header of the format defined by the enum class: + * + *
+ * public enum Header { + * Name, Email, Phone + * } + * + * CSVFormat format = aformat.withHeader(Header.class); + *+ *
+ * The header is also used by the {@link CSVPrinter}.. + *
+ * + * @param headerEnum + * the enum defining the header, {@code null} if disabled, empty if parsed automatically, user + * specified otherwise. + * + * @return A new CSVFormat that is equal to this but with the specified header + * @see #withHeader(String...) + * @see #withSkipHeaderRecord(boolean) + * @since 1.3 + */ + public CSVFormat withHeader(final Class extends Enum>> headerEnum) { + String[] header = null; + if (headerEnum != null) { + Enum>[] enumValues = headerEnum.getEnumConstants(); + header = new String[enumValues.length]; + for (int i = 0; i < enumValues.length; i++) { + header[i] = enumValues[i].name(); + } + } + return withHeader(header); + } + /** * Returns a new {@code CSVFormat} with the header of the format set from the result set metadata. The header can * either be parsed automatically from the input file with: @@ -1193,41 +1228,6 @@ public final class CSVFormat implements Serializable { skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase, trim, trailingDelimiter); } - /** - * Returns a new {@code CSVFormat} with the header of the format defined by the enum class: - * - *- * public enum Header { - * Name, Email, Phone - * } - * - * CSVFormat format = aformat.withHeader(Header.class); - *- *
- * The header is also used by the {@link CSVPrinter}.. - *
- * - * @param headerEnum - * the enum defining the header, {@code null} if disabled, empty if parsed automatically, user - * specified otherwise. - * - * @return A new CSVFormat that is equal to this but with the specified header - * @see #withHeader(String...) - * @see #withSkipHeaderRecord(boolean) - * @since 1.3 - */ - public CSVFormat withHeader(final Class extends Enum>> headerEnum) { - String[] header = null; - if (headerEnum != null) { - Enum>[] enumValues = headerEnum.getEnumConstants(); - header = new String[enumValues.length]; - for (int i = 0; i < enumValues.length; i++) { - header[i] = enumValues[i].name(); - } - } - return withHeader(header); - } - /** * Returns a new {@code CSVFormat} with the header comments of the format set to the given values. The comments will * be printed first, before the headers. This setting is ignored by the parser.