Consistently rename Quote/QuotePolicy to QuoteMode
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1612344 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4695d73e3b
commit
a72c71f5cc
|
@ -148,7 +148,7 @@ public final class CSVFormat implements Serializable {
|
|||
|
||||
private final char delimiter;
|
||||
private final Character quoteChar; // null if quoting is disabled
|
||||
private final Quote quotePolicy;
|
||||
private final QuoteMode quoteMode;
|
||||
private final Character commentStart; // null if commenting is disabled
|
||||
private final Character escape; // null if escaping is disabled
|
||||
private final boolean ignoreSurroundingSpaces; // Should leading/trailing spaces be ignored around values?
|
||||
|
@ -313,8 +313,8 @@ public final class CSVFormat implements Serializable {
|
|||
* the char used for value separation, must not be a line break character
|
||||
* @param quoteChar
|
||||
* the Character used as value encapsulation marker, may be {@code null} to disable
|
||||
* @param quotePolicy
|
||||
* the quote policy
|
||||
* @param quoteMode
|
||||
* the quote mode
|
||||
* @param commentStart
|
||||
* the Character used for comment identification, may be {@code null} to disable
|
||||
* @param escape
|
||||
|
@ -334,7 +334,7 @@ public final class CSVFormat implements Serializable {
|
|||
* @throws IllegalArgumentException if the delimiter is a line break character
|
||||
*/
|
||||
private CSVFormat(final char delimiter, final Character quoteChar,
|
||||
final Quote quotePolicy, final Character commentStart,
|
||||
final QuoteMode quoteMode, final Character commentStart,
|
||||
final Character escape, final boolean ignoreSurroundingSpaces,
|
||||
final boolean ignoreEmptyLines, final String recordSeparator,
|
||||
final String nullString, final String[] header, final boolean skipHeaderRecord,
|
||||
|
@ -344,7 +344,7 @@ public final class CSVFormat implements Serializable {
|
|||
}
|
||||
this.delimiter = delimiter;
|
||||
this.quoteChar = quoteChar;
|
||||
this.quotePolicy = quotePolicy;
|
||||
this.quoteMode = quoteMode;
|
||||
this.commentStart = commentStart;
|
||||
this.escape = escape;
|
||||
this.ignoreSurroundingSpaces = ignoreSurroundingSpaces;
|
||||
|
@ -384,7 +384,7 @@ public final class CSVFormat implements Serializable {
|
|||
if (delimiter != other.delimiter) {
|
||||
return false;
|
||||
}
|
||||
if (quotePolicy != other.quotePolicy) {
|
||||
if (quoteMode != other.quoteMode) {
|
||||
return false;
|
||||
}
|
||||
if (quoteChar == null) {
|
||||
|
@ -552,8 +552,8 @@ public final class CSVFormat implements Serializable {
|
|||
*
|
||||
* @return the quote policy
|
||||
*/
|
||||
public Quote getQuotePolicy() {
|
||||
return quotePolicy;
|
||||
public QuoteMode getQuoteMode() {
|
||||
return quoteMode;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -581,7 +581,7 @@ public final class CSVFormat implements Serializable {
|
|||
int result = 1;
|
||||
|
||||
result = prime * result + delimiter;
|
||||
result = prime * result + ((quotePolicy == null) ? 0 : quotePolicy.hashCode());
|
||||
result = prime * result + ((quoteMode == null) ? 0 : quoteMode.hashCode());
|
||||
result = prime * result + ((quoteChar == null) ? 0 : quoteChar.hashCode());
|
||||
result = prime * result + ((commentStart == null) ? 0 : commentStart.hashCode());
|
||||
result = prime * result + ((escape == null) ? 0 : escape.hashCode());
|
||||
|
@ -735,7 +735,7 @@ public final class CSVFormat implements Serializable {
|
|||
"The comment start and the escape character cannot be the same ('" + commentStart + "')");
|
||||
}
|
||||
|
||||
if (escape == null && quotePolicy == Quote.NONE) {
|
||||
if (escape == null && quoteMode == QuoteMode.NONE) {
|
||||
throw new IllegalArgumentException("No quotes mode set but no escape character is set");
|
||||
}
|
||||
}
|
||||
|
@ -770,7 +770,7 @@ public final class CSVFormat implements Serializable {
|
|||
if (isLineBreak(commentMarker)) {
|
||||
throw new IllegalArgumentException("The comment start marker character cannot be a line break");
|
||||
}
|
||||
return new CSVFormat(delimiter, quoteChar, quotePolicy, commentMarker, escape,
|
||||
return new CSVFormat(delimiter, quoteChar, quoteMode, commentMarker, escape,
|
||||
ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, header, skipHeaderRecord,
|
||||
allowMissingColumnNames);
|
||||
}
|
||||
|
@ -788,7 +788,7 @@ public final class CSVFormat implements Serializable {
|
|||
if (isLineBreak(delimiter)) {
|
||||
throw new IllegalArgumentException("The delimiter cannot be a line break");
|
||||
}
|
||||
return new CSVFormat(delimiter, quoteChar, quotePolicy, commentStart, escape,
|
||||
return new CSVFormat(delimiter, quoteChar, quoteMode, commentStart, escape,
|
||||
ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, header, skipHeaderRecord,
|
||||
allowMissingColumnNames);
|
||||
}
|
||||
|
@ -819,7 +819,7 @@ public final class CSVFormat implements Serializable {
|
|||
if (isLineBreak(escape)) {
|
||||
throw new IllegalArgumentException("The escape character cannot be a line break");
|
||||
}
|
||||
return new CSVFormat(delimiter, quoteChar, quotePolicy, commentStart, escape,
|
||||
return new CSVFormat(delimiter, quoteChar, quoteMode, commentStart, escape,
|
||||
ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, header, skipHeaderRecord,
|
||||
allowMissingColumnNames);
|
||||
}
|
||||
|
@ -842,7 +842,7 @@ public final class CSVFormat implements Serializable {
|
|||
* @see #withSkipHeaderRecord(boolean)
|
||||
*/
|
||||
public CSVFormat withHeader(final String... header) {
|
||||
return new CSVFormat(delimiter, quoteChar, quotePolicy, commentStart, escape,
|
||||
return new CSVFormat(delimiter, quoteChar, quoteMode, commentStart, escape,
|
||||
ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, header, skipHeaderRecord,
|
||||
allowMissingColumnNames);
|
||||
}
|
||||
|
@ -856,7 +856,7 @@ public final class CSVFormat implements Serializable {
|
|||
* @return A new CSVFormat that is equal to this but with the specified missing column names behavior.
|
||||
*/
|
||||
public CSVFormat withAllowMissingColumnNames(final boolean allowMissingColumnNames) {
|
||||
return new CSVFormat(delimiter, quoteChar, quotePolicy, commentStart, escape,
|
||||
return new CSVFormat(delimiter, quoteChar, quoteMode, commentStart, escape,
|
||||
ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, header, skipHeaderRecord,
|
||||
allowMissingColumnNames);
|
||||
}
|
||||
|
@ -870,7 +870,7 @@ public final class CSVFormat implements Serializable {
|
|||
* @return A new CSVFormat that is equal to this but with the specified empty line skipping behavior.
|
||||
*/
|
||||
public CSVFormat withIgnoreEmptyLines(final boolean ignoreEmptyLines) {
|
||||
return new CSVFormat(delimiter, quoteChar, quotePolicy, commentStart, escape,
|
||||
return new CSVFormat(delimiter, quoteChar, quoteMode, commentStart, escape,
|
||||
ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, header, skipHeaderRecord,
|
||||
allowMissingColumnNames);
|
||||
}
|
||||
|
@ -884,7 +884,7 @@ public final class CSVFormat implements Serializable {
|
|||
* @return A new CSVFormat that is equal to this but with the specified trimming behavior.
|
||||
*/
|
||||
public CSVFormat withIgnoreSurroundingSpaces(final boolean ignoreSurroundingSpaces) {
|
||||
return new CSVFormat(delimiter, quoteChar, quotePolicy, commentStart, escape,
|
||||
return new CSVFormat(delimiter, quoteChar, quoteMode, commentStart, escape,
|
||||
ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, header, skipHeaderRecord,
|
||||
allowMissingColumnNames);
|
||||
}
|
||||
|
@ -905,7 +905,7 @@ public final class CSVFormat implements Serializable {
|
|||
* @return A new CSVFormat that is equal to this but with the specified null conversion string.
|
||||
*/
|
||||
public CSVFormat withNullString(final String nullString) {
|
||||
return new CSVFormat(delimiter, quoteChar, quotePolicy, commentStart, escape,
|
||||
return new CSVFormat(delimiter, quoteChar, quoteMode, commentStart, escape,
|
||||
ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, header, skipHeaderRecord,
|
||||
allowMissingColumnNames);
|
||||
}
|
||||
|
@ -936,7 +936,7 @@ public final class CSVFormat implements Serializable {
|
|||
if (isLineBreak(quoteChar)) {
|
||||
throw new IllegalArgumentException("The quoteChar cannot be a line break");
|
||||
}
|
||||
return new CSVFormat(delimiter, quoteChar, quotePolicy, commentStart, escape,
|
||||
return new CSVFormat(delimiter, quoteChar, quoteMode, commentStart, escape,
|
||||
ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, header, skipHeaderRecord,
|
||||
allowMissingColumnNames);
|
||||
}
|
||||
|
@ -944,13 +944,13 @@ public final class CSVFormat implements Serializable {
|
|||
/**
|
||||
* Sets the output quote policy of the format to the specified value.
|
||||
*
|
||||
* @param quotePolicy
|
||||
* @param quoteModePolicy
|
||||
* the quote policy to use for output.
|
||||
*
|
||||
* @return A new CSVFormat that is equal to this but with the specified quote policy
|
||||
*/
|
||||
public CSVFormat withQuotePolicy(final Quote quotePolicy) {
|
||||
return new CSVFormat(delimiter, quoteChar, quotePolicy, commentStart, escape,
|
||||
public CSVFormat withQuoteMode(final QuoteMode quoteModePolicy) {
|
||||
return new CSVFormat(delimiter, quoteChar, quoteModePolicy, commentStart, escape,
|
||||
ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, header, skipHeaderRecord,
|
||||
allowMissingColumnNames);
|
||||
}
|
||||
|
@ -984,7 +984,7 @@ public final class CSVFormat implements Serializable {
|
|||
* if recordSeparator is none of CR, LF or CRLF
|
||||
*/
|
||||
public CSVFormat withRecordSeparator(final String recordSeparator) {
|
||||
return new CSVFormat(delimiter, quoteChar, quotePolicy, commentStart, escape,
|
||||
return new CSVFormat(delimiter, quoteChar, quoteMode, commentStart, escape,
|
||||
ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, header, skipHeaderRecord,
|
||||
allowMissingColumnNames);
|
||||
}
|
||||
|
@ -999,7 +999,7 @@ public final class CSVFormat implements Serializable {
|
|||
* @see #withHeader(String...)
|
||||
*/
|
||||
public CSVFormat withSkipHeaderRecord(final boolean skipHeaderRecord) {
|
||||
return new CSVFormat(delimiter, quoteChar, quotePolicy, commentStart, escape,
|
||||
return new CSVFormat(delimiter, quoteChar, quoteMode, commentStart, escape,
|
||||
ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, header, skipHeaderRecord,
|
||||
allowMissingColumnNames);
|
||||
}
|
||||
|
|
|
@ -182,11 +182,11 @@ public final class CSVPrinter implements Flushable, Closeable {
|
|||
final char delimChar = format.getDelimiter();
|
||||
final char quoteChar = format.getQuoteChar().charValue();
|
||||
|
||||
Quote quotePolicy = format.getQuotePolicy();
|
||||
if (quotePolicy == null) {
|
||||
quotePolicy = Quote.MINIMAL;
|
||||
QuoteMode quoteModePolicy = format.getQuoteMode();
|
||||
if (quoteModePolicy == null) {
|
||||
quoteModePolicy = QuoteMode.MINIMAL;
|
||||
}
|
||||
switch (quotePolicy) {
|
||||
switch (quoteModePolicy) {
|
||||
case ALL:
|
||||
quote = true;
|
||||
break;
|
||||
|
@ -248,7 +248,7 @@ public final class CSVPrinter implements Flushable, Closeable {
|
|||
}
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Unexpected Quote value: " + quotePolicy);
|
||||
throw new IllegalStateException("Unexpected Quote value: " + quoteModePolicy);
|
||||
}
|
||||
|
||||
if (!quote) {
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.apache.commons.csv;
|
|||
*
|
||||
* @version $Id$
|
||||
*/
|
||||
public enum Quote {
|
||||
public enum QuoteMode {
|
||||
|
||||
/**
|
||||
* Quotes all fields.
|
|
@ -88,7 +88,7 @@ public class CSVFormatTest {
|
|||
final CSVFormat right = CSVFormat.newFormat('\'')
|
||||
.withQuoteChar('"')
|
||||
.withCommentMarker('#')
|
||||
.withQuotePolicy(Quote.ALL);
|
||||
.withQuoteMode(QuoteMode.ALL);
|
||||
final CSVFormat left = right
|
||||
.withCommentMarker('!');
|
||||
|
||||
|
@ -109,7 +109,7 @@ public class CSVFormatTest {
|
|||
.withQuoteChar('"')
|
||||
.withCommentMarker('#')
|
||||
.withEscape('+')
|
||||
.withQuotePolicy(Quote.ALL);
|
||||
.withQuoteMode(QuoteMode.ALL);
|
||||
final CSVFormat left = right
|
||||
.withEscape('!');
|
||||
|
||||
|
@ -126,7 +126,7 @@ public class CSVFormatTest {
|
|||
.withIgnoreEmptyLines(true)
|
||||
.withIgnoreSurroundingSpaces(true)
|
||||
.withQuoteChar('"')
|
||||
.withQuotePolicy(Quote.ALL);
|
||||
.withQuoteMode(QuoteMode.ALL);
|
||||
final CSVFormat left = right
|
||||
.withHeader("Three", "Two", "One");
|
||||
|
||||
|
@ -141,7 +141,7 @@ public class CSVFormatTest {
|
|||
.withIgnoreEmptyLines(true)
|
||||
.withIgnoreSurroundingSpaces(true)
|
||||
.withQuoteChar('"')
|
||||
.withQuotePolicy(Quote.ALL);
|
||||
.withQuoteMode(QuoteMode.ALL);
|
||||
final CSVFormat left = right
|
||||
.withIgnoreEmptyLines(false);
|
||||
|
||||
|
@ -155,7 +155,7 @@ public class CSVFormatTest {
|
|||
.withEscape('+')
|
||||
.withIgnoreSurroundingSpaces(true)
|
||||
.withQuoteChar('"')
|
||||
.withQuotePolicy(Quote.ALL);
|
||||
.withQuoteMode(QuoteMode.ALL);
|
||||
final CSVFormat left = right
|
||||
.withIgnoreSurroundingSpaces(false);
|
||||
|
||||
|
@ -174,9 +174,9 @@ public class CSVFormatTest {
|
|||
public void testEqualsQuotePolicy() {
|
||||
final CSVFormat right = CSVFormat.newFormat('\'')
|
||||
.withQuoteChar('"')
|
||||
.withQuotePolicy(Quote.ALL);
|
||||
.withQuoteMode(QuoteMode.ALL);
|
||||
final CSVFormat left = right
|
||||
.withQuotePolicy(Quote.MINIMAL);
|
||||
.withQuoteMode(QuoteMode.MINIMAL);
|
||||
|
||||
assertNotEquals(right, left);
|
||||
}
|
||||
|
@ -190,7 +190,7 @@ public class CSVFormatTest {
|
|||
.withIgnoreEmptyLines(true)
|
||||
.withIgnoreSurroundingSpaces(true)
|
||||
.withQuoteChar('"')
|
||||
.withQuotePolicy(Quote.ALL);
|
||||
.withQuoteMode(QuoteMode.ALL);
|
||||
final CSVFormat left = right
|
||||
.withRecordSeparator(LF);
|
||||
|
||||
|
@ -206,7 +206,7 @@ public class CSVFormatTest {
|
|||
.withIgnoreEmptyLines(true)
|
||||
.withIgnoreSurroundingSpaces(true)
|
||||
.withQuoteChar('"')
|
||||
.withQuotePolicy(Quote.ALL)
|
||||
.withQuoteMode(QuoteMode.ALL)
|
||||
.withNullString("null");
|
||||
final CSVFormat left = right
|
||||
.withNullString("---");
|
||||
|
@ -223,7 +223,7 @@ public class CSVFormatTest {
|
|||
.withIgnoreEmptyLines(true)
|
||||
.withIgnoreSurroundingSpaces(true)
|
||||
.withQuoteChar('"')
|
||||
.withQuotePolicy(Quote.ALL)
|
||||
.withQuoteMode(QuoteMode.ALL)
|
||||
.withNullString("null")
|
||||
.withSkipHeaderRecord(true);
|
||||
final CSVFormat left = right
|
||||
|
@ -291,7 +291,7 @@ public class CSVFormatTest {
|
|||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testQuotePolicyNoneWithoutEscapeThrowsException() {
|
||||
CSVFormat.newFormat('!').withQuotePolicy(Quote.NONE);
|
||||
CSVFormat.newFormat('!').withQuoteMode(QuoteMode.NONE);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -301,7 +301,7 @@ public class CSVFormatTest {
|
|||
assertEquals(null, RFC4180.getEscape());
|
||||
assertFalse(RFC4180.getIgnoreEmptyLines());
|
||||
assertEquals(Character.valueOf('"'), RFC4180.getQuoteChar());
|
||||
assertEquals(null, RFC4180.getQuotePolicy());
|
||||
assertEquals(null, RFC4180.getQuoteMode());
|
||||
assertEquals("\r\n", RFC4180.getRecordSeparator());
|
||||
}
|
||||
|
||||
|
@ -405,8 +405,8 @@ public class CSVFormatTest {
|
|||
|
||||
@Test
|
||||
public void testWithQuotePolicy() throws Exception {
|
||||
final CSVFormat formatWithQuotePolicy = CSVFormat.DEFAULT.withQuotePolicy(Quote.ALL);
|
||||
assertEquals(Quote.ALL, formatWithQuotePolicy.getQuotePolicy());
|
||||
final CSVFormat formatWithQuotePolicy = CSVFormat.DEFAULT.withQuoteMode(QuoteMode.ALL);
|
||||
assertEquals(QuoteMode.ALL, formatWithQuotePolicy.getQuoteMode());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -352,7 +352,7 @@ public class CSVPrinterTest {
|
|||
@Test
|
||||
public void testQuoteAll() throws IOException {
|
||||
final StringWriter sw = new StringWriter();
|
||||
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuotePolicy(Quote.ALL));
|
||||
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuoteMode(QuoteMode.ALL));
|
||||
printer.printRecord("a", "b\nc", "d");
|
||||
assertEquals("\"a\",\"b\nc\",\"d\"" + recordSeparator, sw.toString());
|
||||
printer.close();
|
||||
|
@ -361,7 +361,7 @@ public class CSVPrinterTest {
|
|||
@Test
|
||||
public void testQuoteNonNumeric() throws IOException {
|
||||
final StringWriter sw = new StringWriter();
|
||||
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuotePolicy(Quote.NON_NUMERIC));
|
||||
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withQuoteMode(QuoteMode.NON_NUMERIC));
|
||||
printer.printRecord("a", "b\nc", Integer.valueOf(1));
|
||||
assertEquals("\"a\",\"b\nc\",1" + recordSeparator, sw.toString());
|
||||
printer.close();
|
||||
|
@ -417,7 +417,7 @@ public class CSVPrinterTest {
|
|||
@Test
|
||||
public void testDelimeterQuoteNONE() throws IOException {
|
||||
final StringWriter sw = new StringWriter();
|
||||
final CSVFormat format = CSVFormat.DEFAULT.withEscape('!').withQuotePolicy(Quote.NONE);
|
||||
final CSVFormat format = CSVFormat.DEFAULT.withEscape('!').withQuoteMode(QuoteMode.NONE);
|
||||
final CSVPrinter printer = new CSVPrinter(sw, format);
|
||||
printer.print("a,b,c");
|
||||
printer.print("xyz");
|
||||
|
|
Loading…
Reference in New Issue