diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index ab5d7d663..b7d6f9dff 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -45,6 +45,8 @@
Add CSVPrinter.getRecordCount().
Add and use CSVParser.Builder and builder() and deprecate CSVParser constructors.
+ CSVFormat.Builder implements Supplier<CSVFormat>.
+ Deprecate CSVFormat.Builder.build() for get().
Bump org.apache.commons:commons-parent from 76 to 78 #486, #495.
Bump org.codehaus.mojo:taglist-maven-plugin from 3.1.0 to 3.2.1 #493.
diff --git a/src/main/java/org/apache/commons/csv/CSVFormat.java b/src/main/java/org/apache/commons/csv/CSVFormat.java
index 7376f902a..3d4b43c6b 100644
--- a/src/main/java/org/apache/commons/csv/CSVFormat.java
+++ b/src/main/java/org/apache/commons/csv/CSVFormat.java
@@ -37,6 +37,7 @@
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
+import java.util.function.Supplier;
import org.apache.commons.codec.binary.Base64OutputStream;
import org.apache.commons.io.IOUtils;
@@ -182,7 +183,7 @@ public final class CSVFormat implements Serializable {
*
* @since 1.9.0
*/
- public static class Builder {
+ public static class Builder implements Supplier {
/**
* Creates a new default builder.
@@ -273,8 +274,21 @@ private Builder(final CSVFormat csvFormat) {
* Builds a new CSVFormat instance.
*
* @return a new CSVFormat instance.
+ * @deprecated Use {@link #get()}.
*/
+ @Deprecated
public CSVFormat build() {
+ return get();
+ }
+
+ /**
+ * Builds a new CSVFormat instance.
+ *
+ * @return a new CSVFormat instance.
+ * @since 1.13.0
+ */
+ @Override
+ public CSVFormat get() {
return new CSVFormat(this);
}
@@ -997,7 +1011,7 @@ public CSVFormat getFormat() {
.setAllowMissingColumnNames(true)
.setTrailingData(true)
.setLenientEof(true)
- .build();
+ .get();
// @formatter:on
/**
@@ -1029,7 +1043,7 @@ public CSVFormat getFormat() {
.setEscape(Constants.BACKSLASH)
.setQuote(Constants.DOUBLE_QUOTE_CHAR)
.setRecordSeparator(Constants.LF)
- .build();
+ .get();
// @formatter:on
/**
@@ -1059,7 +1073,7 @@ public CSVFormat getFormat() {
.setDelimiter(Constants.COMMA)
.setQuote(Constants.DOUBLE_QUOTE_CHAR)
.setRecordSeparator(Constants.LF)
- .build();
+ .get();
// @formatter:on
/**
@@ -1101,7 +1115,7 @@ public CSVFormat getFormat() {
.setQuote(Constants.DOUBLE_QUOTE_CHAR)
.setQuoteMode(QuoteMode.MINIMAL)
.setSkipHeaderRecord(false)
- .build();
+ .get();
// @formatter:off
/**
@@ -1138,7 +1152,7 @@ public CSVFormat getFormat() {
.setQuote(Constants.DOUBLE_QUOTE_CHAR)
.setQuoteMode(QuoteMode.MINIMAL)
.setSkipHeaderRecord(false)
- .build();
+ .get();
// @formatter:off
/**
@@ -1175,7 +1189,7 @@ public CSVFormat getFormat() {
.setRecordSeparator(Constants.LF)
.setNullString(Constants.SQL_NULL_STRING)
.setQuoteMode(QuoteMode.ALL_NON_NULL)
- .build();
+ .get();
// @formatter:off
/**
@@ -1215,7 +1229,7 @@ public CSVFormat getFormat() {
.setTrim(true)
.setRecordSeparator(System.lineSeparator())
.setQuoteMode(QuoteMode.MINIMAL)
- .build();
+ .get();
// @formatter:off
/**
@@ -1253,7 +1267,7 @@ public CSVFormat getFormat() {
.setRecordSeparator(Constants.LF)
.setNullString(Constants.EMPTY)
.setQuoteMode(QuoteMode.ALL_NON_NULL)
- .build();
+ .get();
// @formatter:off
/**
@@ -1291,7 +1305,7 @@ public CSVFormat getFormat() {
.setRecordSeparator(Constants.LF)
.setNullString(Constants.SQL_NULL_STRING)
.setQuoteMode(QuoteMode.ALL_NON_NULL)
- .build();
+ .get();
// @formatter:off
/**
@@ -1309,7 +1323,7 @@ public CSVFormat getFormat() {
*
* @see Predefined#RFC4180
*/
- public static final CSVFormat RFC4180 = DEFAULT.builder().setIgnoreEmptyLines(false).build();
+ public static final CSVFormat RFC4180 = DEFAULT.builder().setIgnoreEmptyLines(false).get();
private static final long serialVersionUID = 2L;
@@ -1332,7 +1346,7 @@ public CSVFormat getFormat() {
public static final CSVFormat TDF = DEFAULT.builder()
.setDelimiter(Constants.TAB)
.setIgnoreSurroundingSpaces(true)
- .build();
+ .get();
// @formatter:on
/**
@@ -1647,7 +1661,7 @@ public Builder builder() {
* @return a copy of this instance.
*/
CSVFormat copy() {
- return builder().build();
+ return builder().get();
}
@Override
@@ -2610,7 +2624,7 @@ private void validate() throws IllegalArgumentException {
*/
@Deprecated
public CSVFormat withAllowDuplicateHeaderNames() {
- return builder().setDuplicateHeaderMode(DuplicateHeaderMode.ALLOW_ALL).build();
+ return builder().setDuplicateHeaderMode(DuplicateHeaderMode.ALLOW_ALL).get();
}
/**
@@ -2624,7 +2638,7 @@ public CSVFormat withAllowDuplicateHeaderNames() {
@Deprecated
public CSVFormat withAllowDuplicateHeaderNames(final boolean allowDuplicateHeaderNames) {
final DuplicateHeaderMode mode = allowDuplicateHeaderNames ? DuplicateHeaderMode.ALLOW_ALL : DuplicateHeaderMode.ALLOW_EMPTY;
- return builder().setDuplicateHeaderMode(mode).build();
+ return builder().setDuplicateHeaderMode(mode).get();
}
/**
@@ -2637,7 +2651,7 @@ public CSVFormat withAllowDuplicateHeaderNames(final boolean allowDuplicateHeade
*/
@Deprecated
public CSVFormat withAllowMissingColumnNames() {
- return builder().setAllowMissingColumnNames(true).build();
+ return builder().setAllowMissingColumnNames(true).get();
}
/**
@@ -2650,7 +2664,7 @@ public CSVFormat withAllowMissingColumnNames() {
*/
@Deprecated
public CSVFormat withAllowMissingColumnNames(final boolean allowMissingColumnNames) {
- return builder().setAllowMissingColumnNames(allowMissingColumnNames).build();
+ return builder().setAllowMissingColumnNames(allowMissingColumnNames).get();
}
/**
@@ -2664,7 +2678,7 @@ public CSVFormat withAllowMissingColumnNames(final boolean allowMissingColumnNam
*/
@Deprecated
public CSVFormat withAutoFlush(final boolean autoFlush) {
- return builder().setAutoFlush(autoFlush).build();
+ return builder().setAutoFlush(autoFlush).get();
}
/**
@@ -2679,7 +2693,7 @@ public CSVFormat withAutoFlush(final boolean autoFlush) {
*/
@Deprecated
public CSVFormat withCommentMarker(final char commentMarker) {
- return builder().setCommentMarker(commentMarker).build();
+ return builder().setCommentMarker(commentMarker).get();
}
/**
@@ -2694,7 +2708,7 @@ public CSVFormat withCommentMarker(final char commentMarker) {
*/
@Deprecated
public CSVFormat withCommentMarker(final Character commentMarker) {
- return builder().setCommentMarker(commentMarker).build();
+ return builder().setCommentMarker(commentMarker).get();
}
/**
@@ -2707,7 +2721,7 @@ public CSVFormat withCommentMarker(final Character commentMarker) {
*/
@Deprecated
public CSVFormat withDelimiter(final char delimiter) {
- return builder().setDelimiter(delimiter).build();
+ return builder().setDelimiter(delimiter).get();
}
/**
@@ -2720,7 +2734,7 @@ public CSVFormat withDelimiter(final char delimiter) {
*/
@Deprecated
public CSVFormat withEscape(final char escape) {
- return builder().setEscape(escape).build();
+ return builder().setEscape(escape).get();
}
/**
@@ -2733,7 +2747,7 @@ public CSVFormat withEscape(final char escape) {
*/
@Deprecated
public CSVFormat withEscape(final Character escape) {
- return builder().setEscape(escape).build();
+ return builder().setEscape(escape).get();
}
/**
@@ -2759,7 +2773,7 @@ public CSVFormat withFirstRecordAsHeader() {
return builder()
.setHeader()
.setSkipHeaderRecord(true)
- .build();
+ .get();
// @formatter:on
}
@@ -2790,7 +2804,7 @@ public CSVFormat withFirstRecordAsHeader() {
*/
@Deprecated
public CSVFormat withHeader(final Class extends Enum>> headerEnum) {
- return builder().setHeader(headerEnum).build();
+ return builder().setHeader(headerEnum).get();
}
/**
@@ -2818,7 +2832,7 @@ public CSVFormat withHeader(final Class extends Enum>> headerEnum) {
*/
@Deprecated
public CSVFormat withHeader(final ResultSet resultSet) throws SQLException {
- return builder().setHeader(resultSet).build();
+ return builder().setHeader(resultSet).get();
}
/**
@@ -2846,7 +2860,7 @@ public CSVFormat withHeader(final ResultSet resultSet) throws SQLException {
*/
@Deprecated
public CSVFormat withHeader(final ResultSetMetaData resultSetMetaData) throws SQLException {
- return builder().setHeader(resultSetMetaData).build();
+ return builder().setHeader(resultSetMetaData).get();
}
/**
@@ -2873,7 +2887,7 @@ public CSVFormat withHeader(final ResultSetMetaData resultSetMetaData) throws SQ
*/
@Deprecated
public CSVFormat withHeader(final String... header) {
- return builder().setHeader(header).build();
+ return builder().setHeader(header).get();
}
/**
@@ -2892,7 +2906,7 @@ public CSVFormat withHeader(final String... header) {
*/
@Deprecated
public CSVFormat withHeaderComments(final Object... headerComments) {
- return builder().setHeaderComments(headerComments).build();
+ return builder().setHeaderComments(headerComments).get();
}
/**
@@ -2905,7 +2919,7 @@ public CSVFormat withHeaderComments(final Object... headerComments) {
*/
@Deprecated
public CSVFormat withIgnoreEmptyLines() {
- return builder().setIgnoreEmptyLines(true).build();
+ return builder().setIgnoreEmptyLines(true).get();
}
/**
@@ -2918,7 +2932,7 @@ public CSVFormat withIgnoreEmptyLines() {
*/
@Deprecated
public CSVFormat withIgnoreEmptyLines(final boolean ignoreEmptyLines) {
- return builder().setIgnoreEmptyLines(ignoreEmptyLines).build();
+ return builder().setIgnoreEmptyLines(ignoreEmptyLines).get();
}
/**
@@ -2931,7 +2945,7 @@ public CSVFormat withIgnoreEmptyLines(final boolean ignoreEmptyLines) {
*/
@Deprecated
public CSVFormat withIgnoreHeaderCase() {
- return builder().setIgnoreHeaderCase(true).build();
+ return builder().setIgnoreHeaderCase(true).get();
}
/**
@@ -2944,7 +2958,7 @@ public CSVFormat withIgnoreHeaderCase() {
*/
@Deprecated
public CSVFormat withIgnoreHeaderCase(final boolean ignoreHeaderCase) {
- return builder().setIgnoreHeaderCase(ignoreHeaderCase).build();
+ return builder().setIgnoreHeaderCase(ignoreHeaderCase).get();
}
/**
@@ -2957,7 +2971,7 @@ public CSVFormat withIgnoreHeaderCase(final boolean ignoreHeaderCase) {
*/
@Deprecated
public CSVFormat withIgnoreSurroundingSpaces() {
- return builder().setIgnoreSurroundingSpaces(true).build();
+ return builder().setIgnoreSurroundingSpaces(true).get();
}
/**
@@ -2969,7 +2983,7 @@ public CSVFormat withIgnoreSurroundingSpaces() {
*/
@Deprecated
public CSVFormat withIgnoreSurroundingSpaces(final boolean ignoreSurroundingSpaces) {
- return builder().setIgnoreSurroundingSpaces(ignoreSurroundingSpaces).build();
+ return builder().setIgnoreSurroundingSpaces(ignoreSurroundingSpaces).get();
}
/**
@@ -2985,7 +2999,7 @@ public CSVFormat withIgnoreSurroundingSpaces(final boolean ignoreSurroundingSpac
*/
@Deprecated
public CSVFormat withNullString(final String nullString) {
- return builder().setNullString(nullString).build();
+ return builder().setNullString(nullString).get();
}
/**
@@ -2998,7 +3012,7 @@ public CSVFormat withNullString(final String nullString) {
*/
@Deprecated
public CSVFormat withQuote(final char quoteChar) {
- return builder().setQuote(quoteChar).build();
+ return builder().setQuote(quoteChar).get();
}
/**
@@ -3011,7 +3025,7 @@ public CSVFormat withQuote(final char quoteChar) {
*/
@Deprecated
public CSVFormat withQuote(final Character quoteChar) {
- return builder().setQuote(quoteChar).build();
+ return builder().setQuote(quoteChar).get();
}
/**
@@ -3024,7 +3038,7 @@ public CSVFormat withQuote(final Character quoteChar) {
*/
@Deprecated
public CSVFormat withQuoteMode(final QuoteMode quoteMode) {
- return builder().setQuoteMode(quoteMode).build();
+ return builder().setQuoteMode(quoteMode).get();
}
/**
@@ -3041,7 +3055,7 @@ public CSVFormat withQuoteMode(final QuoteMode quoteMode) {
*/
@Deprecated
public CSVFormat withRecordSeparator(final char recordSeparator) {
- return builder().setRecordSeparator(recordSeparator).build();
+ return builder().setRecordSeparator(recordSeparator).get();
}
/**
@@ -3059,7 +3073,7 @@ public CSVFormat withRecordSeparator(final char recordSeparator) {
*/
@Deprecated
public CSVFormat withRecordSeparator(final String recordSeparator) {
- return builder().setRecordSeparator(recordSeparator).build();
+ return builder().setRecordSeparator(recordSeparator).get();
}
/**
@@ -3073,7 +3087,7 @@ public CSVFormat withRecordSeparator(final String recordSeparator) {
*/
@Deprecated
public CSVFormat withSkipHeaderRecord() {
- return builder().setSkipHeaderRecord(true).build();
+ return builder().setSkipHeaderRecord(true).get();
}
/**
@@ -3086,7 +3100,7 @@ public CSVFormat withSkipHeaderRecord() {
*/
@Deprecated
public CSVFormat withSkipHeaderRecord(final boolean skipHeaderRecord) {
- return builder().setSkipHeaderRecord(skipHeaderRecord).build();
+ return builder().setSkipHeaderRecord(skipHeaderRecord).get();
}
/**
@@ -3104,7 +3118,7 @@ public CSVFormat withSkipHeaderRecord(final boolean skipHeaderRecord) {
*/
@Deprecated
public CSVFormat withSystemRecordSeparator() {
- return builder().setRecordSeparator(System.lineSeparator()).build();
+ return builder().setRecordSeparator(System.lineSeparator()).get();
}
/**
@@ -3116,7 +3130,7 @@ public CSVFormat withSystemRecordSeparator() {
*/
@Deprecated
public CSVFormat withTrailingDelimiter() {
- return builder().setTrailingDelimiter(true).build();
+ return builder().setTrailingDelimiter(true).get();
}
/**
@@ -3129,7 +3143,7 @@ public CSVFormat withTrailingDelimiter() {
*/
@Deprecated
public CSVFormat withTrailingDelimiter(final boolean trailingDelimiter) {
- return builder().setTrailingDelimiter(trailingDelimiter).build();
+ return builder().setTrailingDelimiter(trailingDelimiter).get();
}
/**
@@ -3141,7 +3155,7 @@ public CSVFormat withTrailingDelimiter(final boolean trailingDelimiter) {
*/
@Deprecated
public CSVFormat withTrim() {
- return builder().setTrim(true).build();
+ return builder().setTrim(true).get();
}
/**
@@ -3154,6 +3168,6 @@ public CSVFormat withTrim() {
*/
@Deprecated
public CSVFormat withTrim(final boolean trim) {
- return builder().setTrim(trim).build();
+ return builder().setTrim(trim).get();
}
}
diff --git a/src/main/java/org/apache/commons/csv/CSVPrinter.java b/src/main/java/org/apache/commons/csv/CSVPrinter.java
index 09db126cc..a0177eda0 100644
--- a/src/main/java/org/apache/commons/csv/CSVPrinter.java
+++ b/src/main/java/org/apache/commons/csv/CSVPrinter.java
@@ -258,7 +258,7 @@ public synchronized void printComment(final String comment) throws IOException {
* @since 1.9.0
*/
public synchronized void printHeaders(final ResultSet resultSet) throws IOException, SQLException {
- try (IOStream stream = IOStream.of(format.builder().setHeader(resultSet).build().getHeader())) {
+ try (IOStream stream = IOStream.of(format.builder().setHeader(resultSet).get().getHeader())) {
stream.forEachOrdered(this::print);
}
println();
diff --git a/src/test/java/org/apache/commons/csv/CSVDuplicateHeaderTest.java b/src/test/java/org/apache/commons/csv/CSVDuplicateHeaderTest.java
index dfca5765b..7932a8c90 100644
--- a/src/test/java/org/apache/commons/csv/CSVDuplicateHeaderTest.java
+++ b/src/test/java/org/apache/commons/csv/CSVDuplicateHeaderTest.java
@@ -282,12 +282,12 @@ public void testCSVFormat(final DuplicateHeaderMode duplicateHeaderMode,
.setIgnoreHeaderCase(ignoreHeaderCase)
.setHeader(headers);
if (valid) {
- final CSVFormat format = builder.build();
+ final CSVFormat format = builder.get();
Assertions.assertEquals(duplicateHeaderMode, format.getDuplicateHeaderMode(), "DuplicateHeaderMode");
Assertions.assertEquals(allowMissingColumnNames, format.getAllowMissingColumnNames(), "AllowMissingColumnNames");
Assertions.assertArrayEquals(headers, format.getHeader(), "Header");
} else {
- Assertions.assertThrows(IllegalArgumentException.class, builder::build);
+ Assertions.assertThrows(IllegalArgumentException.class, builder::get);
}
}
@@ -315,7 +315,7 @@ public void testCSVParser(final DuplicateHeaderMode duplicateHeaderMode,
.setIgnoreHeaderCase(ignoreHeaderCase)
.setNullString("NULL")
.setHeader()
- .build();
+ .get();
// @formatter:on
final String input = Arrays.stream(headers)
.map(s -> s == null ? format.getNullString() : s)
diff --git a/src/test/java/org/apache/commons/csv/CSVFormatTest.java b/src/test/java/org/apache/commons/csv/CSVFormatTest.java
index ff806b82e..7ce0aad72 100644
--- a/src/test/java/org/apache/commons/csv/CSVFormatTest.java
+++ b/src/test/java/org/apache/commons/csv/CSVFormatTest.java
@@ -68,7 +68,7 @@ private static void assertNotEquals(final Object right, final Object left) {
}
private static CSVFormat copy(final CSVFormat format) {
- return format.builder().setDelimiter(format.getDelimiter()).build();
+ return format.builder().setDelimiter(format.getDelimiter()).get();
}
private void assertNotEquals(final String name, final String type, final Object left, final Object right) {
@@ -80,9 +80,15 @@ private void assertNotEquals(final String name, final String type, final Object
}
}
+ @Test
+ public void testBuildVsGet() {
+ final Builder builder = CSVFormat.DEFAULT.builder();
+ assertNotSame(builder.get(), builder.build());
+ }
+
@Test
public void testDelimiterEmptyStringThrowsException1() {
- assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.builder().setDelimiter("").build());
+ assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.builder().setDelimiter("").get());
}
@SuppressWarnings("deprecation")
@@ -93,7 +99,7 @@ public void testDelimiterSameAsCommentStartThrowsException_Deprecated() {
@Test
public void testDelimiterSameAsCommentStartThrowsException1() {
- assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.builder().setDelimiter('!').setCommentMarker('!').build());
+ assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.builder().setDelimiter('!').setCommentMarker('!').get());
}
@SuppressWarnings("deprecation")
@@ -104,7 +110,7 @@ public void testDelimiterSameAsEscapeThrowsException_Deprecated() {
@Test
public void testDelimiterSameAsEscapeThrowsException1() {
- assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.builder().setDelimiter('!').setEscape('!').build());
+ assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.builder().setDelimiter('!').setEscape('!').get());
}
@Test
@@ -115,7 +121,7 @@ public void testDelimiterSameAsRecordSeparatorThrowsException() {
@Test
public void testDuplicateHeaderElements() {
final String[] header = { "A", "A" };
- final CSVFormat format = CSVFormat.DEFAULT.builder().setHeader(header).build();
+ final CSVFormat format = CSVFormat.DEFAULT.builder().setHeader(header).get();
assertEquals(2, format.getHeader().length);
assertArrayEquals(header, format.getHeader());
}
@@ -131,7 +137,7 @@ public void testDuplicateHeaderElements_Deprecated() {
@Test
public void testDuplicateHeaderElementsFalse() {
- assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.builder().setAllowDuplicateHeaderNames(false).setHeader("A", "A").build());
+ assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.builder().setAllowDuplicateHeaderNames(false).setHeader("A", "A").get());
}
@SuppressWarnings("deprecation")
@@ -142,7 +148,7 @@ public void testDuplicateHeaderElementsFalse_Deprecated() {
@Test
public void testDuplicateHeaderElementsTrue() {
- CSVFormat.DEFAULT.builder().setAllowDuplicateHeaderNames(true).setHeader("A", "A").build();
+ CSVFormat.DEFAULT.builder().setAllowDuplicateHeaderNames(true).setHeader("A", "A").get();
}
@SuppressWarnings("deprecation")
@@ -153,39 +159,36 @@ public void testDuplicateHeaderElementsTrue_Deprecated() {
@Test
public void testDuplicateHeaderElementsTrueContainsEmpty1() {
- CSVFormat.DEFAULT.builder().setAllowDuplicateHeaderNames(false).setHeader("A", "", "B", "").build();
+ CSVFormat.DEFAULT.builder().setAllowDuplicateHeaderNames(false).setHeader("A", "", "B", "").get();
}
@Test
public void testDuplicateHeaderElementsTrueContainsEmpty2() {
- CSVFormat.DEFAULT.builder().setDuplicateHeaderMode(DuplicateHeaderMode.ALLOW_EMPTY).setHeader("A", "", "B", "").build();
+ CSVFormat.DEFAULT.builder().setDuplicateHeaderMode(DuplicateHeaderMode.ALLOW_EMPTY).setHeader("A", "", "B", "").get();
}
@Test
public void testDuplicateHeaderElementsTrueContainsEmpty3() {
- CSVFormat.DEFAULT.builder().setAllowDuplicateHeaderNames(false).setAllowMissingColumnNames(true).setHeader("A", "", "B", "").build();
+ CSVFormat.DEFAULT.builder().setAllowDuplicateHeaderNames(false).setAllowMissingColumnNames(true).setHeader("A", "", "B", "").get();
}
@Test
public void testEquals() {
final CSVFormat right = CSVFormat.DEFAULT;
final CSVFormat left = copy(right);
-
Assertions.assertNotEquals(null, right);
Assertions.assertNotEquals("A String Instance", right);
-
assertEquals(right, right);
assertEquals(right, left);
assertEquals(left, right);
-
assertEquals(right.hashCode(), right.hashCode());
assertEquals(right.hashCode(), left.hashCode());
}
@Test
public void testEqualsCommentStart() {
- final CSVFormat right = CSVFormat.newFormat('\'').builder().setQuote('"').setCommentMarker('#').setQuoteMode(QuoteMode.ALL).build();
- final CSVFormat left = right.builder().setCommentMarker('!').build();
+ final CSVFormat right = CSVFormat.newFormat('\'').builder().setQuote('"').setCommentMarker('#').setQuoteMode(QuoteMode.ALL).get();
+ final CSVFormat left = right.builder().setCommentMarker('!').get();
assertNotEquals(right, left);
}
@@ -209,8 +212,8 @@ public void testEqualsDelimiter() {
@Test
public void testEqualsEscape() {
- final CSVFormat right = CSVFormat.newFormat('\'').builder().setQuote('"').setCommentMarker('#').setEscape('+').setQuoteMode(QuoteMode.ALL).build();
- final CSVFormat left = right.builder().setEscape('!').build();
+ final CSVFormat right = CSVFormat.newFormat('\'').builder().setQuote('"').setCommentMarker('#').setEscape('+').setQuoteMode(QuoteMode.ALL).get();
+ final CSVFormat left = right.builder().setEscape('!').get();
assertNotEquals(right, left);
}
@@ -299,8 +302,8 @@ public void testEqualsHash() throws Exception {
@Test
public void testEqualsHeader() {
final CSVFormat right = CSVFormat.newFormat('\'').builder().setRecordSeparator(CR).setCommentMarker('#').setEscape('+').setHeader("One", "Two", "Three")
- .setIgnoreEmptyLines(true).setIgnoreSurroundingSpaces(true).setQuote('"').setQuoteMode(QuoteMode.ALL).build();
- final CSVFormat left = right.builder().setHeader("Three", "Two", "One").build();
+ .setIgnoreEmptyLines(true).setIgnoreSurroundingSpaces(true).setQuote('"').setQuoteMode(QuoteMode.ALL).get();
+ final CSVFormat left = right.builder().setHeader("Three", "Two", "One").get();
assertNotEquals(right, left);
}
@@ -318,8 +321,8 @@ public void testEqualsHeader_Deprecated() {
@Test
public void testEqualsIgnoreEmptyLines() {
final CSVFormat right = CSVFormat.newFormat('\'').builder().setCommentMarker('#').setEscape('+').setIgnoreEmptyLines(true)
- .setIgnoreSurroundingSpaces(true).setQuote('"').setQuoteMode(QuoteMode.ALL).build();
- final CSVFormat left = right.builder().setIgnoreEmptyLines(false).build();
+ .setIgnoreSurroundingSpaces(true).setQuote('"').setQuoteMode(QuoteMode.ALL).get();
+ final CSVFormat left = right.builder().setIgnoreEmptyLines(false).get();
assertNotEquals(right, left);
}
@@ -337,8 +340,8 @@ public void testEqualsIgnoreEmptyLines_Deprecated() {
@Test
public void testEqualsIgnoreSurroundingSpaces() {
final CSVFormat right = CSVFormat.newFormat('\'').builder().setCommentMarker('#').setEscape('+').setIgnoreSurroundingSpaces(true).setQuote('"')
- .setQuoteMode(QuoteMode.ALL).build();
- final CSVFormat left = right.builder().setIgnoreSurroundingSpaces(false).build();
+ .setQuoteMode(QuoteMode.ALL).get();
+ final CSVFormat left = right.builder().setIgnoreSurroundingSpaces(false).get();
assertNotEquals(right, left);
}
@@ -355,8 +358,8 @@ public void testEqualsIgnoreSurroundingSpaces_Deprecated() {
@Test
public void testEqualsLeftNoQuoteRightQuote() {
- final CSVFormat left = CSVFormat.newFormat(',').builder().setQuote(null).build();
- final CSVFormat right = left.builder().setQuote('#').build();
+ final CSVFormat left = CSVFormat.newFormat(',').builder().setQuote(null).get();
+ final CSVFormat right = left.builder().setQuote('#').get();
assertNotEquals(left, right);
}
@@ -372,8 +375,8 @@ public void testEqualsLeftNoQuoteRightQuote_Deprecated() {
@Test
public void testEqualsNoQuotes() {
- final CSVFormat left = CSVFormat.newFormat(',').builder().setQuote(null).build();
- final CSVFormat right = left.builder().setQuote(null).build();
+ final CSVFormat left = CSVFormat.newFormat(',').builder().setQuote(null).get();
+ final CSVFormat right = left.builder().setQuote(null).get();
assertEquals(left, right);
}
@@ -390,8 +393,8 @@ public void testEqualsNoQuotes_Deprecated() {
@Test
public void testEqualsNullString() {
final CSVFormat right = CSVFormat.newFormat('\'').builder().setRecordSeparator(CR).setCommentMarker('#').setEscape('+').setIgnoreEmptyLines(true)
- .setIgnoreSurroundingSpaces(true).setQuote('"').setQuoteMode(QuoteMode.ALL).setNullString("null").build();
- final CSVFormat left = right.builder().setNullString("---").build();
+ .setIgnoreSurroundingSpaces(true).setQuote('"').setQuoteMode(QuoteMode.ALL).setNullString("null").get();
+ final CSVFormat left = right.builder().setNullString("---").get();
assertNotEquals(right, left);
}
@@ -538,8 +541,8 @@ public void testEqualsOne() {
@Test
public void testEqualsQuoteChar() {
- final CSVFormat right = CSVFormat.newFormat('\'').builder().setQuote('"').build();
- final CSVFormat left = right.builder().setQuote('!').build();
+ final CSVFormat right = CSVFormat.newFormat('\'').builder().setQuote('"').get();
+ final CSVFormat left = right.builder().setQuote('!').get();
assertNotEquals(right, left);
}
@@ -555,8 +558,8 @@ public void testEqualsQuoteChar_Deprecated() {
@Test
public void testEqualsQuotePolicy() {
- final CSVFormat right = CSVFormat.newFormat('\'').builder().setQuote('"').setQuoteMode(QuoteMode.ALL).build();
- final CSVFormat left = right.builder().setQuoteMode(QuoteMode.MINIMAL).build();
+ final CSVFormat right = CSVFormat.newFormat('\'').builder().setQuote('"').setQuoteMode(QuoteMode.ALL).get();
+ final CSVFormat left = right.builder().setQuoteMode(QuoteMode.MINIMAL).get();
assertNotEquals(right, left);
}
@@ -573,8 +576,8 @@ public void testEqualsQuotePolicy_Deprecated() {
@Test
public void testEqualsRecordSeparator() {
final CSVFormat right = CSVFormat.newFormat('\'').builder().setRecordSeparator(CR).setCommentMarker('#').setEscape('+').setIgnoreEmptyLines(true)
- .setIgnoreSurroundingSpaces(true).setQuote('"').setQuoteMode(QuoteMode.ALL).build();
- final CSVFormat left = right.builder().setRecordSeparator(LF).build();
+ .setIgnoreSurroundingSpaces(true).setQuote('"').setQuoteMode(QuoteMode.ALL).get();
+ final CSVFormat left = right.builder().setRecordSeparator(LF).get();
assertNotEquals(right, left);
}
@@ -591,8 +594,8 @@ public void testEqualsRecordSeparator_Deprecated() {
public void testEqualsSkipHeaderRecord() {
final CSVFormat right = CSVFormat.newFormat('\'').builder().setRecordSeparator(CR).setCommentMarker('#').setEscape('+').setIgnoreEmptyLines(true)
- .setIgnoreSurroundingSpaces(true).setQuote('"').setQuoteMode(QuoteMode.ALL).setNullString("null").setSkipHeaderRecord(true).build();
- final CSVFormat left = right.builder().setSkipHeaderRecord(false).build();
+ .setIgnoreSurroundingSpaces(true).setQuote('"').setQuoteMode(QuoteMode.ALL).setNullString("null").setSkipHeaderRecord(true).get();
+ final CSVFormat left = right.builder().setSkipHeaderRecord(false).get();
assertNotEquals(right, left);
}
@@ -672,7 +675,7 @@ public void testEqualsWithNull() {
@Test
public void testEscapeSameAsCommentStartThrowsException() {
- assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.builder().setEscape('!').setCommentMarker('!').build());
+ assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.builder().setEscape('!').setCommentMarker('!').get());
}
@SuppressWarnings("deprecation")
@@ -685,7 +688,7 @@ public void testEscapeSameAsCommentStartThrowsException_Deprecated() {
public void testEscapeSameAsCommentStartThrowsExceptionForWrapperType() {
// Cannot assume that callers won't use different Character objects
assertThrows(IllegalArgumentException.class,
- () -> CSVFormat.DEFAULT.builder().setEscape(Character.valueOf('!')).setCommentMarker(Character.valueOf('!')).build());
+ () -> CSVFormat.DEFAULT.builder().setEscape(Character.valueOf('!')).setCommentMarker(Character.valueOf('!')).get());
}
@SuppressWarnings("deprecation")
@@ -736,20 +739,20 @@ public void testFormatToString() {
@Test
public void testGetAllowDuplicateHeaderNames() {
final Builder builder = CSVFormat.DEFAULT.builder();
- assertTrue(builder.build().getAllowDuplicateHeaderNames());
- assertTrue(builder.setDuplicateHeaderMode(DuplicateHeaderMode.ALLOW_ALL).build().getAllowDuplicateHeaderNames());
- assertFalse(builder.setDuplicateHeaderMode(DuplicateHeaderMode.ALLOW_EMPTY).build().getAllowDuplicateHeaderNames());
- assertFalse(builder.setDuplicateHeaderMode(DuplicateHeaderMode.DISALLOW).build().getAllowDuplicateHeaderNames());
+ assertTrue(builder.get().getAllowDuplicateHeaderNames());
+ assertTrue(builder.setDuplicateHeaderMode(DuplicateHeaderMode.ALLOW_ALL).get().getAllowDuplicateHeaderNames());
+ assertFalse(builder.setDuplicateHeaderMode(DuplicateHeaderMode.ALLOW_EMPTY).get().getAllowDuplicateHeaderNames());
+ assertFalse(builder.setDuplicateHeaderMode(DuplicateHeaderMode.DISALLOW).get().getAllowDuplicateHeaderNames());
}
@Test
public void testGetDuplicateHeaderMode() {
final Builder builder = CSVFormat.DEFAULT.builder();
- assertEquals(DuplicateHeaderMode.ALLOW_ALL, builder.build().getDuplicateHeaderMode());
- assertEquals(DuplicateHeaderMode.ALLOW_ALL, builder.setDuplicateHeaderMode(DuplicateHeaderMode.ALLOW_ALL).build().getDuplicateHeaderMode());
- assertEquals(DuplicateHeaderMode.ALLOW_EMPTY, builder.setDuplicateHeaderMode(DuplicateHeaderMode.ALLOW_EMPTY).build().getDuplicateHeaderMode());
- assertEquals(DuplicateHeaderMode.DISALLOW, builder.setDuplicateHeaderMode(DuplicateHeaderMode.DISALLOW).build().getDuplicateHeaderMode());
+ assertEquals(DuplicateHeaderMode.ALLOW_ALL, builder.get().getDuplicateHeaderMode());
+ assertEquals(DuplicateHeaderMode.ALLOW_ALL, builder.setDuplicateHeaderMode(DuplicateHeaderMode.ALLOW_ALL).get().getDuplicateHeaderMode());
+ assertEquals(DuplicateHeaderMode.ALLOW_EMPTY, builder.setDuplicateHeaderMode(DuplicateHeaderMode.ALLOW_EMPTY).get().getDuplicateHeaderMode());
+ assertEquals(DuplicateHeaderMode.DISALLOW, builder.setDuplicateHeaderMode(DuplicateHeaderMode.DISALLOW).get().getDuplicateHeaderMode());
}
@Test
@@ -785,7 +788,7 @@ public void testHashCodeAndWithIgnoreHeaderCase() {
@Test
public void testJiraCsv236() {
- CSVFormat.DEFAULT.builder().setAllowDuplicateHeaderNames(true).setHeader("CC", "VV", "VV").build();
+ CSVFormat.DEFAULT.builder().setAllowDuplicateHeaderNames(true).setHeader("CC", "VV", "VV").get();
}
@SuppressWarnings("deprecation")
@@ -857,7 +860,7 @@ public void testNewFormat() {
@Test
public void testNullRecordSeparatorCsv106() {
- final CSVFormat format = CSVFormat.newFormat(';').builder().setSkipHeaderRecord(true).setHeader("H1", "H2").build();
+ final CSVFormat format = CSVFormat.newFormat(';').builder().setSkipHeaderRecord(true).setHeader("H1", "H2").get();
final String formatStr = format.format("A", "B");
assertNotNull(formatStr);
assertFalse(formatStr.endsWith("null"));
@@ -935,7 +938,7 @@ public void testPrintWithQuotes() throws IOException {
@Test
public void testQuoteCharSameAsCommentStartThrowsException() {
- assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.builder().setQuote('!').setCommentMarker('!').build());
+ assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.builder().setQuote('!').setCommentMarker('!').get());
}
@SuppressWarnings("deprecation")
@@ -947,7 +950,7 @@ public void testQuoteCharSameAsCommentStartThrowsException_Deprecated() {
@Test
public void testQuoteCharSameAsCommentStartThrowsExceptionForWrapperType() {
// Cannot assume that callers won't use different Character objects
- assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.builder().setQuote(Character.valueOf('!')).setCommentMarker('!').build());
+ assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.builder().setQuote(Character.valueOf('!')).setCommentMarker('!').get());
}
@SuppressWarnings("deprecation")
@@ -959,7 +962,7 @@ public void testQuoteCharSameAsCommentStartThrowsExceptionForWrapperType_Depreca
@Test
public void testQuoteCharSameAsDelimiterThrowsException() {
- assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.builder().setQuote('!').setDelimiter('!').build());
+ assertThrows(IllegalArgumentException.class, () -> CSVFormat.DEFAULT.builder().setQuote('!').setDelimiter('!').get());
}
@SuppressWarnings("deprecation")
@@ -975,7 +978,7 @@ public void testQuoteModeNoneShouldReturnMeaningfulExceptionMessage() {
CSVFormat.DEFAULT.builder()
.setHeader("Col1", "Col2", "Col3", "Col4")
.setQuoteMode(QuoteMode.NONE)
- .build()
+ .get()
// @formatter:on
);
final String actualMessage = exception.getMessage();
@@ -985,7 +988,7 @@ public void testQuoteModeNoneShouldReturnMeaningfulExceptionMessage() {
@Test
public void testQuotePolicyNoneWithoutEscapeThrowsException() {
- assertThrows(IllegalArgumentException.class, () -> CSVFormat.newFormat('!').builder().setQuoteMode(QuoteMode.NONE).build());
+ assertThrows(IllegalArgumentException.class, () -> CSVFormat.newFormat('!').builder().setQuoteMode(QuoteMode.NONE).get());
}
@SuppressWarnings("deprecation")
@@ -1247,7 +1250,7 @@ public void testWithDelimiterLFThrowsException() {
@Test
public void testWithEmptyDuplicates() {
- final CSVFormat formatWithEmptyDuplicates = CSVFormat.DEFAULT.builder().setDuplicateHeaderMode(DuplicateHeaderMode.ALLOW_EMPTY).build();
+ final CSVFormat formatWithEmptyDuplicates = CSVFormat.DEFAULT.builder().setDuplicateHeaderMode(DuplicateHeaderMode.ALLOW_EMPTY).get();
assertEquals(DuplicateHeaderMode.ALLOW_EMPTY, formatWithEmptyDuplicates.getDuplicateHeaderMode());
assertFalse(formatWithEmptyDuplicates.getAllowDuplicateHeaderNames());
diff --git a/src/test/java/org/apache/commons/csv/CSVParserTest.java b/src/test/java/org/apache/commons/csv/CSVParserTest.java
index aed3a2056..8f5d577f6 100644
--- a/src/test/java/org/apache/commons/csv/CSVParserTest.java
+++ b/src/test/java/org/apache/commons/csv/CSVParserTest.java
@@ -99,7 +99,7 @@ public class CSVParserTest {
"# multi-line" + CRLF + "# comment";
// Format with auto-detected header
- static private final CSVFormat FORMAT_AUTO_HEADER = CSVFormat.Builder.create(CSVFormat.DEFAULT).setCommentMarker('#').setHeader().build();
+ static private final CSVFormat FORMAT_AUTO_HEADER = CSVFormat.Builder.create(CSVFormat.DEFAULT).setCommentMarker('#').setHeader().get();
// Format with explicit header
// @formatter:off
@@ -107,7 +107,7 @@ public class CSVParserTest {
.setSkipHeaderRecord(true)
.setCommentMarker('#')
.setHeader("A", "B")
- .build();
+ .get();
// @formatter:on
// Format with explicit header that does not skip the header line
@@ -115,7 +115,7 @@ public class CSVParserTest {
CSVFormat FORMAT_EXPLICIT_HEADER_NOSKIP = CSVFormat.Builder.create(CSVFormat.DEFAULT)
.setCommentMarker('#')
.setHeader("A", "B")
- .build();
+ .get();
// @formatter:on
@SuppressWarnings("resource") // caller releases
@@ -1243,7 +1243,7 @@ public void testNotValueCSV() throws IOException {
public void testParse() throws Exception {
final ClassLoader loader = ClassLoader.getSystemClassLoader();
final URL url = loader.getResource("org/apache/commons/csv/CSVFileParser/test.csv");
- final CSVFormat format = CSVFormat.DEFAULT.builder().setHeader("A", "B", "C", "D").build();
+ final CSVFormat format = CSVFormat.DEFAULT.builder().setHeader("A", "B", "C", "D").get();
final Charset charset = StandardCharsets.UTF_8;
// Reader
try (final CSVParser parser = CSVParser.parse(new InputStreamReader(url.openStream(), charset), format)) {
@@ -1350,7 +1350,7 @@ public void testParseUrlCharsetNullFormat() {
@Test
public void testParseWithDelimiterStringWithEscape() throws IOException {
final String source = "a![!|!]b![|]c[|]xyz\r\nabc[abc][|]xyz";
- final CSVFormat csvFormat = CSVFormat.DEFAULT.builder().setDelimiter("[|]").setEscape('!').build();
+ final CSVFormat csvFormat = CSVFormat.DEFAULT.builder().setDelimiter("[|]").setEscape('!').get();
try (CSVParser csvParser = csvFormat.parse(new StringReader(source))) {
CSVRecord csvRecord = csvParser.nextRecord();
assertEquals("a[|]b![|]c", csvRecord.get(0));
@@ -1364,7 +1364,7 @@ public void testParseWithDelimiterStringWithEscape() throws IOException {
@Test
public void testParseWithDelimiterStringWithQuote() throws IOException {
final String source = "'a[|]b[|]c'[|]xyz\r\nabc[abc][|]xyz";
- final CSVFormat csvFormat = CSVFormat.DEFAULT.builder().setDelimiter("[|]").setQuote('\'').build();
+ final CSVFormat csvFormat = CSVFormat.DEFAULT.builder().setDelimiter("[|]").setQuote('\'').get();
try (CSVParser csvParser = csvFormat.parse(new StringReader(source))) {
CSVRecord csvRecord = csvParser.nextRecord();
assertEquals("a[|]b[|]c", csvRecord.get(0));
@@ -1592,7 +1592,7 @@ public void testThrowExceptionWithLineAndPosition() throws IOException {
final CSVFormat csvFormat = CSVFormat.DEFAULT.builder()
.setHeader()
.setSkipHeaderRecord(true)
- .build();
+ .get();
// @formatter:on
try (CSVParser csvParser = csvFormat.parse(stringReader)) {
final UncheckedIOException exception = assertThrows(UncheckedIOException.class, csvParser::getRecords);
diff --git a/src/test/java/org/apache/commons/csv/CSVPrinterTest.java b/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
index 2bd318ca4..99e82fa64 100644
--- a/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
+++ b/src/test/java/org/apache/commons/csv/CSVPrinterTest.java
@@ -184,7 +184,7 @@ private CSVPrinter printWithHeaderComments(final StringWriter sw, final Date now
.setHeaderComments("Generated by Apache Commons CSV 1.1", now)
.setCommentMarker('#')
.setHeader("Col1", "Col2")
- .build();
+ .get();
// @formatter:on
final CSVPrinter printer = format.print(sw);
printer.printRecord("A", "B");
@@ -390,7 +390,7 @@ public void testDelimeterQuoteNone() throws IOException {
@Test
public void testDelimeterStringQuoted() throws IOException {
final StringWriter sw = new StringWriter();
- try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.builder().setDelimiter("[|]").setQuote('\'').build())) {
+ try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.builder().setDelimiter("[|]").setQuote('\'').get())) {
assertInitialState(printer);
printer.print("a[|]b[|]c");
printer.print("xyz");
@@ -401,7 +401,7 @@ public void testDelimeterStringQuoted() throws IOException {
@Test
public void testDelimeterStringQuoteNone() throws IOException {
final StringWriter sw = new StringWriter();
- final CSVFormat format = CSVFormat.DEFAULT.builder().setDelimiter("[|]").setEscape('!').setQuoteMode(QuoteMode.NONE).build();
+ final CSVFormat format = CSVFormat.DEFAULT.builder().setDelimiter("[|]").setEscape('!').setQuoteMode(QuoteMode.NONE).get();
try (final CSVPrinter printer = new CSVPrinter(sw, format)) {
assertInitialState(printer);
printer.print("a[|]b[|]c");
@@ -436,7 +436,7 @@ public void testDelimiterPlain() throws IOException {
@Test
public void testDelimiterStringEscaped() throws IOException {
final StringWriter sw = new StringWriter();
- try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.builder().setDelimiter("|||").setEscape('!').setQuote(null).build())) {
+ try (final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.builder().setDelimiter("|||").setEscape('!').setQuote(null).get())) {
assertInitialState(printer);
printer.print("a|||b|||c");
printer.print("xyz");
diff --git a/src/test/java/org/apache/commons/csv/CSVRecordTest.java b/src/test/java/org/apache/commons/csv/CSVRecordTest.java
index b1f61a141..5b0c5d812 100644
--- a/src/test/java/org/apache/commons/csv/CSVRecordTest.java
+++ b/src/test/java/org/apache/commons/csv/CSVRecordTest.java
@@ -76,7 +76,7 @@ public void setUp() throws Exception {
try (final CSVParser parser = CSVFormat.DEFAULT.parse(new StringReader(rowData))) {
record = parser.iterator().next();
}
- try (final CSVParser parser = CSVFormat.DEFAULT.builder().setHeader(EnumHeader.class).build().parse(new StringReader(rowData))) {
+ try (final CSVParser parser = CSVFormat.DEFAULT.builder().setHeader(EnumHeader.class).get().parse(new StringReader(rowData))) {
recordWithHeader = parser.iterator().next();
headerMap = parser.getHeaderMap();
}
@@ -94,7 +94,7 @@ public void testCSVRecordNULLValues() throws IOException {
@Test
public void testDuplicateHeaderGet() throws IOException {
final String csv = "A,A,B,B\n1,2,5,6\n";
- final CSVFormat format = CSVFormat.DEFAULT.builder().setHeader().build();
+ final CSVFormat format = CSVFormat.DEFAULT.builder().setHeader().get();
try (final CSVParser parser = CSVParser.parse(csv, format)) {
final CSVRecord record = parser.nextRecord();
@@ -109,7 +109,7 @@ public void testDuplicateHeaderGet() throws IOException {
@Test
public void testDuplicateHeaderToMap() throws IOException {
final String csv = "A,A,B,B\n1,2,5,6\n";
- final CSVFormat format = CSVFormat.DEFAULT.builder().setHeader().build();
+ final CSVFormat format = CSVFormat.DEFAULT.builder().setHeader().get();
try (final CSVParser parser = CSVParser.parse(csv, format)) {
final CSVRecord record = parser.nextRecord();
diff --git a/src/test/java/org/apache/commons/csv/LexerTest.java b/src/test/java/org/apache/commons/csv/LexerTest.java
index e6ccaea53..6a1aabf30 100644
--- a/src/test/java/org/apache/commons/csv/LexerTest.java
+++ b/src/test/java/org/apache/commons/csv/LexerTest.java
@@ -199,11 +199,11 @@ public void testDelimiterIsWhitespace() throws IOException {
@Test
public void testEOFWithoutClosingQuote() throws Exception {
final String code = "a,\"b";
- try (final Lexer parser = createLexer(code, CSVFormat.Builder.create().setLenientEof(true).build())) {
+ try (final Lexer parser = createLexer(code, CSVFormat.Builder.create().setLenientEof(true).get())) {
assertThat(parser.nextToken(new Token()), matches(TOKEN, "a"));
assertThat(parser.nextToken(new Token()), matches(EOF, "b"));
}
- try (final Lexer parser = createLexer(code, CSVFormat.Builder.create().setLenientEof(false).build())) {
+ try (final Lexer parser = createLexer(code, CSVFormat.Builder.create().setLenientEof(false).get())) {
assertThat(parser.nextToken(new Token()), matches(TOKEN, "a"));
assertThrows(IOException.class, () -> parser.nextToken(new Token()));
}
@@ -439,12 +439,12 @@ public void testTab() throws Exception {
@Test
public void testTrailingTextAfterQuote() throws Exception {
final String code = "\"a\" b,\"a\" \" b,\"a\" b \"\"";
- try (final Lexer parser = createLexer(code, CSVFormat.Builder.create().setTrailingData(true).build())) {
+ try (final Lexer parser = createLexer(code, CSVFormat.Builder.create().setTrailingData(true).get())) {
assertThat(parser.nextToken(new Token()), matches(TOKEN, "a b"));
assertThat(parser.nextToken(new Token()), matches(TOKEN, "a \" b"));
assertThat(parser.nextToken(new Token()), matches(EOF, "a b \"\""));
}
- try (final Lexer parser = createLexer(code, CSVFormat.Builder.create().setTrailingData(false).build())) {
+ try (final Lexer parser = createLexer(code, CSVFormat.Builder.create().setTrailingData(false).get())) {
assertThrows(IOException.class, () -> parser.nextToken(new Token()));
}
}
diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv148Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv148Test.java
index 62cd33b2c..82fd98560 100644
--- a/src/test/java/org/apache/commons/csv/issues/JiraCsv148Test.java
+++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv148Test.java
@@ -30,7 +30,7 @@ public void testWithIgnoreSurroundingSpacesEmpty() {
final CSVFormat format = CSVFormat.DEFAULT.builder()
.setQuoteMode(QuoteMode.ALL)
.setIgnoreSurroundingSpaces(true)
- .build();
+ .get();
// @formatter:on
assertEquals(
"\"\",\" \",\" Single space on the left\",\"Single space on the right \"," +
@@ -50,7 +50,7 @@ public void testWithTrimEmpty() {
final CSVFormat format = CSVFormat.DEFAULT.builder()
.setQuoteMode(QuoteMode.ALL)
.setTrim(true)
- .build();
+ .get();
// @formatter:on
assertEquals(
"\"\",\"\",\"Single space on the left\",\"Single space on the right\"," + "\"Single spaces on both sides\",\"Multiple spaces on the left\"," +
diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv149Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv149Test.java
index 0a08958e8..d287c32f6 100644
--- a/src/test/java/org/apache/commons/csv/issues/JiraCsv149Test.java
+++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv149Test.java
@@ -47,7 +47,7 @@ private void testJiraCsv149EndWithEolAtEof(final boolean eolAtEof) throws IOExce
.setHeader()
.setSkipHeaderRecord(true)
.setQuote('"')
- .build();
+ .get();
// @formatter:on
int lineCounter = 2;
try (final CSVParser parser = CSVParser.builder().setReader(reader).setFormat(format).get()) {
diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv150Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv150Test.java
index 7d8ba89fd..620dab7fc 100644
--- a/src/test/java/org/apache/commons/csv/issues/JiraCsv150Test.java
+++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv150Test.java
@@ -36,18 +36,18 @@ private void testDisable(final CSVFormat format, final StringReader reader) thro
@Test
public void testDisableComment() throws IOException {
final StringReader stringReader = new StringReader("\"66\u2441\",,\"\",\"DeutscheBK\ufffe\",\"000\"\r\n");
- testDisable(CSVFormat.DEFAULT.builder().setCommentMarker(null).build(), stringReader);
+ testDisable(CSVFormat.DEFAULT.builder().setCommentMarker(null).get(), stringReader);
}
@Test
public void testDisableEncapsulation() throws IOException {
final StringReader stringReader = new StringReader("66\u2441,,\"\",\ufffeDeutscheBK,\"000\"\r\n");
- testDisable(CSVFormat.DEFAULT.builder().setQuote(null).build(), stringReader);
+ testDisable(CSVFormat.DEFAULT.builder().setQuote(null).get(), stringReader);
}
@Test
public void testDisableEscaping() throws IOException {
final StringReader stringReader = new StringReader("\"66\u2441\",,\"\",\"DeutscheBK\ufffe\",\"000\"\r\n");
- testDisable(CSVFormat.DEFAULT.builder().setEscape(null).build(), stringReader);
+ testDisable(CSVFormat.DEFAULT.builder().setEscape(null).get(), stringReader);
}
}
diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv154Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv154Test.java
index 1f7d93e26..93a429632 100644
--- a/src/test/java/org/apache/commons/csv/issues/JiraCsv154Test.java
+++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv154Test.java
@@ -34,7 +34,7 @@ public void testJiraCsv154_withCommentMarker() throws IOException {
.setHeader("H1", "H2")
.setCommentMarker('#')
.setHeaderComments(comment)
- .build();
+ .get();
// @formatter:on
final StringBuilder out = new StringBuilder();
try (final CSVPrinter printer = format.print(out)) {
@@ -53,7 +53,7 @@ public void testJiraCsv154_withHeaderComments() throws IOException {
.setHeader("H1", "H2")
.setHeaderComments(comment)
.setCommentMarker('#')
- .build();
+ .get();
// @formatter:on
final StringBuilder out = new StringBuilder();
try (final CSVPrinter printer = format.print(out)) {
diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv167Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv167Test.java
index 57d63298e..f7e85b5f1 100644
--- a/src/test/java/org/apache/commons/csv/issues/JiraCsv167Test.java
+++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv167Test.java
@@ -70,7 +70,7 @@ public void testParse() throws IOException {
.setQuoteMode(QuoteMode.ALL)
.setRecordSeparator('\n')
.setSkipHeaderRecord(false)
- .build();
+ .get();
// @formatter:on
int comments = 0;
int records = 0;
diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv198Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv198Test.java
index 996e2eb3b..e07cf98bc 100644
--- a/src/test/java/org/apache/commons/csv/issues/JiraCsv198Test.java
+++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv198Test.java
@@ -35,7 +35,7 @@ public class JiraCsv198Test {
.setDelimiter('^')
.setHeader()
.setSkipHeaderRecord(true)
- .build();
+ .get();
// @formatter:on
@Test
diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv203Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv203Test.java
index 17c62351e..4469b3660 100644
--- a/src/test/java/org/apache/commons/csv/issues/JiraCsv203Test.java
+++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv203Test.java
@@ -36,7 +36,7 @@ public void testQuoteModeAll() throws Exception {
.setNullString("N/A")
.setIgnoreSurroundingSpaces(true)
.setQuoteMode(QuoteMode.ALL)
- .build();
+ .get();
// @formatter:on
final StringBuilder buffer = new StringBuilder();
try (final CSVPrinter printer = new CSVPrinter(buffer, format)) {
@@ -52,7 +52,7 @@ public void testQuoteModeAllNonNull() throws Exception {
.setNullString("N/A")
.setIgnoreSurroundingSpaces(true)
.setQuoteMode(QuoteMode.ALL_NON_NULL)
- .build();
+ .get();
// @formatter:on
final StringBuilder buffer = new StringBuilder();
try (final CSVPrinter printer = new CSVPrinter(buffer, format)) {
@@ -68,7 +68,7 @@ public void testQuoteModeMinimal() throws Exception {
.setNullString("N/A")
.setIgnoreSurroundingSpaces(true)
.setQuoteMode(QuoteMode.MINIMAL)
- .build();
+ .get();
// @formatter:on
final StringBuilder buffer = new StringBuilder();
try (final CSVPrinter printer = new CSVPrinter(buffer, format)) {
@@ -84,7 +84,7 @@ public void testQuoteModeNonNumeric() throws Exception {
.setNullString("N/A")
.setIgnoreSurroundingSpaces(true)
.setQuoteMode(QuoteMode.NON_NUMERIC)
- .build();
+ .get();
// @formatter:on
final StringBuilder buffer = new StringBuilder();
try (final CSVPrinter printer = new CSVPrinter(buffer, format)) {
@@ -100,7 +100,7 @@ public void testWithEmptyValues() throws Exception {
.setNullString("N/A")
.setIgnoreSurroundingSpaces(true)
.setQuoteMode(QuoteMode.ALL)
- .build();
+ .get();
// @formatter:on
final StringBuilder buffer = new StringBuilder();
try (final CSVPrinter printer = new CSVPrinter(buffer, format)) {
@@ -117,7 +117,7 @@ public void testWithoutNullString() throws Exception {
//.setNullString("N/A")
.setIgnoreSurroundingSpaces(true)
.setQuoteMode(QuoteMode.ALL)
- .build();
+ .get();
// @formatter:on
final StringBuilder buffer = new StringBuilder();
try (final CSVPrinter printer = new CSVPrinter(buffer, format)) {
@@ -132,7 +132,7 @@ public void testWithoutQuoteMode() throws Exception {
final CSVFormat format = CSVFormat.EXCEL.builder()
.setNullString("N/A")
.setIgnoreSurroundingSpaces(true)
- .build();
+ .get();
// @formatter:on
final StringBuilder buffer = new StringBuilder();
try (final CSVPrinter printer = new CSVPrinter(buffer, format)) {
diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv206Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv206Test.java
index 26645a169..2932982fc 100644
--- a/src/test/java/org/apache/commons/csv/issues/JiraCsv206Test.java
+++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv206Test.java
@@ -35,7 +35,7 @@ public void testJiraCsv206MultipleCharacterDelimiter() throws IOException {
// Read with multiple character delimiter
final String source = "FirstName[|]LastName[|]Address\r\nJohn[|]Smith[|]123 Main St.";
final StringReader reader = new StringReader(source);
- final CSVFormat format = CSVFormat.DEFAULT.builder().setDelimiter("[|]").build();
+ final CSVFormat format = CSVFormat.DEFAULT.builder().setDelimiter("[|]").get();
CSVRecord record = null;
try (final CSVParser csvParser = CSVParser.builder().setReader(reader).setFormat(format).get()) {
final Iterator iterator = csvParser.iterator();
@@ -60,7 +60,7 @@ record = iterator.next();
final CSVFormat formatExcel = CSVFormat.EXCEL.builder()
.setDelimiter("[I]").setHeader("first name", "last name", "address")
.setCommentMarker('#')
- .setHeaderComments(comment).build();
+ .setHeaderComments(comment).get();
// @formatter:on
final StringBuilder out = new StringBuilder();
try (final CSVPrinter printer = formatExcel.print(out)) {
diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv211Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv211Test.java
index 126e85e50..0cc552206 100644
--- a/src/test/java/org/apache/commons/csv/issues/JiraCsv211Test.java
+++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv211Test.java
@@ -33,12 +33,12 @@ public void testJiraCsv211Format() throws IOException {
final CSVFormat printFormat = CSVFormat.DEFAULT.builder()
.setDelimiter('\t')
.setHeader("ID", "Name", "Country", "Age")
- .build();
+ .get();
// @formatter:on
final String formatted = printFormat.format("1", "Jane Doe", "USA", "");
assertEquals("ID\tName\tCountry\tAge\r\n1\tJane Doe\tUSA\t", formatted);
- final CSVFormat parseFormat = CSVFormat.DEFAULT.builder().setDelimiter('\t').setHeader().setSkipHeaderRecord(true).build();
+ final CSVFormat parseFormat = CSVFormat.DEFAULT.builder().setDelimiter('\t').setHeader().setSkipHeaderRecord(true).get();
try (final CSVParser parser = parseFormat.parse(new StringReader(formatted))) {
parser.forEach(record -> {
assertEquals("1", record.get(0));
diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv213Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv213Test.java
index e175ff0e9..8e5ec9baa 100644
--- a/src/test/java/org/apache/commons/csv/issues/JiraCsv213Test.java
+++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv213Test.java
@@ -46,7 +46,7 @@ private void createEndChannel(final File csvFile) {
.setSkipHeaderRecord(true)
.setRecordSeparator('\n')
.setQuoteMode(QuoteMode.ALL)
- .build();
+ .get();
// @formatter:on
try (Reader reader = Files.newBufferedReader(csvFile.toPath(), StandardCharsets.UTF_8);
CSVParser parser = csvFormat.parse(reader)) {
diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv247Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv247Test.java
index 4dc18a001..4cf5bbbe3 100644
--- a/src/test/java/org/apache/commons/csv/issues/JiraCsv247Test.java
+++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv247Test.java
@@ -36,7 +36,7 @@ public class JiraCsv247Test {
@Test
public void testHeadersMissingOneColumnWhenAllowingMissingColumnNames() throws Exception {
- final CSVFormat format = CSVFormat.DEFAULT.builder().setHeader().setAllowMissingColumnNames(true).build();
+ final CSVFormat format = CSVFormat.DEFAULT.builder().setHeader().setAllowMissingColumnNames(true).get();
assertTrue(format.getAllowMissingColumnNames(), "We should allow missing column names");
@@ -62,7 +62,7 @@ record = iterator.next();
@Test
public void testHeadersMissingThrowsWhenNotAllowingMissingColumnNames() {
- final CSVFormat format = CSVFormat.DEFAULT.builder().setHeader().build();
+ final CSVFormat format = CSVFormat.DEFAULT.builder().setHeader().get();
assertFalse(format.getAllowMissingColumnNames(), "By default we should not allow missing column names");
diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv249Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv249Test.java
index 58caced45..e8b2cbf86 100644
--- a/src/test/java/org/apache/commons/csv/issues/JiraCsv249Test.java
+++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv249Test.java
@@ -34,7 +34,7 @@ public class JiraCsv249Test {
@Test
public void testJiraCsv249() throws IOException {
- final CSVFormat format = CSVFormat.DEFAULT.builder().setEscape('\\').build();
+ final CSVFormat format = CSVFormat.DEFAULT.builder().setEscape('\\').get();
final StringWriter stringWriter = new StringWriter();
try (CSVPrinter printer = new CSVPrinter(stringWriter, format)) {
printer.printRecord("foo \\", "bar");
diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv253Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv253Test.java
index 90507313e..0e429a372 100644
--- a/src/test/java/org/apache/commons/csv/issues/JiraCsv253Test.java
+++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv253Test.java
@@ -42,7 +42,7 @@ private void assertArrayEqual(final String[] expected, final CSVRecord actual) {
@Test
public void testHandleAbsentValues() throws IOException {
final String source = "\"John\",,\"Doe\"\n" + ",\"AA\",123\n" + "\"John\",90,\n" + "\"\",,90";
- final CSVFormat csvFormat = CSVFormat.DEFAULT.builder().setQuoteMode(QuoteMode.NON_NUMERIC).build();
+ final CSVFormat csvFormat = CSVFormat.DEFAULT.builder().setQuoteMode(QuoteMode.NON_NUMERIC).get();
try (final CSVParser parser = csvFormat.parse(new StringReader(source))) {
final Iterator csvRecords = parser.iterator();
assertArrayEqual(new String[] {"John", null, "Doe"}, csvRecords.next());
diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv263Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv263Test.java
index 062ed7caf..39e61b46a 100644
--- a/src/test/java/org/apache/commons/csv/issues/JiraCsv263Test.java
+++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv263Test.java
@@ -40,7 +40,7 @@ public void testPrintFromReaderWithQuotes() throws IOException {
.setQuote('"')
.setEscape('?')
.setQuoteMode(QuoteMode.NON_NUMERIC)
- .build();
+ .get();
// @formatter:on
final StringBuilder out = new StringBuilder();
diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv264Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv264Test.java
index 0e18ae55b..ee83c569e 100644
--- a/src/test/java/org/apache/commons/csv/issues/JiraCsv264Test.java
+++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv264Test.java
@@ -53,7 +53,7 @@ public void testJiraCsv264() {
.setHeader()
.setDuplicateHeaderMode(DuplicateHeaderMode.DISALLOW)
.setAllowMissingColumnNames(true)
- .build();
+ .get();
try (StringReader reader = new StringReader(CSV_STRING)) {
assertThrows(IllegalArgumentException.class, () -> csvFormat.parse(reader));
@@ -67,7 +67,7 @@ public void testJiraCsv264WithGapAllowEmpty() throws IOException {
.setHeader()
.setDuplicateHeaderMode(DuplicateHeaderMode.ALLOW_EMPTY)
.setAllowMissingColumnNames(true)
- .build();
+ .get();
try (StringReader reader = new StringReader(CSV_STRING_GAP); final CSVParser parser = csvFormat.parse(reader)) {
// empty
@@ -81,7 +81,7 @@ public void testJiraCsv264WithGapDisallow() {
.setHeader()
.setDuplicateHeaderMode(DuplicateHeaderMode.DISALLOW)
.setAllowMissingColumnNames(true)
- .build();
+ .get();
try (StringReader reader = new StringReader(CSV_STRING_GAP)) {
assertThrows(IllegalArgumentException.class, () -> csvFormat.parse(reader));
diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv265Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv265Test.java
index ac5f851d6..6d8997685 100644
--- a/src/test/java/org/apache/commons/csv/issues/JiraCsv265Test.java
+++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv265Test.java
@@ -48,7 +48,7 @@ public void testCharacterPositionWithComments() throws IOException {
.setCommentMarker('#')
.setHeader()
.setSkipHeaderRecord(true)
- .build();
+ .get();
// @formatter:on
try (final CSVParser parser = csvFormat.parse(new StringReader(csv))) {
final Iterator itr = parser.iterator();
@@ -76,7 +76,7 @@ public void testCharacterPositionWithCommentsSpanningMultipleLines() throws IOEx
.setCommentMarker('#')
.setHeader()
.setSkipHeaderRecord(true)
- .build();
+ .get();
// @formatter:on
try (final CSVParser parser = csvFormat.parse(new StringReader(csv))) {
final Iterator itr = parser.iterator();
diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv288Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv288Test.java
index 4d5307e9b..965469c64 100644
--- a/src/test/java/org/apache/commons/csv/issues/JiraCsv288Test.java
+++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv288Test.java
@@ -44,7 +44,7 @@ public void testParseWithABADelimiter() throws Exception {
final Reader in = new StringReader("a|~|b|~|c|~|d|~||~|f");
final StringBuilder stringBuilder = new StringBuilder();
try (CSVPrinter csvPrinter = new CSVPrinter(stringBuilder, CSVFormat.EXCEL);
- CSVParser parser = CSVParser.parse(in, CSVFormat.Builder.create().setDelimiter("|~|").build())) {
+ CSVParser parser = CSVParser.parse(in, CSVFormat.Builder.create().setDelimiter("|~|").get())) {
for (final CSVRecord csvRecord : parser) {
print(csvRecord, csvPrinter);
assertEquals("a,b,c,d,,f", stringBuilder.toString());
@@ -59,7 +59,7 @@ public void testParseWithDoublePipeDelimiter() throws Exception {
final Reader in = new StringReader("a||b||c||d||||f");
final StringBuilder stringBuilder = new StringBuilder();
try (CSVPrinter csvPrinter = new CSVPrinter(stringBuilder, CSVFormat.EXCEL);
- CSVParser csvParser = CSVParser.parse(in, CSVFormat.Builder.create().setDelimiter("||").build())) {
+ CSVParser csvParser = CSVParser.parse(in, CSVFormat.Builder.create().setDelimiter("||").get())) {
for (final CSVRecord csvRecord : csvParser) {
print(csvRecord, csvPrinter);
assertEquals("a,b,c,d,,f", stringBuilder.toString());
@@ -74,7 +74,7 @@ public void testParseWithDoublePipeDelimiterDoubleCharValue() throws Exception {
final Reader in = new StringReader("a||bb||cc||dd||f");
final StringBuilder stringBuilder = new StringBuilder();
try (CSVPrinter csvPrinter = new CSVPrinter(stringBuilder, CSVFormat.EXCEL);
- CSVParser csvParser = CSVParser.parse(in, CSVFormat.Builder.create().setDelimiter("||").build())) {
+ CSVParser csvParser = CSVParser.parse(in, CSVFormat.Builder.create().setDelimiter("||").get())) {
for (final CSVRecord csvRecord : csvParser) {
print(csvRecord, csvPrinter);
assertEquals("a,bb,cc,dd,f", stringBuilder.toString());
@@ -89,7 +89,7 @@ public void testParseWithDoublePipeDelimiterEndsWithDelimiter() throws Exception
final Reader in = new StringReader("a||b||c||d||||f||");
final StringBuilder stringBuilder = new StringBuilder();
try (CSVPrinter csvPrinter = new CSVPrinter(stringBuilder, CSVFormat.EXCEL);
- CSVParser csvParser = CSVParser.parse(in, CSVFormat.Builder.create().setDelimiter("||").build())) {
+ CSVParser csvParser = CSVParser.parse(in, CSVFormat.Builder.create().setDelimiter("||").get())) {
for (final CSVRecord csvRecord : csvParser) {
print(csvRecord, csvPrinter);
assertEquals("a,b,c,d,,f,", stringBuilder.toString());
@@ -104,7 +104,7 @@ public void testParseWithDoublePipeDelimiterQuoted() throws Exception {
final Reader in = new StringReader("a||\"b||c\"||d||||f");
final StringBuilder stringBuilder = new StringBuilder();
try (CSVPrinter csvPrinter = new CSVPrinter(stringBuilder, CSVFormat.EXCEL);
- CSVParser csvParser = CSVParser.parse(in, CSVFormat.Builder.create().setDelimiter("||").build())) {
+ CSVParser csvParser = CSVParser.parse(in, CSVFormat.Builder.create().setDelimiter("||").get())) {
for (final CSVRecord csvRecord : csvParser) {
print(csvRecord, csvPrinter);
assertEquals("a,b||c,d,,f", stringBuilder.toString());
@@ -118,7 +118,7 @@ public void testParseWithSinglePipeDelimiterEndsWithDelimiter() throws Exception
final Reader in = new StringReader("a|b|c|d||f|");
final StringBuilder stringBuilder = new StringBuilder();
try (CSVPrinter csvPrinter = new CSVPrinter(stringBuilder, CSVFormat.EXCEL);
- CSVParser csvParser = CSVParser.parse(in, CSVFormat.Builder.create().setDelimiter("|").build())) {
+ CSVParser csvParser = CSVParser.parse(in, CSVFormat.Builder.create().setDelimiter("|").get())) {
for (final CSVRecord csvRecord : csvParser) {
print(csvRecord, csvPrinter);
assertEquals("a,b,c,d,,f,", stringBuilder.toString());
@@ -133,7 +133,7 @@ public void testParseWithTriplePipeDelimiter() throws Exception {
final Reader in = new StringReader("a|||b|||c|||d||||||f");
final StringBuilder stringBuilder = new StringBuilder();
try (CSVPrinter csvPrinter = new CSVPrinter(stringBuilder, CSVFormat.EXCEL);
- CSVParser csvParser = CSVParser.parse(in, CSVFormat.Builder.create().setDelimiter("|||").build())) {
+ CSVParser csvParser = CSVParser.parse(in, CSVFormat.Builder.create().setDelimiter("|||").get())) {
for (final CSVRecord csvRecord : csvParser) {
print(csvRecord, csvPrinter);
assertEquals("a,b,c,d,,f", stringBuilder.toString());
@@ -147,7 +147,7 @@ public void testParseWithTwoCharDelimiter1() throws Exception {
final Reader in = new StringReader("a~|b~|c~|d~|~|f");
final StringBuilder stringBuilder = new StringBuilder();
try (CSVPrinter csvPrinter = new CSVPrinter(stringBuilder, CSVFormat.EXCEL);
- CSVParser csvParser = CSVParser.parse(in, CSVFormat.Builder.create().setDelimiter("~|").build())) {
+ CSVParser csvParser = CSVParser.parse(in, CSVFormat.Builder.create().setDelimiter("~|").get())) {
for (final CSVRecord csvRecord : csvParser) {
print(csvRecord, csvPrinter);
assertEquals("a,b,c,d,,f", stringBuilder.toString());
@@ -161,7 +161,7 @@ public void testParseWithTwoCharDelimiter2() throws Exception {
final Reader in = new StringReader("a~|b~|c~|d~|~|f~");
final StringBuilder stringBuilder = new StringBuilder();
try (CSVPrinter csvPrinter = new CSVPrinter(stringBuilder, CSVFormat.EXCEL);
- CSVParser csvParser = CSVParser.parse(in, CSVFormat.Builder.create().setDelimiter("~|").build())) {
+ CSVParser csvParser = CSVParser.parse(in, CSVFormat.Builder.create().setDelimiter("~|").get())) {
for (final CSVRecord csvRecord : csvParser) {
print(csvRecord, csvPrinter);
assertEquals("a,b,c,d,,f~", stringBuilder.toString());
@@ -175,7 +175,7 @@ public void testParseWithTwoCharDelimiter3() throws Exception {
final Reader in = new StringReader("a~|b~|c~|d~|~|f|");
final StringBuilder stringBuilder = new StringBuilder();
try (CSVPrinter csvPrinter = new CSVPrinter(stringBuilder, CSVFormat.EXCEL);
- CSVParser csvParser = CSVParser.parse(in, CSVFormat.Builder.create().setDelimiter("~|").build())) {
+ CSVParser csvParser = CSVParser.parse(in, CSVFormat.Builder.create().setDelimiter("~|").get())) {
for (final CSVRecord csvRecord : csvParser) {
print(csvRecord, csvPrinter);
assertEquals("a,b,c,d,,f|", stringBuilder.toString());
@@ -189,7 +189,7 @@ public void testParseWithTwoCharDelimiter4() throws Exception {
final Reader in = new StringReader("a~|b~|c~|d~|~|f~~||g");
final StringBuilder stringBuilder = new StringBuilder();
try (CSVPrinter csvPrinter = new CSVPrinter(stringBuilder, CSVFormat.EXCEL);
- CSVParser csvParser = CSVParser.parse(in, CSVFormat.Builder.create().setDelimiter("~|").build())) {
+ CSVParser csvParser = CSVParser.parse(in, CSVFormat.Builder.create().setDelimiter("~|").get())) {
for (final CSVRecord csvRecord : csvParser) {
print(csvRecord, csvPrinter);
assertEquals("a,b,c,d,,f~,|g", stringBuilder.toString());
@@ -204,7 +204,7 @@ public void testParseWithTwoCharDelimiterEndsWithDelimiter() throws Exception {
final Reader in = new StringReader("a~|b~|c~|d~|~|f~|");
final StringBuilder stringBuilder = new StringBuilder();
try (CSVPrinter csvPrinter = new CSVPrinter(stringBuilder, CSVFormat.EXCEL);
- CSVParser csvParser = CSVParser.parse(in, CSVFormat.Builder.create().setDelimiter("~|").build())) {
+ CSVParser csvParser = CSVParser.parse(in, CSVFormat.Builder.create().setDelimiter("~|").get())) {
for (final CSVRecord csvRecord : csvParser) {
print(csvRecord, csvPrinter);
assertEquals("a,b,c,d,,f,", stringBuilder.toString());
diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv290Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv290Test.java
index e0ead70bf..c20c321a6 100644
--- a/src/test/java/org/apache/commons/csv/issues/JiraCsv290Test.java
+++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv290Test.java
@@ -94,7 +94,7 @@ public void testPostgresqlText() throws Exception {
@Test
public void testWriteThenRead() throws Exception {
final StringWriter sw = new StringWriter();
- final CSVFormat format = CSVFormat.POSTGRESQL_CSV.builder().setHeader().setSkipHeaderRecord(true).build();
+ final CSVFormat format = CSVFormat.POSTGRESQL_CSV.builder().setHeader().setSkipHeaderRecord(true).get();
try (CSVPrinter printer = new CSVPrinter(sw, format)) {
printer.printRecord("column1", "column2");
printer.printRecord("v11", "v12");
diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv294Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv294Test.java
index 3d13e4799..27d1d31d9 100644
--- a/src/test/java/org/apache/commons/csv/issues/JiraCsv294Test.java
+++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv294Test.java
@@ -58,23 +58,23 @@ private static void testInternal(final CSVFormat format, final String expectedSu
@Test
public void testDefaultCsvFormatWithBackslashEscapeWorks() throws IOException {
- testInternal(CSVFormat.Builder.create().setEscape('\\').build(), ",\"b \\\"\\\"\",");
+ testInternal(CSVFormat.Builder.create().setEscape('\\').get(), ",\"b \\\"\\\"\",");
}
@Test
public void testDefaultCsvFormatWithNullEscapeWorks() throws IOException {
- testInternal(CSVFormat.Builder.create().setEscape(null).build(), ",\"b \"\"\"\"\",");
+ testInternal(CSVFormat.Builder.create().setEscape(null).get(), ",\"b \"\"\"\"\",");
}
@Test
public void testDefaultCsvFormatWithQuoteEscapeWorks() throws IOException {
// this one doesn't actually work but should behave like setEscape(null)
// Printer is writing the expected content but Parser is unable to consume it
- testInternal(CSVFormat.Builder.create().setEscape('"').build(), ",\"b \"\"\"\"\",");
+ testInternal(CSVFormat.Builder.create().setEscape('"').get(), ",\"b \"\"\"\"\",");
}
@Test
public void testDefaultCsvFormatWorks() throws IOException {
- testInternal(CSVFormat.Builder.create().build(), ",\"b \"\"\"\"\",");
+ testInternal(CSVFormat.Builder.create().get(), ",\"b \"\"\"\"\",");
}
}
diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv93Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv93Test.java
index 5b62d9af4..4b6ad53ef 100644
--- a/src/test/java/org/apache/commons/csv/issues/JiraCsv93Test.java
+++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv93Test.java
@@ -65,23 +65,23 @@ public void testWithNotSetNullString() throws IOException {
objects1,
"abc,,,\"a,b,c\",123",
new String[]{"abc", "", "", "a,b,c", "123"});
- every(CSVFormat.DEFAULT.builder().setQuoteMode(QuoteMode.ALL).build(),
+ every(CSVFormat.DEFAULT.builder().setQuoteMode(QuoteMode.ALL).get(),
objects1,
"\"abc\",\"\",,\"a,b,c\",\"123\"",
new String[]{"abc", "", "", "a,b,c", "123"});
- every(CSVFormat.DEFAULT.builder().setQuoteMode(QuoteMode.ALL_NON_NULL).build(),
+ every(CSVFormat.DEFAULT.builder().setQuoteMode(QuoteMode.ALL_NON_NULL).get(),
objects1,
"\"abc\",\"\",,\"a,b,c\",\"123\"",
new String[]{"abc", "", null, "a,b,c", "123"});
- every(CSVFormat.DEFAULT.builder().setQuoteMode(QuoteMode.MINIMAL).build(),
+ every(CSVFormat.DEFAULT.builder().setQuoteMode(QuoteMode.MINIMAL).get(),
objects1,
"abc,,,\"a,b,c\",123",
new String[]{"abc", "", "", "a,b,c", "123"});
- every(CSVFormat.DEFAULT.builder().setEscape('?').setQuoteMode(QuoteMode.NONE).build(),
+ every(CSVFormat.DEFAULT.builder().setEscape('?').setQuoteMode(QuoteMode.NONE).get(),
objects1,
"abc,,,a?,b?,c,123",
new String[]{"abc", "", "", "a,b,c", "123"});
- every(CSVFormat.DEFAULT.builder().setQuoteMode(QuoteMode.NON_NUMERIC).build(),
+ every(CSVFormat.DEFAULT.builder().setQuoteMode(QuoteMode.NON_NUMERIC).get(),
objects1,
"\"abc\",\"\",,\"a,b,c\",123",
new String[]{"abc", "", null, "a,b,c", "123"});
@@ -91,27 +91,27 @@ public void testWithNotSetNullString() throws IOException {
@Test
public void testWithSetNullStringEmptyString() throws IOException {
// @formatter:off
- every(CSVFormat.DEFAULT.builder().setNullString("").build(),
+ every(CSVFormat.DEFAULT.builder().setNullString("").get(),
objects1,
"abc,,,\"a,b,c\",123",
new String[]{"abc", null, null, "a,b,c", "123"});
- every(CSVFormat.DEFAULT.builder().setNullString("").setQuoteMode(QuoteMode.ALL).build(),
+ every(CSVFormat.DEFAULT.builder().setNullString("").setQuoteMode(QuoteMode.ALL).get(),
objects1,
"\"abc\",\"\",\"\",\"a,b,c\",\"123\"",
new String[]{"abc", null, null, "a,b,c", "123"});
- every(CSVFormat.DEFAULT.builder().setNullString("").setQuoteMode(QuoteMode.ALL_NON_NULL).build(),
+ every(CSVFormat.DEFAULT.builder().setNullString("").setQuoteMode(QuoteMode.ALL_NON_NULL).get(),
objects1,
"\"abc\",\"\",,\"a,b,c\",\"123\"",
new String[]{"abc", "", null, "a,b,c", "123"});
- every(CSVFormat.DEFAULT.builder().setNullString("").setQuoteMode(QuoteMode.MINIMAL).build(),
+ every(CSVFormat.DEFAULT.builder().setNullString("").setQuoteMode(QuoteMode.MINIMAL).get(),
objects1,
"abc,,,\"a,b,c\",123",
new String[]{"abc", null, null, "a,b,c", "123"});
- every(CSVFormat.DEFAULT.builder().setNullString("").setEscape('?').setQuoteMode(QuoteMode.NONE).build(),
+ every(CSVFormat.DEFAULT.builder().setNullString("").setEscape('?').setQuoteMode(QuoteMode.NONE).get(),
objects1,
"abc,,,a?,b?,c,123",
new String[]{"abc", null, null, "a,b,c", "123"});
- every(CSVFormat.DEFAULT.builder().setNullString("").setQuoteMode(QuoteMode.NON_NUMERIC).build(),
+ every(CSVFormat.DEFAULT.builder().setNullString("").setQuoteMode(QuoteMode.NON_NUMERIC).get(),
objects1,
"\"abc\",\"\",,\"a,b,c\",123",
new String[]{"abc", "", null, "a,b,c", "123"});
@@ -121,27 +121,27 @@ public void testWithSetNullStringEmptyString() throws IOException {
@Test
public void testWithSetNullStringNULL() throws IOException {
// @formatter:off
- every(CSVFormat.DEFAULT.builder().setNullString("NULL").build(),
+ every(CSVFormat.DEFAULT.builder().setNullString("NULL").get(),
objects2,
"abc,NULL,NULL,\"a,b,c\",123",
new String[]{"abc", null, null, "a,b,c", "123"});
- every(CSVFormat.DEFAULT.builder().setNullString("NULL").setQuoteMode(QuoteMode.ALL).build(),
+ every(CSVFormat.DEFAULT.builder().setNullString("NULL").setQuoteMode(QuoteMode.ALL).get(),
objects2,
"\"abc\",\"NULL\",\"NULL\",\"a,b,c\",\"123\"",
new String[]{"abc", null, null, "a,b,c", "123"});
- every(CSVFormat.DEFAULT.builder().setNullString("NULL").setQuoteMode(QuoteMode.ALL_NON_NULL).build(),
+ every(CSVFormat.DEFAULT.builder().setNullString("NULL").setQuoteMode(QuoteMode.ALL_NON_NULL).get(),
objects2,
"\"abc\",\"NULL\",NULL,\"a,b,c\",\"123\"",
new String[]{"abc", "NULL", null, "a,b,c", "123"});
- every(CSVFormat.DEFAULT.builder().setNullString("NULL").setQuoteMode(QuoteMode.MINIMAL).build(),
+ every(CSVFormat.DEFAULT.builder().setNullString("NULL").setQuoteMode(QuoteMode.MINIMAL).get(),
objects2,
"abc,NULL,NULL,\"a,b,c\",123",
new String[]{"abc", null, null, "a,b,c", "123"});
- every(CSVFormat.DEFAULT.builder().setNullString("NULL").setEscape('?').setQuoteMode(QuoteMode.NONE).build(),
+ every(CSVFormat.DEFAULT.builder().setNullString("NULL").setEscape('?').setQuoteMode(QuoteMode.NONE).get(),
objects2,
"abc,NULL,NULL,a?,b?,c,123",
new String[]{"abc", null, null, "a,b,c", "123"});
- every(CSVFormat.DEFAULT.builder().setNullString("NULL").setQuoteMode(QuoteMode.NON_NUMERIC).build(),
+ every(CSVFormat.DEFAULT.builder().setNullString("NULL").setQuoteMode(QuoteMode.NON_NUMERIC).get(),
objects2,
"\"abc\",\"NULL\",NULL,\"a,b,c\",123",
new String[]{"abc", "NULL", null, "a,b,c", "123"});
diff --git a/src/test/java/org/apache/commons/csv/perf/PerformanceTest.java b/src/test/java/org/apache/commons/csv/perf/PerformanceTest.java
index ba9ef4991..f22911287 100644
--- a/src/test/java/org/apache/commons/csv/perf/PerformanceTest.java
+++ b/src/test/java/org/apache/commons/csv/perf/PerformanceTest.java
@@ -70,7 +70,7 @@ private BufferedReader createBufferedReader() throws IOException {
}
private long parse(final Reader reader, final boolean traverseColumns) throws IOException {
- final CSVFormat format = CSVFormat.DEFAULT.builder().setIgnoreSurroundingSpaces(false).build();
+ final CSVFormat format = CSVFormat.DEFAULT.builder().setIgnoreSurroundingSpaces(false).get();
long recordCount = 0;
try (final CSVParser parser = format.parse(reader)) {
for (final CSVRecord record : parser) {