Modified: websites/production/commons/content/proper/commons-csv/jacoco/org.apache.commons.csv/CSVFormat.java.html ============================================================================== --- websites/production/commons/content/proper/commons-csv/jacoco/org.apache.commons.csv/CSVFormat.java.html (original) +++ websites/production/commons/content/proper/commons-csv/jacoco/org.apache.commons.csv/CSVFormat.java.html Sun May 29 02:24:04 2016 @@ -19,11 +19,13 @@ package org.apache.commons.csv; import static org.apache.commons.csv.Constants.BACKSLASH; import static org.apache.commons.csv.Constants.COMMA; +import static org.apache.commons.csv.Constants.COMMENT; import static org.apache.commons.csv.Constants.CR; import static org.apache.commons.csv.Constants.CRLF; import static org.apache.commons.csv.Constants.DOUBLE_QUOTE_CHAR; import static org.apache.commons.csv.Constants.LF; import static org.apache.commons.csv.Constants.PIPE; +import static org.apache.commons.csv.Constants.SP; import static org.apache.commons.csv.Constants.TAB; import java.io.IOException; @@ -144,7 +146,7 @@ import java.util.Set; * This class is immutable. * </p> * - * @version $Id: CSVFormat.java 1742506 2016-05-06 07:07:43Z britter $ + * @version $Id: CSVFormat.java 1745258 2016-05-23 20:24:33Z ggregory $ */ public final class CSVFormat implements Serializable { @@ -153,50 +155,50 @@ public final class CSVFormat implements * * @since 1.2 */ -<span class="fc" id="L156"> public enum Predefined {</span> +<span class="fc" id="L158"> public enum Predefined {</span> /** * @see CSVFormat#DEFAULT */ -<span class="fc" id="L161"> Default(CSVFormat.DEFAULT),</span> +<span class="fc" id="L163"> Default(CSVFormat.DEFAULT),</span> /** * @see CSVFormat#EXCEL */ -<span class="fc" id="L166"> Excel(CSVFormat.EXCEL),</span> +<span class="fc" id="L168"> Excel(CSVFormat.EXCEL),</span> /** * @see CSVFormat#INFORMIX_UNLOAD * @since 1.3 */ -<span class="fc" id="L172"> InformixUnload(CSVFormat.INFORMIX_UNLOAD),</span> +<span class="fc" id="L174"> InformixUnload(CSVFormat.INFORMIX_UNLOAD),</span> /** * @see CSVFormat#INFORMIX_UNLOAD_CSV * @since 1.3 */ -<span class="fc" id="L178"> InformixUnloadCsv(CSVFormat.INFORMIX_UNLOAD_CSV),</span> +<span class="fc" id="L180"> InformixUnloadCsv(CSVFormat.INFORMIX_UNLOAD_CSV),</span> /** * @see CSVFormat#MYSQL */ -<span class="fc" id="L183"> MySQL(CSVFormat.MYSQL),</span> +<span class="fc" id="L185"> MySQL(CSVFormat.MYSQL),</span> /** * @see CSVFormat#RFC4180 */ -<span class="fc" id="L188"> RFC4180(CSVFormat.RFC4180),</span> +<span class="fc" id="L190"> RFC4180(CSVFormat.RFC4180),</span> /** * @see CSVFormat#TDF */ -<span class="fc" id="L193"> TDF(CSVFormat.TDF);</span> +<span class="fc" id="L195"> TDF(CSVFormat.TDF);</span> private final CSVFormat format; -<span class="fc" id="L197"> Predefined(final CSVFormat format) {</span> -<span class="fc" id="L198"> this.format = format;</span> -<span class="fc" id="L199"> }</span> +<span class="fc" id="L199"> Predefined(final CSVFormat format) {</span> +<span class="fc" id="L200"> this.format = format;</span> +<span class="fc" id="L201"> }</span> /** * Gets the format. @@ -204,7 +206,7 @@ public final class CSVFormat implements * @return the format. */ public CSVFormat getFormat() { -<span class="fc" id="L207"> return format;</span> +<span class="fc" id="L209"> return format;</span> } } @@ -223,7 +225,7 @@ public final class CSVFormat implements * * @see Predefined#Default */ -<span class="fc" id="L226"> public static final CSVFormat DEFAULT = new CSVFormat(COMMA, DOUBLE_QUOTE_CHAR, null, null, null, false, true, CRLF,</span> +<span class="fc" id="L228"> public static final CSVFormat DEFAULT = new CSVFormat(COMMA, DOUBLE_QUOTE_CHAR, null, null, null, false, true, CRLF,</span> null, null, null, false, false, false, false, false); /** @@ -255,7 +257,7 @@ public final class CSVFormat implements * * @see Predefined#Excel */ -<span class="fc" id="L258"> public static final CSVFormat EXCEL = DEFAULT.withIgnoreEmptyLines(false).withAllowMissingColumnNames();</span> +<span class="fc" id="L260"> public static final CSVFormat EXCEL = DEFAULT.withIgnoreEmptyLines(false).withAllowMissingColumnNames();</span> /** * Default Informix CSV UNLOAD format used by the {@code UNLOAD TO file_name} operation. @@ -281,11 +283,11 @@ public final class CSVFormat implements * http://www.ibm.com/support/knowledgecenter/SSBJG3_2.5.0/com.ibm.gen_busug.doc/c_fgl_InOutSql_UNLOAD.htm</a> * @since 1.3 */ -<span class="fc" id="L284"> public static final CSVFormat INFORMIX_UNLOAD = DEFAULT.withDelimiter(PIPE).withEscape(BACKSLASH)</span> -<span class="fc" id="L285"> .withQuote(DOUBLE_QUOTE_CHAR).withRecordSeparator(LF);</span> +<span class="fc" id="L286"> public static final CSVFormat INFORMIX_UNLOAD = DEFAULT.withDelimiter(PIPE).withEscape(BACKSLASH)</span> + .withQuote(DOUBLE_QUOTE_CHAR).withRecordSeparator(LF); /** - * Default Informix CSV UNLOAD format used by the {@code UNLOAD TO file_name} operation. + * Default Informix CSV UNLOAD format used by the {@code UNLOAD TO file_name} operation (escaping is disabled.) * * <p> * This is a comma-delimited format with a LF character as the line separator. Values are not quoted and special @@ -307,8 +309,8 @@ public final class CSVFormat implements * http://www.ibm.com/support/knowledgecenter/SSBJG3_2.5.0/com.ibm.gen_busug.doc/c_fgl_InOutSql_UNLOAD.htm</a> * @since 1.3 */ -<span class="fc" id="L310"> public static final CSVFormat INFORMIX_UNLOAD_CSV = DEFAULT.withDelimiter(COMMA).withQuote(DOUBLE_QUOTE_CHAR)</span> -<span class="fc" id="L311"> .withRecordSeparator(LF);</span> +<span class="fc" id="L312"> public static final CSVFormat INFORMIX_UNLOAD_CSV = DEFAULT.withDelimiter(COMMA).withQuote(DOUBLE_QUOTE_CHAR)</span> + .withRecordSeparator(LF); /** * Default MySQL format used by the {@code SELECT INTO OUTFILE} and {@code LOAD DATA INFILE} operations. @@ -334,8 +336,8 @@ public final class CSVFormat implements * @see <a href="http://dev.mysql.com/doc/refman/5.1/en/load-data.html"> http://dev.mysql.com/doc/refman/5.1/en/load * -data.html</a> */ -<span class="fc" id="L337"> public static final CSVFormat MYSQL = DEFAULT.withDelimiter(TAB).withEscape(BACKSLASH).withIgnoreEmptyLines(false)</span> -<span class="fc" id="L338"> .withQuote(null).withRecordSeparator(LF).withNullString("\\N");</span> +<span class="fc" id="L339"> public static final CSVFormat MYSQL = DEFAULT.withDelimiter(TAB).withEscape(BACKSLASH).withIgnoreEmptyLines(false)</span> + .withQuote(null).withRecordSeparator(LF).withNullString("\\N"); /** * Comma separated format as defined by <a href="http://tools.ietf.org/html/rfc4180">RFC 4180</a>. @@ -352,7 +354,7 @@ public final class CSVFormat implements * * @see Predefined#RFC4180 */ -<span class="fc" id="L355"> public static final CSVFormat RFC4180 = DEFAULT.withIgnoreEmptyLines(false);</span> +<span class="fc" id="L357"> public static final CSVFormat RFC4180 = DEFAULT.withIgnoreEmptyLines(false);</span> private static final long serialVersionUID = 1L; @@ -371,7 +373,7 @@ public final class CSVFormat implements * * @see Predefined#TDF */ -<span class="fc" id="L374"> public static final CSVFormat TDF = DEFAULT.withDelimiter(TAB).withIgnoreSurroundingSpaces();</span> +<span class="fc" id="L376"> public static final CSVFormat TDF = DEFAULT.withDelimiter(TAB).withIgnoreSurroundingSpaces();</span> /** * Returns true if the given character is a line break character. @@ -382,7 +384,7 @@ public final class CSVFormat implements * @return true if <code>c</code> is a line break character */ private static boolean isLineBreak(final char c) { -<span class="fc bfc" id="L385" title="All 4 branches covered."> return c == LF || c == CR;</span> +<span class="fc bfc" id="L387" title="All 4 branches covered."> return c == LF || c == CR;</span> } /** @@ -394,7 +396,7 @@ public final class CSVFormat implements * @return true if <code>c</code> is a line break character (and not null) */ private static boolean isLineBreak(final Character c) { -<span class="fc bfc" id="L397" title="All 4 branches covered."> return c != null && isLineBreak(c.charValue());</span> +<span class="fc bfc" id="L399" title="All 4 branches covered."> return c != null && isLineBreak(c.charValue());</span> } /** @@ -418,7 +420,7 @@ public final class CSVFormat implements * @see #TDF */ public static CSVFormat newFormat(final char delimiter) { -<span class="fc" id="L421"> return new CSVFormat(delimiter, null, null, null, null, false, false, null, null, null, null, false, false,</span> +<span class="fc" id="L423"> return new CSVFormat(delimiter, null, null, null, null, false, false, null, null, null, null, false, false,</span> false, false, false); } @@ -431,7 +433,7 @@ public final class CSVFormat implements * @since 1.2 */ public static CSVFormat valueOf(final String format) { -<span class="fc" id="L434"> return CSVFormat.Predefined.valueOf(format).getFormat();</span> +<span class="fc" id="L436"> return CSVFormat.Predefined.valueOf(format).getFormat();</span> } private final boolean allowMissingColumnNames; @@ -499,7 +501,8 @@ public final class CSVFormat implements * TODO * @param trim * TODO - * @param trailingDelimiter TODO + * @param trailingDelimiter + * TODO * @throws IllegalArgumentException * if the delimiter is a line break character */ @@ -508,93 +511,93 @@ public final class CSVFormat implements final boolean ignoreEmptyLines, final String recordSeparator, final String nullString, final Object[] headerComments, final String[] header, final boolean skipHeaderRecord, final boolean allowMissingColumnNames, final boolean ignoreHeaderCase, final boolean trim, -<span class="fc" id="L511"> final boolean trailingDelimiter) {</span> -<span class="fc" id="L512"> this.delimiter = delimiter;</span> -<span class="fc" id="L513"> this.quoteCharacter = quoteChar;</span> -<span class="fc" id="L514"> this.quoteMode = quoteMode;</span> -<span class="fc" id="L515"> this.commentMarker = commentStart;</span> -<span class="fc" id="L516"> this.escapeCharacter = escape;</span> -<span class="fc" id="L517"> this.ignoreSurroundingSpaces = ignoreSurroundingSpaces;</span> -<span class="fc" id="L518"> this.allowMissingColumnNames = allowMissingColumnNames;</span> -<span class="fc" id="L519"> this.ignoreEmptyLines = ignoreEmptyLines;</span> -<span class="fc" id="L520"> this.recordSeparator = recordSeparator;</span> -<span class="fc" id="L521"> this.nullString = nullString;</span> -<span class="fc" id="L522"> this.headerComments = toStringArray(headerComments);</span> -<span class="fc bfc" id="L523" title="All 2 branches covered."> this.header = header == null ? null : header.clone();</span> -<span class="fc" id="L524"> this.skipHeaderRecord = skipHeaderRecord;</span> -<span class="fc" id="L525"> this.ignoreHeaderCase = ignoreHeaderCase;</span> -<span class="fc" id="L526"> this.trailingDelimiter = trailingDelimiter;</span> -<span class="fc" id="L527"> this.trim = trim;</span> -<span class="fc" id="L528"> validate();</span> -<span class="fc" id="L529"> }</span> +<span class="fc" id="L514"> final boolean trailingDelimiter) {</span> +<span class="fc" id="L515"> this.delimiter = delimiter;</span> +<span class="fc" id="L516"> this.quoteCharacter = quoteChar;</span> +<span class="fc" id="L517"> this.quoteMode = quoteMode;</span> +<span class="fc" id="L518"> this.commentMarker = commentStart;</span> +<span class="fc" id="L519"> this.escapeCharacter = escape;</span> +<span class="fc" id="L520"> this.ignoreSurroundingSpaces = ignoreSurroundingSpaces;</span> +<span class="fc" id="L521"> this.allowMissingColumnNames = allowMissingColumnNames;</span> +<span class="fc" id="L522"> this.ignoreEmptyLines = ignoreEmptyLines;</span> +<span class="fc" id="L523"> this.recordSeparator = recordSeparator;</span> +<span class="fc" id="L524"> this.nullString = nullString;</span> +<span class="fc" id="L525"> this.headerComments = toStringArray(headerComments);</span> +<span class="fc bfc" id="L526" title="All 2 branches covered."> this.header = header == null ? null : header.clone();</span> +<span class="fc" id="L527"> this.skipHeaderRecord = skipHeaderRecord;</span> +<span class="fc" id="L528"> this.ignoreHeaderCase = ignoreHeaderCase;</span> +<span class="fc" id="L529"> this.trailingDelimiter = trailingDelimiter;</span> +<span class="fc" id="L530"> this.trim = trim;</span> +<span class="fc" id="L531"> validate();</span> +<span class="fc" id="L532"> }</span> @Override public boolean equals(final Object obj) { -<span class="fc bfc" id="L533" title="All 2 branches covered."> if (this == obj) {</span> -<span class="fc" id="L534"> return true;</span> - } -<span class="fc bfc" id="L536" title="All 2 branches covered."> if (obj == null) {</span> -<span class="fc" id="L537"> return false;</span> +<span class="fc bfc" id="L536" title="All 2 branches covered."> if (this == obj) {</span> +<span class="fc" id="L537"> return true;</span> } -<span class="fc bfc" id="L539" title="All 2 branches covered."> if (getClass() != obj.getClass()) {</span> +<span class="fc bfc" id="L539" title="All 2 branches covered."> if (obj == null) {</span> <span class="fc" id="L540"> return false;</span> } - -<span class="fc" id="L543"> final CSVFormat other = (CSVFormat) obj;</span> -<span class="fc bfc" id="L544" title="All 2 branches covered."> if (delimiter != other.delimiter) {</span> -<span class="fc" id="L545"> return false;</span> +<span class="fc bfc" id="L542" title="All 2 branches covered."> if (getClass() != obj.getClass()) {</span> +<span class="fc" id="L543"> return false;</span> } -<span class="fc bfc" id="L547" title="All 2 branches covered."> if (quoteMode != other.quoteMode) {</span> + +<span class="fc" id="L546"> final CSVFormat other = (CSVFormat) obj;</span> +<span class="fc bfc" id="L547" title="All 2 branches covered."> if (delimiter != other.delimiter) {</span> <span class="fc" id="L548"> return false;</span> } -<span class="pc bpc" id="L550" title="1 of 2 branches missed."> if (quoteCharacter == null) {</span> -<span class="nc bnc" id="L551" title="All 2 branches missed."> if (other.quoteCharacter != null) {</span> -<span class="nc" id="L552"> return false;</span> - } -<span class="fc bfc" id="L554" title="All 2 branches covered."> } else if (!quoteCharacter.equals(other.quoteCharacter)) {</span> -<span class="fc" id="L555"> return false;</span> +<span class="fc bfc" id="L550" title="All 2 branches covered."> if (quoteMode != other.quoteMode) {</span> +<span class="fc" id="L551"> return false;</span> } -<span class="fc bfc" id="L557" title="All 2 branches covered."> if (commentMarker == null) {</span> -<span class="pc bpc" id="L558" title="1 of 2 branches missed."> if (other.commentMarker != null) {</span> -<span class="nc" id="L559"> return false;</span> +<span class="pc bpc" id="L553" title="1 of 2 branches missed."> if (quoteCharacter == null) {</span> +<span class="nc bnc" id="L554" title="All 2 branches missed."> if (other.quoteCharacter != null) {</span> +<span class="nc" id="L555"> return false;</span> } -<span class="fc bfc" id="L561" title="All 2 branches covered."> } else if (!commentMarker.equals(other.commentMarker)) {</span> -<span class="fc" id="L562"> return false;</span> +<span class="fc bfc" id="L557" title="All 2 branches covered."> } else if (!quoteCharacter.equals(other.quoteCharacter)) {</span> +<span class="fc" id="L558"> return false;</span> } -<span class="fc bfc" id="L564" title="All 2 branches covered."> if (escapeCharacter == null) {</span> -<span class="pc bpc" id="L565" title="1 of 2 branches missed."> if (other.escapeCharacter != null) {</span> -<span class="nc" id="L566"> return false;</span> +<span class="fc bfc" id="L560" title="All 2 branches covered."> if (commentMarker == null) {</span> +<span class="pc bpc" id="L561" title="1 of 2 branches missed."> if (other.commentMarker != null) {</span> +<span class="nc" id="L562"> return false;</span> } -<span class="fc bfc" id="L568" title="All 2 branches covered."> } else if (!escapeCharacter.equals(other.escapeCharacter)) {</span> -<span class="fc" id="L569"> return false;</span> +<span class="fc bfc" id="L564" title="All 2 branches covered."> } else if (!commentMarker.equals(other.commentMarker)) {</span> +<span class="fc" id="L565"> return false;</span> } -<span class="fc bfc" id="L571" title="All 2 branches covered."> if (nullString == null) {</span> -<span class="pc bpc" id="L572" title="1 of 2 branches missed."> if (other.nullString != null) {</span> -<span class="nc" id="L573"> return false;</span> +<span class="fc bfc" id="L567" title="All 2 branches covered."> if (escapeCharacter == null) {</span> +<span class="pc bpc" id="L568" title="1 of 2 branches missed."> if (other.escapeCharacter != null) {</span> +<span class="nc" id="L569"> return false;</span> } -<span class="fc bfc" id="L575" title="All 2 branches covered."> } else if (!nullString.equals(other.nullString)) {</span> -<span class="fc" id="L576"> return false;</span> +<span class="fc bfc" id="L571" title="All 2 branches covered."> } else if (!escapeCharacter.equals(other.escapeCharacter)) {</span> +<span class="fc" id="L572"> return false;</span> } -<span class="fc bfc" id="L578" title="All 2 branches covered."> if (!Arrays.equals(header, other.header)) {</span> +<span class="fc bfc" id="L574" title="All 2 branches covered."> if (nullString == null) {</span> +<span class="pc bpc" id="L575" title="1 of 2 branches missed."> if (other.nullString != null) {</span> +<span class="nc" id="L576"> return false;</span> + } +<span class="fc bfc" id="L578" title="All 2 branches covered."> } else if (!nullString.equals(other.nullString)) {</span> <span class="fc" id="L579"> return false;</span> } -<span class="fc bfc" id="L581" title="All 2 branches covered."> if (ignoreSurroundingSpaces != other.ignoreSurroundingSpaces) {</span> +<span class="fc bfc" id="L581" title="All 2 branches covered."> if (!Arrays.equals(header, other.header)) {</span> <span class="fc" id="L582"> return false;</span> } -<span class="fc bfc" id="L584" title="All 2 branches covered."> if (ignoreEmptyLines != other.ignoreEmptyLines) {</span> +<span class="fc bfc" id="L584" title="All 2 branches covered."> if (ignoreSurroundingSpaces != other.ignoreSurroundingSpaces) {</span> <span class="fc" id="L585"> return false;</span> } -<span class="fc bfc" id="L587" title="All 2 branches covered."> if (skipHeaderRecord != other.skipHeaderRecord) {</span> +<span class="fc bfc" id="L587" title="All 2 branches covered."> if (ignoreEmptyLines != other.ignoreEmptyLines) {</span> <span class="fc" id="L588"> return false;</span> } -<span class="pc bpc" id="L590" title="1 of 2 branches missed."> if (recordSeparator == null) {</span> -<span class="nc bnc" id="L591" title="All 2 branches missed."> if (other.recordSeparator != null) {</span> -<span class="nc" id="L592"> return false;</span> +<span class="fc bfc" id="L590" title="All 2 branches covered."> if (skipHeaderRecord != other.skipHeaderRecord) {</span> +<span class="fc" id="L591"> return false;</span> + } +<span class="pc bpc" id="L593" title="1 of 2 branches missed."> if (recordSeparator == null) {</span> +<span class="nc bnc" id="L594" title="All 2 branches missed."> if (other.recordSeparator != null) {</span> +<span class="nc" id="L595"> return false;</span> } -<span class="fc bfc" id="L594" title="All 2 branches covered."> } else if (!recordSeparator.equals(other.recordSeparator)) {</span> -<span class="fc" id="L595"> return false;</span> +<span class="fc bfc" id="L597" title="All 2 branches covered."> } else if (!recordSeparator.equals(other.recordSeparator)) {</span> +<span class="fc" id="L598"> return false;</span> } -<span class="fc" id="L597"> return true;</span> +<span class="fc" id="L600"> return true;</span> } /** @@ -605,13 +608,13 @@ public final class CSVFormat implements * @return the formatted values */ public String format(final Object... values) { -<span class="fc" id="L608"> final StringWriter out = new StringWriter();</span> +<span class="fc" id="L611"> final StringWriter out = new StringWriter();</span> try { -<span class="fc" id="L610"> new CSVPrinter(out, this).printRecord(values);</span> -<span class="fc" id="L611"> return out.toString().trim();</span> -<span class="nc" id="L612"> } catch (final IOException e) {</span> +<span class="fc" id="L613"> new CSVPrinter(out, this).printRecord(values);</span> +<span class="fc" id="L614"> return out.toString().trim();</span> +<span class="nc" id="L615"> } catch (final IOException e) {</span> // should not happen because a StringWriter does not do IO. -<span class="nc" id="L614"> throw new IllegalStateException(e);</span> +<span class="nc" id="L617"> throw new IllegalStateException(e);</span> } } @@ -622,7 +625,7 @@ public final class CSVFormat implements * {@link IllegalArgumentException}. */ public boolean getAllowMissingColumnNames() { -<span class="fc" id="L625"> return allowMissingColumnNames;</span> +<span class="fc" id="L628"> return allowMissingColumnNames;</span> } /** @@ -631,7 +634,7 @@ public final class CSVFormat implements * @return the comment start marker, may be {@code null} */ public Character getCommentMarker() { -<span class="fc" id="L634"> return commentMarker;</span> +<span class="fc" id="L637"> return commentMarker;</span> } /** @@ -640,7 +643,7 @@ public final class CSVFormat implements * @return the delimiter character */ public char getDelimiter() { -<span class="fc" id="L643"> return delimiter;</span> +<span class="fc" id="L646"> return delimiter;</span> } /** @@ -649,7 +652,7 @@ public final class CSVFormat implements * @return the escape character, may be {@code null} */ public Character getEscapeCharacter() { -<span class="fc" id="L652"> return escapeCharacter;</span> +<span class="fc" id="L655"> return escapeCharacter;</span> } /** @@ -658,7 +661,7 @@ public final class CSVFormat implements * @return a copy of the header array; {@code null} if disabled, the empty array if to be read from the file */ public String[] getHeader() { -<span class="fc bfc" id="L661" title="All 2 branches covered."> return header != null ? header.clone() : null;</span> +<span class="fc bfc" id="L664" title="All 2 branches covered."> return header != null ? header.clone() : null;</span> } /** @@ -667,7 +670,7 @@ public final class CSVFormat implements * @return a copy of the header comment array; {@code null} if disabled. */ public String[] getHeaderComments() { -<span class="fc bfc" id="L670" title="All 2 branches covered."> return headerComments != null ? headerComments.clone() : null;</span> +<span class="fc bfc" id="L673" title="All 2 branches covered."> return headerComments != null ? headerComments.clone() : null;</span> } /** @@ -677,7 +680,7 @@ public final class CSVFormat implements * records. */ public boolean getIgnoreEmptyLines() { -<span class="fc" id="L680"> return ignoreEmptyLines;</span> +<span class="fc" id="L683"> return ignoreEmptyLines;</span> } /** @@ -687,7 +690,7 @@ public final class CSVFormat implements * @since 1.3 */ public boolean getIgnoreHeaderCase() { -<span class="fc" id="L690"> return ignoreHeaderCase;</span> +<span class="fc" id="L693"> return ignoreHeaderCase;</span> } /** @@ -696,7 +699,7 @@ public final class CSVFormat implements * @return {@code true} if spaces around values are ignored, {@code false} if they are treated as part of the value. */ public boolean getIgnoreSurroundingSpaces() { -<span class="fc" id="L699"> return ignoreSurroundingSpaces;</span> +<span class="fc" id="L702"> return ignoreSurroundingSpaces;</span> } /** @@ -710,7 +713,7 @@ public final class CSVFormat implements * @return the String to convert to and from {@code null}. No substitution occurs if {@code null} */ public String getNullString() { -<span class="fc" id="L713"> return nullString;</span> +<span class="fc" id="L716"> return nullString;</span> } /** @@ -719,7 +722,7 @@ public final class CSVFormat implements * @return the quoteChar character, may be {@code null} */ public Character getQuoteCharacter() { -<span class="fc" id="L722"> return quoteCharacter;</span> +<span class="fc" id="L725"> return quoteCharacter;</span> } /** @@ -728,7 +731,7 @@ public final class CSVFormat implements * @return the quote policy */ public QuoteMode getQuoteMode() { -<span class="fc" id="L731"> return quoteMode;</span> +<span class="fc" id="L734"> return quoteMode;</span> } /** @@ -737,7 +740,7 @@ public final class CSVFormat implements * @return the record separator */ public String getRecordSeparator() { -<span class="fc" id="L740"> return recordSeparator;</span> +<span class="fc" id="L743"> return recordSeparator;</span> } /** @@ -746,7 +749,7 @@ public final class CSVFormat implements * @return whether to skip the header record. */ public boolean getSkipHeaderRecord() { -<span class="fc" id="L749"> return skipHeaderRecord;</span> +<span class="fc" id="L752"> return skipHeaderRecord;</span> } /** @@ -756,7 +759,7 @@ public final class CSVFormat implements * @since 1.3 */ public boolean getTrailingDelimiter() { -<span class="fc" id="L759"> return trailingDelimiter;</span> +<span class="fc" id="L762"> return trailingDelimiter;</span> } /** @@ -765,27 +768,27 @@ public final class CSVFormat implements * @return whether to trim leading and trailing blanks. */ public boolean getTrim() { -<span class="fc" id="L768"> return trim;</span> +<span class="fc" id="L771"> return trim;</span> } @Override public int hashCode() { -<span class="fc" id="L773"> final int prime = 31;</span> -<span class="fc" id="L774"> int result = 1;</span> +<span class="fc" id="L776"> final int prime = 31;</span> +<span class="fc" id="L777"> int result = 1;</span> -<span class="fc" id="L776"> result = prime * result + delimiter;</span> -<span class="pc bpc" id="L777" title="1 of 2 branches missed."> result = prime * result + ((quoteMode == null) ? 0 : quoteMode.hashCode());</span> -<span class="pc bpc" id="L778" title="1 of 2 branches missed."> result = prime * result + ((quoteCharacter == null) ? 0 : quoteCharacter.hashCode());</span> -<span class="pc bpc" id="L779" title="1 of 2 branches missed."> result = prime * result + ((commentMarker == null) ? 0 : commentMarker.hashCode());</span> -<span class="pc bpc" id="L780" title="1 of 2 branches missed."> result = prime * result + ((escapeCharacter == null) ? 0 : escapeCharacter.hashCode());</span> -<span class="pc bpc" id="L781" title="1 of 2 branches missed."> result = prime * result + ((nullString == null) ? 0 : nullString.hashCode());</span> -<span class="pc bpc" id="L782" title="1 of 2 branches missed."> result = prime * result + (ignoreSurroundingSpaces ? 1231 : 1237);</span> -<span class="pc bpc" id="L783" title="1 of 2 branches missed."> result = prime * result + (ignoreHeaderCase ? 1231 : 1237);</span> -<span class="pc bpc" id="L784" title="1 of 2 branches missed."> result = prime * result + (ignoreEmptyLines ? 1231 : 1237);</span> -<span class="pc bpc" id="L785" title="1 of 2 branches missed."> result = prime * result + (skipHeaderRecord ? 1231 : 1237);</span> -<span class="pc bpc" id="L786" title="1 of 2 branches missed."> result = prime * result + ((recordSeparator == null) ? 0 : recordSeparator.hashCode());</span> -<span class="fc" id="L787"> result = prime * result + Arrays.hashCode(header);</span> -<span class="fc" id="L788"> return result;</span> +<span class="fc" id="L779"> result = prime * result + delimiter;</span> +<span class="pc bpc" id="L780" title="1 of 2 branches missed."> result = prime * result + ((quoteMode == null) ? 0 : quoteMode.hashCode());</span> +<span class="pc bpc" id="L781" title="1 of 2 branches missed."> result = prime * result + ((quoteCharacter == null) ? 0 : quoteCharacter.hashCode());</span> +<span class="pc bpc" id="L782" title="1 of 2 branches missed."> result = prime * result + ((commentMarker == null) ? 0 : commentMarker.hashCode());</span> +<span class="pc bpc" id="L783" title="1 of 2 branches missed."> result = prime * result + ((escapeCharacter == null) ? 0 : escapeCharacter.hashCode());</span> +<span class="pc bpc" id="L784" title="1 of 2 branches missed."> result = prime * result + ((nullString == null) ? 0 : nullString.hashCode());</span> +<span class="pc bpc" id="L785" title="1 of 2 branches missed."> result = prime * result + (ignoreSurroundingSpaces ? 1231 : 1237);</span> +<span class="pc bpc" id="L786" title="1 of 2 branches missed."> result = prime * result + (ignoreHeaderCase ? 1231 : 1237);</span> +<span class="pc bpc" id="L787" title="1 of 2 branches missed."> result = prime * result + (ignoreEmptyLines ? 1231 : 1237);</span> +<span class="pc bpc" id="L788" title="1 of 2 branches missed."> result = prime * result + (skipHeaderRecord ? 1231 : 1237);</span> +<span class="pc bpc" id="L789" title="1 of 2 branches missed."> result = prime * result + ((recordSeparator == null) ? 0 : recordSeparator.hashCode());</span> +<span class="fc" id="L790"> result = prime * result + Arrays.hashCode(header);</span> +<span class="fc" id="L791"> return result;</span> } /** @@ -796,7 +799,7 @@ public final class CSVFormat implements * @return {@code true} is comments are supported, {@code false} otherwise */ public boolean isCommentMarkerSet() { -<span class="fc bfc" id="L799" title="All 2 branches covered."> return commentMarker != null;</span> +<span class="fc bfc" id="L802" title="All 2 branches covered."> return commentMarker != null;</span> } /** @@ -805,7 +808,7 @@ public final class CSVFormat implements * @return {@code true} if escapes are processed */ public boolean isEscapeCharacterSet() { -<span class="fc bfc" id="L808" title="All 2 branches covered."> return escapeCharacter != null;</span> +<span class="fc bfc" id="L811" title="All 2 branches covered."> return escapeCharacter != null;</span> } /** @@ -814,7 +817,7 @@ public final class CSVFormat implements * @return {@code true} if a nullString is defined */ public boolean isNullStringSet() { -<span class="pc bpc" id="L817" title="1 of 2 branches missed."> return nullString != null;</span> +<span class="pc bpc" id="L820" title="1 of 2 branches missed."> return nullString != null;</span> } /** @@ -823,7 +826,7 @@ public final class CSVFormat implements * @return {@code true} if a quoteChar is defined */ public boolean isQuoteCharacterSet() { -<span class="fc bfc" id="L826" title="All 2 branches covered."> return quoteCharacter != null;</span> +<span class="fc bfc" id="L829" title="All 2 branches covered."> return quoteCharacter != null;</span> } /** @@ -840,7 +843,7 @@ public final class CSVFormat implements * If an I/O error occurs */ public CSVParser parse(final Reader in) throws IOException { -<span class="fc" id="L843"> return new CSVParser(in, this);</span> +<span class="fc" id="L846"> return new CSVParser(in, this);</span> } /** @@ -857,64 +860,318 @@ public final class CSVFormat implements * thrown if the optional header cannot be printed. */ public CSVPrinter print(final Appendable out) throws IOException { -<span class="fc" id="L860"> return new CSVPrinter(out, this);</span> +<span class="fc" id="L863"> return new CSVPrinter(out, this);</span> } + /** + * Prints the {@code value} as the next value on the line to {@code out}. The value will be escaped or encapsulated + * as needed. Useful when one wants to avoid creating CSVPrinters. + * + * @param value + * value to output. + * @param out + * where to print the value + * @param newRecord + * if this a new record + * @throws IOException + * If an I/O error occurs + * @since 1.4 + */ + public void print(final Object value, final Appendable out, final boolean newRecord) throws IOException { + // null values are considered empty + // Only call CharSequence.toString() if you have to, helps GC-free use cases. + CharSequence charSequence; +<span class="fc bfc" id="L884" title="All 2 branches covered."> if (value == null) {</span> +<span class="fc bfc" id="L885" title="All 2 branches covered."> charSequence = nullString == null ? Constants.EMPTY : nullString;</span> + } else { +<span class="fc bfc" id="L887" title="All 2 branches covered."> charSequence = value instanceof CharSequence ? (CharSequence) value : value.toString();</span> + } +<span class="fc bfc" id="L889" title="All 2 branches covered."> charSequence = getTrim() ? trim(charSequence) : charSequence;</span> +<span class="fc" id="L890"> this.print(value, charSequence, 0, charSequence.length(), out, newRecord);</span> +<span class="fc" id="L891"> }</span> + + private void print(final Object object, final CharSequence value, final int offset, final int len, + final Appendable out, final boolean newRecord) throws IOException { +<span class="fc bfc" id="L895" title="All 2 branches covered."> if (!newRecord) {</span> +<span class="fc" id="L896"> out.append(getDelimiter());</span> + } +<span class="fc bfc" id="L898" title="All 2 branches covered."> if (object == null) {</span> +<span class="fc" id="L899"> out.append(value);</span> +<span class="fc bfc" id="L900" title="All 2 branches covered."> } else if (isQuoteCharacterSet()) {</span> + // the original object is needed so can check for Number +<span class="fc" id="L902"> printAndQuote(object, value, offset, len, out, newRecord);</span> +<span class="fc bfc" id="L903" title="All 2 branches covered."> } else if (isEscapeCharacterSet()) {</span> +<span class="fc" id="L904"> printAndEscape(value, offset, len, out);</span> + } else { +<span class="fc" id="L906"> out.append(value, offset, offset + len);</span> + } +<span class="fc" id="L908"> }</span> + + /* + * Note: must only be called if escaping is enabled, otherwise will generate NPE + */ + private void printAndEscape(final CharSequence value, final int offset, final int len, final Appendable out) + throws IOException { +<span class="fc" id="L915"> int start = offset;</span> +<span class="fc" id="L916"> int pos = offset;</span> +<span class="fc" id="L917"> final int end = offset + len;</span> + +<span class="fc" id="L919"> final char delim = getDelimiter();</span> +<span class="fc" id="L920"> final char escape = getEscapeCharacter().charValue();</span> + +<span class="fc bfc" id="L922" title="All 2 branches covered."> while (pos < end) {</span> +<span class="fc" id="L923"> char c = value.charAt(pos);</span> +<span class="fc bfc" id="L924" title="All 8 branches covered."> if (c == CR || c == LF || c == delim || c == escape) {</span> + // write out segment up until this char +<span class="fc bfc" id="L926" title="All 2 branches covered."> if (pos > start) {</span> +<span class="fc" id="L927"> out.append(value, start, pos);</span> + } +<span class="fc bfc" id="L929" title="All 2 branches covered."> if (c == LF) {</span> +<span class="fc" id="L930"> c = 'n';</span> +<span class="fc bfc" id="L931" title="All 2 branches covered."> } else if (c == CR) {</span> +<span class="fc" id="L932"> c = 'r';</span> + } + +<span class="fc" id="L935"> out.append(escape);</span> +<span class="fc" id="L936"> out.append(c);</span> + +<span class="fc" id="L938"> start = pos + 1; // start on the current char after this one</span> + } + +<span class="fc" id="L941"> pos++;</span> +<span class="fc" id="L942"> }</span> + + // write last segment +<span class="fc bfc" id="L945" title="All 2 branches covered."> if (pos > start) {</span> +<span class="fc" id="L946"> out.append(value, start, pos);</span> + } +<span class="fc" id="L948"> }</span> + + /* + * Note: must only be called if quoting is enabled, otherwise will generate NPE + */ + // the original object is needed so can check for Number + private void printAndQuote(final Object object, final CharSequence value, final int offset, final int len, + final Appendable out, final boolean newRecord) throws IOException { +<span class="fc" id="L956"> boolean quote = false;</span> +<span class="fc" id="L957"> int start = offset;</span> +<span class="fc" id="L958"> int pos = offset;</span> +<span class="fc" id="L959"> final int end = offset + len;</span> + +<span class="fc" id="L961"> final char delimChar = getDelimiter();</span> +<span class="fc" id="L962"> final char quoteChar = getQuoteCharacter().charValue();</span> + +<span class="fc" id="L964"> QuoteMode quoteModePolicy = getQuoteMode();</span> +<span class="fc bfc" id="L965" title="All 2 branches covered."> if (quoteModePolicy == null) {</span> +<span class="fc" id="L966"> quoteModePolicy = QuoteMode.MINIMAL;</span> + } +<span class="pc bpc" id="L968" title="1 of 5 branches missed."> switch (quoteModePolicy) {</span> + case ALL: +<span class="fc" id="L970"> quote = true;</span> +<span class="fc" id="L971"> break;</span> + case NON_NUMERIC: +<span class="fc bfc" id="L973" title="All 2 branches covered."> quote = !(object instanceof Number);</span> +<span class="fc" id="L974"> break;</span> + case NONE: + // Use the existing escaping code +<span class="fc" id="L977"> printAndEscape(value, offset, len, out);</span> +<span class="fc" id="L978"> return;</span> + case MINIMAL: +<span class="fc bfc" id="L980" title="All 2 branches covered."> if (len <= 0) {</span> + // always quote an empty token that is the first + // on the line, as it may be the only thing on the + // line. If it were not quoted in that case, + // an empty line has no tokens. +<span class="fc bfc" id="L985" title="All 2 branches covered."> if (newRecord) {</span> +<span class="fc" id="L986"> quote = true;</span> + } + } else { +<span class="fc" id="L989"> char c = value.charAt(pos);</span> + + // TODO where did this rule come from? +<span class="fc bfc" id="L992" title="All 14 branches covered."> if (newRecord && (c < '0' || c > '9' && c < 'A' || c > 'Z' && c < 'a' || c > 'z')) {</span> +<span class="fc" id="L993"> quote = true;</span> +<span class="fc bfc" id="L994" title="All 2 branches covered."> } else if (c <= COMMENT) {</span> + // Some other chars at the start of a value caused the parser to fail, so for now + // encapsulate if we start in anything less than '#'. We are being conservative + // by including the default comment char too. +<span class="fc" id="L998"> quote = true;</span> + } else { +<span class="fc bfc" id="L1000" title="All 2 branches covered."> while (pos < end) {</span> +<span class="fc" id="L1001"> c = value.charAt(pos);</span> +<span class="fc bfc" id="L1002" title="All 8 branches covered."> if (c == LF || c == CR || c == quoteChar || c == delimChar) {</span> +<span class="fc" id="L1003"> quote = true;</span> +<span class="fc" id="L1004"> break;</span> + } +<span class="fc" id="L1006"> pos++;</span> + } + +<span class="fc bfc" id="L1009" title="All 2 branches covered."> if (!quote) {</span> +<span class="fc" id="L1010"> pos = end - 1;</span> +<span class="fc" id="L1011"> c = value.charAt(pos);</span> + // Some other chars at the end caused the parser to fail, so for now + // encapsulate if we end in anything less than ' ' +<span class="fc bfc" id="L1014" title="All 2 branches covered."> if (c <= SP) {</span> +<span class="fc" id="L1015"> quote = true;</span> + } + } + } + } + +<span class="fc bfc" id="L1021" title="All 2 branches covered."> if (!quote) {</span> + // no encapsulation needed - write out the original value +<span class="fc" id="L1023"> out.append(value, start, end);</span> +<span class="fc" id="L1024"> return;</span> + } + break; + default: +<span class="nc" id="L1028"> throw new IllegalStateException("Unexpected Quote value: " + quoteModePolicy);</span> + } + +<span class="fc bfc" id="L1031" title="All 2 branches covered."> if (!quote) {</span> + // no encapsulation needed - write out the original value +<span class="fc" id="L1033"> out.append(value, start, end);</span> +<span class="fc" id="L1034"> return;</span> + } + + // we hit something that needed encapsulation +<span class="fc" id="L1038"> out.append(quoteChar);</span> + + // Pick up where we left off: pos should be positioned on the first character that caused + // the need for encapsulation. +<span class="fc bfc" id="L1042" title="All 2 branches covered."> while (pos < end) {</span> +<span class="fc" id="L1043"> final char c = value.charAt(pos);</span> +<span class="fc bfc" id="L1044" title="All 2 branches covered."> if (c == quoteChar) {</span> + // write out the chunk up until this point + + // add 1 to the length to write out the encapsulator also +<span class="fc" id="L1048"> out.append(value, start, pos + 1);</span> + // put the next starting position on the encapsulator so we will + // write it out again with the next string (effectively doubling it) +<span class="fc" id="L1051"> start = pos;</span> + } +<span class="fc" id="L1053"> pos++;</span> +<span class="fc" id="L1054"> }</span> + + // write the last segment +<span class="fc" id="L1057"> out.append(value, start, pos);</span> +<span class="fc" id="L1058"> out.append(quoteChar);</span> +<span class="fc" id="L1059"> }</span> + + /** + * Outputs the record separator. + * + * @param out + * where to write + * @throws IOException + * If an I/O error occurs + * @since 1.4 + */ + public void println(final Appendable out) throws IOException { +<span class="fc bfc" id="L1071" title="All 2 branches covered."> if (getTrailingDelimiter()) {</span> +<span class="fc" id="L1072"> out.append(getDelimiter());</span> + } +<span class="fc bfc" id="L1074" title="All 2 branches covered."> if (recordSeparator != null) {</span> +<span class="fc" id="L1075"> out.append(recordSeparator);</span> + } +<span class="fc" id="L1077"> }</span> + + /** + * Prints the given {@code values} to {@code out} as a single record of delimiter separated values followed by the + * record separator. + * + * <p> + * The values will be quoted if needed. Quotes and new-line characters will be escaped. This method adds the record + * separator to the output after printing the record, so there is no need to call {@link #println(Appendable)}. + * </p> + * + * @param out + * where to write + * @param values + * values to output. + * @throws IOException + * If an I/O error occurs + * @since 1.4 + */ + public void printRecord(final Appendable out, final Object... values) throws IOException { +<span class="fc bfc" id="L1097" title="All 2 branches covered."> for (int i = 0; i < values.length; i++) {</span> +<span class="fc bfc" id="L1098" title="All 2 branches covered."> print(values[i], out, i == 0);</span> + } +<span class="fc" id="L1100"> println(out);</span> +<span class="fc" id="L1101"> }</span> + @Override public String toString() { -<span class="fc" id="L865"> final StringBuilder sb = new StringBuilder();</span> -<span class="fc" id="L866"> sb.append("Delimiter=<").append(delimiter).append('>');</span> -<span class="pc bpc" id="L867" title="1 of 2 branches missed."> if (isEscapeCharacterSet()) {</span> -<span class="nc" id="L868"> sb.append(' ');</span> -<span class="nc" id="L869"> sb.append("Escape=<").append(escapeCharacter).append('>');</span> - } -<span class="pc bpc" id="L871" title="1 of 2 branches missed."> if (isQuoteCharacterSet()) {</span> -<span class="fc" id="L872"> sb.append(' ');</span> -<span class="fc" id="L873"> sb.append("QuoteChar=<").append(quoteCharacter).append('>');</span> - } -<span class="fc bfc" id="L875" title="All 2 branches covered."> if (isCommentMarkerSet()) {</span> -<span class="fc" id="L876"> sb.append(' ');</span> -<span class="fc" id="L877"> sb.append("CommentStart=<").append(commentMarker).append('>');</span> - } -<span class="pc bpc" id="L879" title="1 of 2 branches missed."> if (isNullStringSet()) {</span> -<span class="nc" id="L880"> sb.append(' ');</span> -<span class="nc" id="L881"> sb.append("NullString=<").append(nullString).append('>');</span> - } -<span class="pc bpc" id="L883" title="1 of 2 branches missed."> if (recordSeparator != null) {</span> -<span class="nc" id="L884"> sb.append(' ');</span> -<span class="nc" id="L885"> sb.append("RecordSeparator=<").append(recordSeparator).append('>');</span> - } -<span class="fc bfc" id="L887" title="All 2 branches covered."> if (getIgnoreEmptyLines()) {</span> -<span class="fc" id="L888"> sb.append(" EmptyLines:ignored");</span> - } -<span class="fc bfc" id="L890" title="All 2 branches covered."> if (getIgnoreSurroundingSpaces()) {</span> -<span class="fc" id="L891"> sb.append(" SurroundingSpaces:ignored");</span> - } -<span class="pc bpc" id="L893" title="1 of 2 branches missed."> if (getIgnoreHeaderCase()) {</span> -<span class="nc" id="L894"> sb.append(" IgnoreHeaderCase:ignored");</span> - } -<span class="fc" id="L896"> sb.append(" SkipHeaderRecord:").append(skipHeaderRecord);</span> -<span class="pc bpc" id="L897" title="1 of 2 branches missed."> if (headerComments != null) {</span> -<span class="nc" id="L898"> sb.append(' ');</span> -<span class="nc" id="L899"> sb.append("HeaderComments:").append(Arrays.toString(headerComments));</span> - } -<span class="pc bpc" id="L901" title="1 of 2 branches missed."> if (header != null) {</span> -<span class="nc" id="L902"> sb.append(' ');</span> -<span class="nc" id="L903"> sb.append("Header:").append(Arrays.toString(header));</span> +<span class="fc" id="L1105"> final StringBuilder sb = new StringBuilder();</span> +<span class="fc" id="L1106"> sb.append("Delimiter=<").append(delimiter).append('>');</span> +<span class="pc bpc" id="L1107" title="1 of 2 branches missed."> if (isEscapeCharacterSet()) {</span> +<span class="nc" id="L1108"> sb.append(' ');</span> +<span class="nc" id="L1109"> sb.append("Escape=<").append(escapeCharacter).append('>');</span> + } +<span class="pc bpc" id="L1111" title="1 of 2 branches missed."> if (isQuoteCharacterSet()) {</span> +<span class="fc" id="L1112"> sb.append(' ');</span> +<span class="fc" id="L1113"> sb.append("QuoteChar=<").append(quoteCharacter).append('>');</span> + } +<span class="fc bfc" id="L1115" title="All 2 branches covered."> if (isCommentMarkerSet()) {</span> +<span class="fc" id="L1116"> sb.append(' ');</span> +<span class="fc" id="L1117"> sb.append("CommentStart=<").append(commentMarker).append('>');</span> + } +<span class="pc bpc" id="L1119" title="1 of 2 branches missed."> if (isNullStringSet()) {</span> +<span class="nc" id="L1120"> sb.append(' ');</span> +<span class="nc" id="L1121"> sb.append("NullString=<").append(nullString).append('>');</span> + } +<span class="pc bpc" id="L1123" title="1 of 2 branches missed."> if (recordSeparator != null) {</span> +<span class="nc" id="L1124"> sb.append(' ');</span> +<span class="nc" id="L1125"> sb.append("RecordSeparator=<").append(recordSeparator).append('>');</span> + } +<span class="fc bfc" id="L1127" title="All 2 branches covered."> if (getIgnoreEmptyLines()) {</span> +<span class="fc" id="L1128"> sb.append(" EmptyLines:ignored");</span> + } +<span class="fc bfc" id="L1130" title="All 2 branches covered."> if (getIgnoreSurroundingSpaces()) {</span> +<span class="fc" id="L1131"> sb.append(" SurroundingSpaces:ignored");</span> + } +<span class="pc bpc" id="L1133" title="1 of 2 branches missed."> if (getIgnoreHeaderCase()) {</span> +<span class="nc" id="L1134"> sb.append(" IgnoreHeaderCase:ignored");</span> + } +<span class="fc" id="L1136"> sb.append(" SkipHeaderRecord:").append(skipHeaderRecord);</span> +<span class="pc bpc" id="L1137" title="1 of 2 branches missed."> if (headerComments != null) {</span> +<span class="nc" id="L1138"> sb.append(' ');</span> +<span class="nc" id="L1139"> sb.append("HeaderComments:").append(Arrays.toString(headerComments));</span> + } +<span class="pc bpc" id="L1141" title="1 of 2 branches missed."> if (header != null) {</span> +<span class="nc" id="L1142"> sb.append(' ');</span> +<span class="nc" id="L1143"> sb.append("Header:").append(Arrays.toString(header));</span> } -<span class="fc" id="L905"> return sb.toString();</span> +<span class="fc" id="L1145"> return sb.toString();</span> } private String[] toStringArray(final Object[] values) { -<span class="fc bfc" id="L909" title="All 2 branches covered."> if (values == null) {</span> -<span class="fc" id="L910"> return null;</span> +<span class="fc bfc" id="L1149" title="All 2 branches covered."> if (values == null) {</span> +<span class="fc" id="L1150"> return null;</span> + } +<span class="fc" id="L1152"> final String[] strings = new String[values.length];</span> +<span class="fc bfc" id="L1153" title="All 2 branches covered."> for (int i = 0; i < values.length; i++) {</span> +<span class="fc" id="L1154"> final Object value = values[i];</span> +<span class="pc bpc" id="L1155" title="1 of 2 branches missed."> strings[i] = value == null ? null : value.toString();</span> + } +<span class="fc" id="L1157"> return strings;</span> + } + + private CharSequence trim(final CharSequence charSequence) { +<span class="pc bpc" id="L1161" title="1 of 2 branches missed."> if (charSequence instanceof String) {</span> +<span class="fc" id="L1162"> return ((String) charSequence).trim();</span> + } +<span class="nc" id="L1164"> final int count = charSequence.length();</span> +<span class="nc" id="L1165"> int len = count;</span> +<span class="nc" id="L1166"> int pos = 0;</span> + +<span class="nc bnc" id="L1168" title="All 4 branches missed."> while (pos < len && charSequence.charAt(pos) <= SP) {</span> +<span class="nc" id="L1169"> pos++;</span> } -<span class="fc" id="L912"> final String[] strings = new String[values.length];</span> -<span class="fc bfc" id="L913" title="All 2 branches covered."> for (int i = 0; i < values.length; i++) {</span> -<span class="fc" id="L914"> final Object value = values[i];</span> -<span class="pc bpc" id="L915" title="1 of 2 branches missed."> strings[i] = value == null ? null : value.toString();</span> +<span class="nc bnc" id="L1171" title="All 4 branches missed."> while (pos < len && charSequence.charAt(len - 1) <= SP) {</span> +<span class="nc" id="L1172"> len--;</span> } -<span class="fc" id="L917"> return strings;</span> +<span class="nc bnc" id="L1174" title="All 4 branches missed."> return pos > 0 || len < count ? charSequence.subSequence(pos, len) : charSequence;</span> } /** @@ -923,50 +1180,50 @@ public final class CSVFormat implements * @throws IllegalArgumentException */ private void validate() throws IllegalArgumentException { -<span class="pc bpc" id="L926" title="1 of 2 branches missed."> if (isLineBreak(delimiter)) {</span> -<span class="nc" id="L927"> throw new IllegalArgumentException("The delimiter cannot be a line break");</span> +<span class="pc bpc" id="L1183" title="1 of 2 branches missed."> if (isLineBreak(delimiter)) {</span> +<span class="nc" id="L1184"> throw new IllegalArgumentException("The delimiter cannot be a line break");</span> } -<span class="fc bfc" id="L930" title="All 4 branches covered."> if (quoteCharacter != null && delimiter == quoteCharacter.charValue()) {</span> -<span class="fc" id="L931"> throw new IllegalArgumentException(</span> +<span class="fc bfc" id="L1187" title="All 4 branches covered."> if (quoteCharacter != null && delimiter == quoteCharacter.charValue()) {</span> +<span class="fc" id="L1188"> throw new IllegalArgumentException(</span> "The quoteChar character and the delimiter cannot be the same ('" + quoteCharacter + "')"); } -<span class="fc bfc" id="L935" title="All 4 branches covered."> if (escapeCharacter != null && delimiter == escapeCharacter.charValue()) {</span> -<span class="fc" id="L936"> throw new IllegalArgumentException(</span> +<span class="fc bfc" id="L1192" title="All 4 branches covered."> if (escapeCharacter != null && delimiter == escapeCharacter.charValue()) {</span> +<span class="fc" id="L1193"> throw new IllegalArgumentException(</span> "The escape character and the delimiter cannot be the same ('" + escapeCharacter + "')"); } -<span class="fc bfc" id="L940" title="All 4 branches covered."> if (commentMarker != null && delimiter == commentMarker.charValue()) {</span> -<span class="fc" id="L941"> throw new IllegalArgumentException(</span> +<span class="fc bfc" id="L1197" title="All 4 branches covered."> if (commentMarker != null && delimiter == commentMarker.charValue()) {</span> +<span class="fc" id="L1198"> throw new IllegalArgumentException(</span> "The comment start character and the delimiter cannot be the same ('" + commentMarker + "')"); } -<span class="fc bfc" id="L945" title="All 4 branches covered."> if (quoteCharacter != null && quoteCharacter.equals(commentMarker)) {</span> -<span class="fc" id="L946"> throw new IllegalArgumentException(</span> +<span class="fc bfc" id="L1202" title="All 4 branches covered."> if (quoteCharacter != null && quoteCharacter.equals(commentMarker)) {</span> +<span class="fc" id="L1203"> throw new IllegalArgumentException(</span> "The comment start character and the quoteChar cannot be the same ('" + commentMarker + "')"); } -<span class="fc bfc" id="L950" title="All 4 branches covered."> if (escapeCharacter != null && escapeCharacter.equals(commentMarker)) {</span> -<span class="fc" id="L951"> throw new IllegalArgumentException(</span> +<span class="fc bfc" id="L1207" title="All 4 branches covered."> if (escapeCharacter != null && escapeCharacter.equals(commentMarker)) {</span> +<span class="fc" id="L1208"> throw new IllegalArgumentException(</span> "The comment start and the escape character cannot be the same ('" + commentMarker + "')"); } -<span class="fc bfc" id="L955" title="All 4 branches covered."> if (escapeCharacter == null && quoteMode == QuoteMode.NONE) {</span> -<span class="fc" id="L956"> throw new IllegalArgumentException("No quotes mode set but no escape character is set");</span> +<span class="fc bfc" id="L1212" title="All 4 branches covered."> if (escapeCharacter == null && quoteMode == QuoteMode.NONE) {</span> +<span class="fc" id="L1213"> throw new IllegalArgumentException("No quotes mode set but no escape character is set");</span> } // validate header -<span class="fc bfc" id="L960" title="All 2 branches covered."> if (header != null) {</span> -<span class="fc" id="L961"> final Set<String> dupCheck = new HashSet<String>();</span> -<span class="fc bfc" id="L962" title="All 2 branches covered."> for (final String hdr : header) {</span> -<span class="fc bfc" id="L963" title="All 2 branches covered."> if (!dupCheck.add(hdr)) {</span> -<span class="fc" id="L964"> throw new IllegalArgumentException(</span> -<span class="fc" id="L965"> "The header contains a duplicate entry: '" + hdr + "' in " + Arrays.toString(header));</span> +<span class="fc bfc" id="L1217" title="All 2 branches covered."> if (header != null) {</span> +<span class="fc" id="L1218"> final Set<String> dupCheck = new HashSet<String>();</span> +<span class="fc bfc" id="L1219" title="All 2 branches covered."> for (final String hdr : header) {</span> +<span class="fc bfc" id="L1220" title="All 2 branches covered."> if (!dupCheck.add(hdr)) {</span> +<span class="fc" id="L1221"> throw new IllegalArgumentException(</span> + "The header contains a duplicate entry: '" + hdr + "' in " + Arrays.toString(header)); } } } -<span class="fc" id="L969"> }</span> +<span class="fc" id="L1226"> }</span> /** * Returns a new {@code CSVFormat} with the missing column names behavior of the format set to {@code true} @@ -976,7 +1233,7 @@ public final class CSVFormat implements * @since 1.1 */ public CSVFormat withAllowMissingColumnNames() { -<span class="fc" id="L979"> return this.withAllowMissingColumnNames(true);</span> +<span class="fc" id="L1236"> return this.withAllowMissingColumnNames(true);</span> } /** @@ -988,7 +1245,7 @@ public final class CSVFormat implements * @return A new CSVFormat that is equal to this but with the specified missing column names behavior. */ public CSVFormat withAllowMissingColumnNames(final boolean allowMissingColumnNames) { -<span class="fc" id="L991"> return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,</span> +<span class="fc" id="L1248"> return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,</span> ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, headerComments, header, skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase, trim, trailingDelimiter); } @@ -1005,7 +1262,7 @@ public final class CSVFormat implements * thrown if the specified character is a line break */ public CSVFormat withCommentMarker(final char commentMarker) { -<span class="fc" id="L1008"> return withCommentMarker(Character.valueOf(commentMarker));</span> +<span class="fc" id="L1265"> return withCommentMarker(Character.valueOf(commentMarker));</span> } /** @@ -1020,10 +1277,10 @@ public final class CSVFormat implements * thrown if the specified character is a line break */ public CSVFormat withCommentMarker(final Character commentMarker) { -<span class="fc bfc" id="L1023" title="All 2 branches covered."> if (isLineBreak(commentMarker)) {</span> -<span class="fc" id="L1024"> throw new IllegalArgumentException("The comment start marker character cannot be a line break");</span> +<span class="fc bfc" id="L1280" title="All 2 branches covered."> if (isLineBreak(commentMarker)) {</span> +<span class="fc" id="L1281"> throw new IllegalArgumentException("The comment start marker character cannot be a line break");</span> } -<span class="fc" id="L1026"> return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,</span> +<span class="fc" id="L1283"> return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,</span> ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, headerComments, header, skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase, trim, trailingDelimiter); } @@ -1038,10 +1295,10 @@ public final class CSVFormat implements * thrown if the specified character is a line break */ public CSVFormat withDelimiter(final char delimiter) { -<span class="fc bfc" id="L1041" title="All 2 branches covered."> if (isLineBreak(delimiter)) {</span> -<span class="fc" id="L1042"> throw new IllegalArgumentException("The delimiter cannot be a line break");</span> +<span class="fc bfc" id="L1298" title="All 2 branches covered."> if (isLineBreak(delimiter)) {</span> +<span class="fc" id="L1299"> throw new IllegalArgumentException("The delimiter cannot be a line break");</span> } -<span class="fc" id="L1044"> return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,</span> +<span class="fc" id="L1301"> return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,</span> ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, headerComments, header, skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase, trim, trailingDelimiter); } @@ -1056,7 +1313,7 @@ public final class CSVFormat implements * thrown if the specified character is a line break */ public CSVFormat withEscape(final char escape) { -<span class="fc" id="L1059"> return withEscape(Character.valueOf(escape));</span> +<span class="fc" id="L1316"> return withEscape(Character.valueOf(escape));</span> } /** @@ -1069,10 +1326,10 @@ public final class CSVFormat implements * thrown if the specified character is a line break */ public CSVFormat withEscape(final Character escape) { -<span class="fc bfc" id="L1072" title="All 2 branches covered."> if (isLineBreak(escape)) {</span> -<span class="fc" id="L1073"> throw new IllegalArgumentException("The escape character cannot be a line break");</span> +<span class="fc bfc" id="L1329" title="All 2 branches covered."> if (isLineBreak(escape)) {</span> +<span class="fc" id="L1330"> throw new IllegalArgumentException("The escape character cannot be a line break");</span> } -<span class="fc" id="L1075"> return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escape, ignoreSurroundingSpaces,</span> +<span class="fc" id="L1332"> return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escape, ignoreSurroundingSpaces,</span> ignoreEmptyLines, recordSeparator, nullString, headerComments, header, skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase, trim, trailingDelimiter); } @@ -1083,6 +1340,7 @@ public final class CSVFormat implements * <p> * Calling this method is equivalent to calling: * </p> + * * <pre> * CSVFormat format = aFormat.withHeader().withSkipHeaderRecord(); * </pre> @@ -1093,7 +1351,45 @@ public final class CSVFormat implements * @since 1.3 */ public CSVFormat withFirstRecordAsHeader() { -<span class="fc" id="L1096"> return withHeader().withSkipHeaderRecord();</span> +<span class="fc" id="L1354"> return withHeader().withSkipHeaderRecord();</span> + } + + /** + * Returns a new {@code CSVFormat} with the header of the format defined by the enum class. + * + * <p> + * Example: + * </p> + * <pre> + * public enum Header { + * Name, Email, Phone + * } + * + * CSVFormat format = aformat.withHeader(Header.class); + * </pre> + * <p> + * The header is also used by the {@link CSVPrinter}. + * </p> + * + * @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) { +<span class="fc" id="L1384"> String[] header = null;</span> +<span class="pc bpc" id="L1385" title="1 of 2 branches missed."> if (headerEnum != null) {</span> +<span class="fc" id="L1386"> final Enum<?>[] enumValues = headerEnum.getEnumConstants();</span> +<span class="fc" id="L1387"> header = new String[enumValues.length];</span> +<span class="fc bfc" id="L1388" title="All 2 branches covered."> for (int i = 0; i < enumValues.length; i++) {</span> +<span class="fc" id="L1389"> header[i] = enumValues[i].name();</span> + } + } +<span class="fc" id="L1392"> return withHeader(header);</span> } /** @@ -1110,7 +1406,7 @@ public final class CSVFormat implements * CSVFormat format = aformat.withHeader(resultSet); * </pre> * <p> - * The header is also used by the {@link CSVPrinter}.. + * The header is also used by the {@link CSVPrinter}. * </p> * * @param resultSet @@ -1123,7 +1419,7 @@ public final class CSVFormat implements * @since 1.1 */ public CSVFormat withHeader(final ResultSet resultSet) throws SQLException { -<span class="pc bpc" id="L1126" title="1 of 2 branches missed."> return withHeader(resultSet != null ? resultSet.getMetaData() : null);</span> +<span class="pc bpc" id="L1422" title="1 of 2 branches missed."> return withHeader(resultSet != null ? resultSet.getMetaData() : null);</span> } /** @@ -1140,7 +1436,7 @@ public final class CSVFormat implements * CSVFormat format = aformat.withHeader(metaData); * </pre> * <p> - * The header is also used by the {@link CSVPrinter}.. + * The header is also used by the {@link CSVPrinter}. * </p> * * @param metaData @@ -1153,15 +1449,15 @@ public final class CSVFormat implements * @since 1.1 */ public CSVFormat withHeader(final ResultSetMetaData metaData) throws SQLException { -<span class="fc" id="L1156"> String[] labels = null;</span> -<span class="pc bpc" id="L1157" title="1 of 2 branches missed."> if (metaData != null) {</span> -<span class="fc" id="L1158"> final int columnCount = metaData.getColumnCount();</span> -<span class="fc" id="L1159"> labels = new String[columnCount];</span> -<span class="fc bfc" id="L1160" title="All 2 branches covered."> for (int i = 0; i < columnCount; i++) {</span> -<span class="fc" id="L1161"> labels[i] = metaData.getColumnLabel(i + 1);</span> +<span class="fc" id="L1452"> String[] labels = null;</span> +<span class="pc bpc" id="L1453" title="1 of 2 branches missed."> if (metaData != null) {</span> +<span class="fc" id="L1454"> final int columnCount = metaData.getColumnCount();</span> +<span class="fc" id="L1455"> labels = new String[columnCount];</span> +<span class="fc bfc" id="L1456" title="All 2 branches covered."> for (int i = 0; i < columnCount; i++) {</span> +<span class="fc" id="L1457"> labels[i] = metaData.getColumnLabel(i + 1);</span> } } -<span class="fc" id="L1164"> return withHeader(labels);</span> +<span class="fc" id="L1460"> return withHeader(labels);</span> } /** @@ -1178,7 +1474,7 @@ public final class CSVFormat implements * CSVFormat format = aformat.withHeader(&quot;name&quot;, &quot;email&quot;, &quot;phone&quot;); * </pre> * <p> - * The header is also used by the {@link CSVPrinter}.. + * The header is also used by the {@link CSVPrinter}. * </p> * * @param header @@ -1188,47 +1484,12 @@ public final class CSVFormat implements * @see #withSkipHeaderRecord(boolean) */ public CSVFormat withHeader(final String... header) { -<span class="fc" id="L1191"> return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,</span> +<span class="fc" id="L1487"> return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,</span> ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, headerComments, header, skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase, trim, trailingDelimiter); } /** - * Returns a new {@code CSVFormat} with the header of the format defined by the enum class: - * - * <pre> - * public enum Header { - * Name, Email, Phone - * } - * - * CSVFormat format = aformat.withHeader(Header.class); - * </pre> - * <p> - * The header is also used by the {@link CSVPrinter}.. - * </p> - * - * @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) { -<span class="fc" id="L1220"> String[] header = null;</span> -<span class="pc bpc" id="L1221" title="1 of 2 branches missed."> if (headerEnum != null) {</span> -<span class="fc" id="L1222"> Enum<?>[] enumValues = headerEnum.getEnumConstants();</span> -<span class="fc" id="L1223"> header = new String[enumValues.length];</span> -<span class="fc bfc" id="L1224" title="All 2 branches covered."> for (int i = 0; i < enumValues.length; i++) {</span> -<span class="fc" id="L1225"> header[i] = enumValues[i].name();</span> - } - } -<span class="fc" id="L1228"> return withHeader(header);</span> - } - - /** * 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. * @@ -1244,7 +1505,7 @@ public final class CSVFormat implements * @since 1.1 */ public CSVFormat withHeaderComments(final Object... headerComments) { -<span class="fc" id="L1247"> return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,</span> +<span class="fc" id="L1508"> return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,</span> ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, headerComments, header, skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase, trim, trailingDelimiter); } @@ -1257,7 +1518,7 @@ public final class CSVFormat implements * @since 1.1 */ public CSVFormat withIgnoreEmptyLines() { -<span class="fc" id="L1260"> return this.withIgnoreEmptyLines(true);</span> +<span class="fc" id="L1521"> return this.withIgnoreEmptyLines(true);</span> } /** @@ -1269,7 +1530,7 @@ public final class CSVFormat implements * @return A new CSVFormat that is equal to this but with the specified empty line skipping behavior. */ public CSVFormat withIgnoreEmptyLines(final boolean ignoreEmptyLines) { -<span class="fc" id="L1272"> return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,</span> +<span class="fc" id="L1533"> return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,</span> ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, headerComments, header, skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase, trim, trailingDelimiter); } @@ -1282,7 +1543,7 @@ public final class CSVFormat implements * @since 1.3 */ public CSVFormat withIgnoreHeaderCase() { -<span class="fc" id="L1285"> return this.withIgnoreHeaderCase(true);</span> +<span class="fc" id="L1546"> return this.withIgnoreHeaderCase(true);</span> } /** @@ -1295,7 +1556,7 @@ public final class CSVFormat implements * @since 1.3 */ public CSVFormat withIgnoreHeaderCase(final boolean ignoreHeaderCase) { -<span class="fc" id="L1298"> return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,</span> +<span class="fc" id="L1559"> return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,</span> ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, headerComments, header, skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase, trim, trailingDelimiter); } @@ -1308,7 +1569,7 @@ public final class CSVFormat implements * @since 1.1 */ public CSVFormat withIgnoreSurroundingSpaces() { -<span class="fc" id="L1311"> return this.withIgnoreSurroundingSpaces(true);</span> +<span class="fc" id="L1572"> return this.withIgnoreSurroundingSpaces(true);</span> } /** @@ -1320,7 +1581,7 @@ public final class CSVFormat implements * @return A new CSVFormat that is equal to this but with the specified trimming behavior. */ public CSVFormat withIgnoreSurroundingSpaces(final boolean ignoreSurroundingSpaces) { -<span class="fc" id="L1323"> return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,</span> +<span class="fc" id="L1584"> return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,</span> ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, headerComments, header, skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase, trim, trailingDelimiter); } @@ -1339,7 +1600,7 @@ public final class CSVFormat implements * @return A new CSVFormat that is equal to this but with the specified null conversion string. */ public CSVFormat withNullString(final String nullString) { -<span class="fc" id="L1342"> return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,</span> +<span class="fc" id="L1603"> return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,</span> ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, headerComments, header, skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase, trim, trailingDelimiter); } @@ -1354,7 +1615,7 @@ public final class CSVFormat implements * thrown if the specified character is a line break */ public CSVFormat withQuote(final char quoteChar) { -<span class="fc" id="L1357"> return withQuote(Character.valueOf(quoteChar));</span> +<span class="fc" id="L1618"> return withQuote(Character.valueOf(quoteChar));</span> } /** @@ -1367,10 +1628,10 @@ public final class CSVFormat implements * thrown if the specified character is a line break */ public CSVFormat withQuote(final Character quoteChar) { -<span class="fc bfc" id="L1370" title="All 2 branches covered."> if (isLineBreak(quoteChar)) {</span> -<span class="fc" id="L1371"> throw new IllegalArgumentException("The quoteChar cannot be a line break");</span> +<span class="fc bfc" id="L1631" title="All 2 branches covered."> if (isLineBreak(quoteChar)) {</span> +<span class="fc" id="L1632"> throw new IllegalArgumentException("The quoteChar cannot be a line break");</span> } -<span class="fc" id="L1373"> return new CSVFormat(delimiter, quoteChar, quoteMode, commentMarker, escapeCharacter, ignoreSurroundingSpaces,</span> +<span class="fc" id="L1634"> return new CSVFormat(delimiter, quoteChar, quoteMode, commentMarker, escapeCharacter, ignoreSurroundingSpaces,</span> ignoreEmptyLines, recordSeparator, nullString, headerComments, header, skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase, trim, trailingDelimiter); } @@ -1384,7 +1645,7 @@ public final class CSVFormat implements * @return A new CSVFormat that is equal to this but with the specified quote policy */ public CSVFormat withQuoteMode(final QuoteMode quoteModePolicy) { -<span class="fc" id="L1387"> return new CSVFormat(delimiter, quoteCharacter, quoteModePolicy, commentMarker, escapeCharacter,</span> +<span class="fc" id="L1648"> return new CSVFormat(delimiter, quoteCharacter, quoteModePolicy, commentMarker, escapeCharacter,</span> ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, headerComments, header, skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase, trim, trailingDelimiter); } @@ -1403,7 +1664,7 @@ public final class CSVFormat implements * @return A new CSVFormat that is equal to this but with the the specified output record separator */ public CSVFormat withRecordSeparator(final char recordSeparator) { -<span class="fc" id="L1406"> return withRecordSeparator(String.valueOf(recordSeparator));</span> +<span class="fc" id="L1667"> return withRecordSeparator(String.valueOf(recordSeparator));</span> } /** @@ -1422,7 +1683,7 @@ public final class CSVFormat implements * if recordSeparator is none of CR, LF or CRLF */ public CSVFormat withRecordSeparator(final String recordSeparator) { -<span class="fc" id="L1425"> return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,</span> +<span class="fc" id="L1686"> return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,</span> ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, headerComments, header, skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase, trim, trailingDelimiter); } @@ -1436,7 +1697,7 @@ public final class CSVFormat implements * @since 1.1 */ public CSVFormat withSkipHeaderRecord() { -<span class="fc" id="L1439"> return this.withSkipHeaderRecord(true);</span> +<span class="fc" id="L1700"> return this.withSkipHeaderRecord(true);</span> } /** @@ -1449,7 +1710,7 @@ public final class CSVFormat implements * @see #withHeader(String...) */ public CSVFormat withSkipHeaderRecord(final boolean skipHeaderRecord) { -<span class="fc" id="L1452"> return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,</span> +<span class="fc" id="L1713"> return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,</span> ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, headerComments, header, skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase, trim, trailingDelimiter); } @@ -1461,7 +1722,7 @@ public final class CSVFormat implements * @since 1.3 */ public CSVFormat withTrailingDelimiter() { -<span class="fc" id="L1464"> return withTrailingDelimiter(true);</span> +<span class="fc" id="L1725"> return withTrailingDelimiter(true);</span> } /** @@ -1474,7 +1735,7 @@ public final class CSVFormat implements * @since 1.3 */ public CSVFormat withTrailingDelimiter(final boolean trailingDelimiter) { -<span class="fc" id="L1477"> return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,</span> +<span class="fc" id="L1738"> return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,</span> ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, headerComments, header, skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase, trim, trailingDelimiter); } @@ -1486,7 +1747,7 @@ public final class CSVFormat implements * @since 1.3 */ public CSVFormat withTrim() { -<span class="fc" id="L1489"> return withTrim(true);</span> +<span class="fc" id="L1750"> return withTrim(true);</span> } /** @@ -1499,7 +1760,7 @@ public final class CSVFormat implements * @since 1.3 */ public CSVFormat withTrim(final boolean trim) { -<span class="fc" id="L1502"> return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,</span> +<span class="fc" id="L1763"> return new CSVFormat(delimiter, quoteCharacter, quoteMode, commentMarker, escapeCharacter,</span> ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, headerComments, header, skipHeaderRecord, allowMissingColumnNames, ignoreHeaderCase, trim, trailingDelimiter); }