Skip to content
This repository was archived by the owner on Jun 3, 2026. It is now read-only.

Commit b502c5a

Browse files
committed
Sort 1 method into place.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1742957 13f79535-47bb-0310-9956-ffa450edef68
1 parent 8b24cd1 commit b502c5a

1 file changed

Lines changed: 35 additions & 35 deletions

File tree

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

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,41 @@ public CSVFormat withFirstRecordAsHeader() {
10961096
return withHeader().withSkipHeaderRecord();
10971097
}
10981098

1099+
/**
1100+
* Returns a new {@code CSVFormat} with the header of the format defined by the enum class:
1101+
*
1102+
* <pre>
1103+
* public enum Header {
1104+
* Name, Email, Phone
1105+
* }
1106+
*
1107+
* CSVFormat format = aformat.withHeader(Header.class);
1108+
* </pre>
1109+
* <p>
1110+
* The header is also used by the {@link CSVPrinter}..
1111+
* </p>
1112+
*
1113+
* @param headerEnum
1114+
* the enum defining the header, {@code null} if disabled, empty if parsed automatically, user
1115+
* specified otherwise.
1116+
*
1117+
* @return A new CSVFormat that is equal to this but with the specified header
1118+
* @see #withHeader(String...)
1119+
* @see #withSkipHeaderRecord(boolean)
1120+
* @since 1.3
1121+
*/
1122+
public CSVFormat withHeader(final Class<? extends Enum<?>> headerEnum) {
1123+
String[] header = null;
1124+
if (headerEnum != null) {
1125+
Enum<?>[] enumValues = headerEnum.getEnumConstants();
1126+
header = new String[enumValues.length];
1127+
for (int i = 0; i < enumValues.length; i++) {
1128+
header[i] = enumValues[i].name();
1129+
}
1130+
}
1131+
return withHeader(header);
1132+
}
1133+
10991134
/**
11001135
* Returns a new {@code CSVFormat} with the header of the format set from the result set metadata. The header can
11011136
* either be parsed automatically from the input file with:
@@ -1193,41 +1228,6 @@ public CSVFormat withHeader(final String... header) {
11931228
skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase, trim, trailingDelimiter);
11941229
}
11951230

1196-
/**
1197-
* Returns a new {@code CSVFormat} with the header of the format defined by the enum class:
1198-
*
1199-
* <pre>
1200-
* public enum Header {
1201-
* Name, Email, Phone
1202-
* }
1203-
*
1204-
* CSVFormat format = aformat.withHeader(Header.class);
1205-
* </pre>
1206-
* <p>
1207-
* The header is also used by the {@link CSVPrinter}..
1208-
* </p>
1209-
*
1210-
* @param headerEnum
1211-
* the enum defining the header, {@code null} if disabled, empty if parsed automatically, user
1212-
* specified otherwise.
1213-
*
1214-
* @return A new CSVFormat that is equal to this but with the specified header
1215-
* @see #withHeader(String...)
1216-
* @see #withSkipHeaderRecord(boolean)
1217-
* @since 1.3
1218-
*/
1219-
public CSVFormat withHeader(final Class<? extends Enum<?>> headerEnum) {
1220-
String[] header = null;
1221-
if (headerEnum != null) {
1222-
Enum<?>[] enumValues = headerEnum.getEnumConstants();
1223-
header = new String[enumValues.length];
1224-
for (int i = 0; i < enumValues.length; i++) {
1225-
header[i] = enumValues[i].name();
1226-
}
1227-
}
1228-
return withHeader(header);
1229-
}
1230-
12311231
/**
12321232
* Returns a new {@code CSVFormat} with the header comments of the format set to the given values. The comments will
12331233
* be printed first, before the headers. This setting is ignored by the parser.

0 commit comments

Comments
 (0)