@@ -884,11 +884,21 @@ public String format(final Object... values) {
884884 }
885885 }
886886
887+ /**
888+ * Returns true if and only if duplicate names are allowed in the headers.
889+ *
890+ * @return whether duplicate header names are allowed
891+ * @since 1.7
892+ */
893+ public boolean getAllowDuplicateHeaderNames () {
894+ return duplicateHeaderMode == DuplicateHeaderMode .ALLOW_ALL ;
895+ }
896+
887897 /**
888898 * Returns how duplicate headers are handled.
889899 *
890900 * @return if duplicate header values are allowed, allowed conditionally, or disallowed.
891- * @since 1.7
901+ * @since 1.9
892902 */
893903 public DuplicateHeaderMode getDuplicateHeaderMode () {
894904 return duplicateHeaderMode ;
@@ -1687,13 +1697,30 @@ public CSVFormat withAllowDuplicateHeaderNames() {
16871697 return withDuplicateHeaderMode (DuplicateHeaderMode .ALLOW_ALL );
16881698 }
16891699
1700+ /**
1701+ * Returns a new {@code CSVFormat} with duplicate header names behavior set to the given value.
1702+ *
1703+ * @param allowDuplicateHeaderNames the duplicate header names behavior, true to allow, false to disallow.
1704+ * @return a new {@code CSVFormat} with duplicate header names behavior set to the given value.
1705+ * @since 1.7
1706+ */
1707+ public CSVFormat withAllowDuplicateHeaderNames (final boolean allowDuplicateHeaderNames ) {
1708+ final DuplicateHeaderMode mode =
1709+ (allowDuplicateHeaderNames ) ? DuplicateHeaderMode .ALLOW_ALL : DuplicateHeaderMode .ALLOW_EMPTY ;
1710+
1711+ return new CSVFormat (delimiter , quoteCharacter , quoteMode , commentMarker , escapeCharacter ,
1712+ ignoreSurroundingSpaces , ignoreEmptyLines , recordSeparator , nullString , headerComments , header ,
1713+ skipHeaderRecord , allowMissingColumnNames , ignoreHeaderCase , trim , trailingDelimiter , autoFlush ,
1714+ mode );
1715+ }
1716+
16901717 /**
16911718 * Returns a new {@code CSVFormat} with duplicate header names behavior set to the given value.
16921719 *
16931720 * @param duplicateHeaderMode the duplicate header names behavior, to allow, allow conditionally,
16941721 * or disable duplicates.
16951722 * @return a new {@code CSVFormat} with duplicate header names behavior set to the given value.
1696- * @since 1.7
1723+ * @since 1.9
16971724 */
16981725 public CSVFormat withDuplicateHeaderMode (final DuplicateHeaderMode duplicateHeaderMode ) {
16991726 return new CSVFormat (delimiter , quoteCharacter , quoteMode , commentMarker , escapeCharacter ,
0 commit comments