Rename withCommentStart to withCommentMarker to avoid confusion because there is no corresponding withCommentStop method

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1610494 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Benedikt Ritter 2014-07-14 19:34:56 +00:00
parent bb54feb7cd
commit 040c2606eb
6 changed files with 34 additions and 34 deletions

View File

@ -745,14 +745,14 @@ public final class CSVFormat implements Serializable {
* *
* Note that the comment start character is only recognized at the start of a line. * Note that the comment start character is only recognized at the start of a line.
* *
* @param commentStart * @param commentMarker
* the comment start marker * the comment start marker
* @return A new CSVFormat that is equal to this one but with the specified character as the comment start marker * @return A new CSVFormat that is equal to this one but with the specified character as the comment start marker
* @throws IllegalArgumentException * @throws IllegalArgumentException
* thrown if the specified character is a line break * thrown if the specified character is a line break
*/ */
public CSVFormat withCommentStart(final char commentStart) { public CSVFormat withCommentMarker(final char commentMarker) {
return withCommentStart(Character.valueOf(commentStart)); return withCommentMarker(Character.valueOf(commentMarker));
} }
/** /**
@ -760,17 +760,17 @@ public final class CSVFormat implements Serializable {
* *
* Note that the comment start character is only recognized at the start of a line. * Note that the comment start character is only recognized at the start of a line.
* *
* @param commentStart * @param commentMarker
* the comment start marker, use {@code null} to disable * the comment start marker, use {@code null} to disable
* @return A new CSVFormat that is equal to this one but with the specified character as the comment start marker * @return A new CSVFormat that is equal to this one but with the specified character as the comment start marker
* @throws IllegalArgumentException * @throws IllegalArgumentException
* thrown if the specified character is a line break * thrown if the specified character is a line break
*/ */
public CSVFormat withCommentStart(final Character commentStart) { public CSVFormat withCommentMarker(final Character commentMarker) {
if (isLineBreak(commentStart)) { if (isLineBreak(commentMarker)) {
throw new IllegalArgumentException("The comment start character cannot be a line break"); throw new IllegalArgumentException("The comment start marker character cannot be a line break");
} }
return new CSVFormat(delimiter, quoteChar, quotePolicy, commentStart, escape, return new CSVFormat(delimiter, quoteChar, quotePolicy, commentMarker, escape,
ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, header, skipHeaderRecord, ignoreSurroundingSpaces, ignoreEmptyLines, recordSeparator, nullString, header, skipHeaderRecord,
ignoreEmptyHeaders); ignoreEmptyHeaders);
} }

View File

@ -100,7 +100,7 @@ public class CSVFileParserTest {
} else if ("IgnoreSpaces".equalsIgnoreCase(option_parts[0])) { } else if ("IgnoreSpaces".equalsIgnoreCase(option_parts[0])) {
format = format.withIgnoreSurroundingSpaces(Boolean.parseBoolean(option_parts[1])); format = format.withIgnoreSurroundingSpaces(Boolean.parseBoolean(option_parts[1]));
} else if ("CommentStart".equalsIgnoreCase(option_parts[0])) { } else if ("CommentStart".equalsIgnoreCase(option_parts[0])) {
format = format.withCommentStart(option_parts[1].charAt(0)); format = format.withCommentMarker(option_parts[1].charAt(0));
} else if ("CheckComments".equalsIgnoreCase(option_parts[0])) { } else if ("CheckComments".equalsIgnoreCase(option_parts[0])) {
checkComments = true; checkComments = true;
} else { } else {
@ -144,7 +144,7 @@ public class CSVFileParserTest {
} else if ("IgnoreSpaces".equalsIgnoreCase(option_parts[0])) { } else if ("IgnoreSpaces".equalsIgnoreCase(option_parts[0])) {
format = format.withIgnoreSurroundingSpaces(Boolean.parseBoolean(option_parts[1])); format = format.withIgnoreSurroundingSpaces(Boolean.parseBoolean(option_parts[1]));
} else if ("CommentStart".equalsIgnoreCase(option_parts[0])) { } else if ("CommentStart".equalsIgnoreCase(option_parts[0])) {
format = format.withCommentStart(option_parts[1].charAt(0)); format = format.withCommentMarker(option_parts[1].charAt(0));
} else if ("CheckComments".equalsIgnoreCase(option_parts[0])) { } else if ("CheckComments".equalsIgnoreCase(option_parts[0])) {
checkComments = true; checkComments = true;
} else { } else {

View File

@ -54,7 +54,7 @@ public class CSVFormatTest {
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void testDelimiterSameAsCommentStartThrowsException() { public void testDelimiterSameAsCommentStartThrowsException() {
CSVFormat.DEFAULT.withDelimiter('!').withCommentStart('!'); CSVFormat.DEFAULT.withDelimiter('!').withCommentMarker('!');
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
@ -87,10 +87,10 @@ public class CSVFormatTest {
public void testEqualsCommentStart() { public void testEqualsCommentStart() {
final CSVFormat right = CSVFormat.newFormat('\'') final CSVFormat right = CSVFormat.newFormat('\'')
.withQuoteChar('"') .withQuoteChar('"')
.withCommentStart('#') .withCommentMarker('#')
.withQuotePolicy(Quote.ALL); .withQuotePolicy(Quote.ALL);
final CSVFormat left = right final CSVFormat left = right
.withCommentStart('!'); .withCommentMarker('!');
assertNotEquals(right, left); assertNotEquals(right, left);
} }
@ -107,7 +107,7 @@ public class CSVFormatTest {
public void testEqualsEscape() { public void testEqualsEscape() {
final CSVFormat right = CSVFormat.newFormat('\'') final CSVFormat right = CSVFormat.newFormat('\'')
.withQuoteChar('"') .withQuoteChar('"')
.withCommentStart('#') .withCommentMarker('#')
.withEscape('+') .withEscape('+')
.withQuotePolicy(Quote.ALL); .withQuotePolicy(Quote.ALL);
final CSVFormat left = right final CSVFormat left = right
@ -120,7 +120,7 @@ public class CSVFormatTest {
public void testEqualsHeader() { public void testEqualsHeader() {
final CSVFormat right = CSVFormat.newFormat('\'') final CSVFormat right = CSVFormat.newFormat('\'')
.withRecordSeparator(CR) .withRecordSeparator(CR)
.withCommentStart('#') .withCommentMarker('#')
.withEscape('+') .withEscape('+')
.withHeader("One", "Two", "Three") .withHeader("One", "Two", "Three")
.withIgnoreEmptyLines(true) .withIgnoreEmptyLines(true)
@ -136,7 +136,7 @@ public class CSVFormatTest {
@Test @Test
public void testEqualsIgnoreEmptyLines() { public void testEqualsIgnoreEmptyLines() {
final CSVFormat right = CSVFormat.newFormat('\'') final CSVFormat right = CSVFormat.newFormat('\'')
.withCommentStart('#') .withCommentMarker('#')
.withEscape('+') .withEscape('+')
.withIgnoreEmptyLines(true) .withIgnoreEmptyLines(true)
.withIgnoreSurroundingSpaces(true) .withIgnoreSurroundingSpaces(true)
@ -151,7 +151,7 @@ public class CSVFormatTest {
@Test @Test
public void testEqualsIgnoreSurroundingSpaces() { public void testEqualsIgnoreSurroundingSpaces() {
final CSVFormat right = CSVFormat.newFormat('\'') final CSVFormat right = CSVFormat.newFormat('\'')
.withCommentStart('#') .withCommentMarker('#')
.withEscape('+') .withEscape('+')
.withIgnoreSurroundingSpaces(true) .withIgnoreSurroundingSpaces(true)
.withQuoteChar('"') .withQuoteChar('"')
@ -185,7 +185,7 @@ public class CSVFormatTest {
public void testEqualsRecordSeparator() { public void testEqualsRecordSeparator() {
final CSVFormat right = CSVFormat.newFormat('\'') final CSVFormat right = CSVFormat.newFormat('\'')
.withRecordSeparator(CR) .withRecordSeparator(CR)
.withCommentStart('#') .withCommentMarker('#')
.withEscape('+') .withEscape('+')
.withIgnoreEmptyLines(true) .withIgnoreEmptyLines(true)
.withIgnoreSurroundingSpaces(true) .withIgnoreSurroundingSpaces(true)
@ -201,7 +201,7 @@ public class CSVFormatTest {
public void testEqualsNullString() { public void testEqualsNullString() {
final CSVFormat right = CSVFormat.newFormat('\'') final CSVFormat right = CSVFormat.newFormat('\'')
.withRecordSeparator(CR) .withRecordSeparator(CR)
.withCommentStart('#') .withCommentMarker('#')
.withEscape('+') .withEscape('+')
.withIgnoreEmptyLines(true) .withIgnoreEmptyLines(true)
.withIgnoreSurroundingSpaces(true) .withIgnoreSurroundingSpaces(true)
@ -218,7 +218,7 @@ public class CSVFormatTest {
public void testEqualsSkipHeaderRecord() { public void testEqualsSkipHeaderRecord() {
final CSVFormat right = CSVFormat.newFormat('\'') final CSVFormat right = CSVFormat.newFormat('\'')
.withRecordSeparator(CR) .withRecordSeparator(CR)
.withCommentStart('#') .withCommentMarker('#')
.withEscape('+') .withEscape('+')
.withIgnoreEmptyLines(true) .withIgnoreEmptyLines(true)
.withIgnoreSurroundingSpaces(true) .withIgnoreSurroundingSpaces(true)
@ -234,13 +234,13 @@ public class CSVFormatTest {
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void testEscapeSameAsCommentStartThrowsException() { public void testEscapeSameAsCommentStartThrowsException() {
CSVFormat.DEFAULT.withEscape('!').withCommentStart('!'); CSVFormat.DEFAULT.withEscape('!').withCommentMarker('!');
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void testEscapeSameAsCommentStartThrowsExceptionForWrapperType() { public void testEscapeSameAsCommentStartThrowsExceptionForWrapperType() {
// Cannot assume that callers won't use different Character objects // Cannot assume that callers won't use different Character objects
CSVFormat.DEFAULT.withEscape(new Character('!')).withCommentStart(new Character('!')); CSVFormat.DEFAULT.withEscape(new Character('!')).withCommentMarker(new Character('!'));
} }
@Test @Test
@ -275,13 +275,13 @@ public class CSVFormatTest {
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void testQuoteCharSameAsCommentStartThrowsException() { public void testQuoteCharSameAsCommentStartThrowsException() {
CSVFormat.DEFAULT.withQuoteChar('!').withCommentStart('!'); CSVFormat.DEFAULT.withQuoteChar('!').withCommentMarker('!');
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void testQuoteCharSameAsCommentStartThrowsExceptionForWrapperType() { public void testQuoteCharSameAsCommentStartThrowsExceptionForWrapperType() {
// Cannot assume that callers won't use different Character objects // Cannot assume that callers won't use different Character objects
CSVFormat.DEFAULT.withQuoteChar(new Character('!')).withCommentStart('!'); CSVFormat.DEFAULT.withQuoteChar(new Character('!')).withCommentMarker('!');
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
@ -330,13 +330,13 @@ public class CSVFormatTest {
@Test @Test
public void testWithCommentStart() throws Exception { public void testWithCommentStart() throws Exception {
final CSVFormat formatWithCommentStart = CSVFormat.DEFAULT.withCommentStart('#'); final CSVFormat formatWithCommentStart = CSVFormat.DEFAULT.withCommentMarker('#');
assertEquals( Character.valueOf('#'), formatWithCommentStart.getCommentStart()); assertEquals( Character.valueOf('#'), formatWithCommentStart.getCommentStart());
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
public void testWithCommentStartCRThrowsException() { public void testWithCommentStartCRThrowsException() {
CSVFormat.DEFAULT.withCommentStart(CR); CSVFormat.DEFAULT.withCommentMarker(CR);
} }
@Test @Test

View File

@ -242,7 +242,7 @@ public class CSVParserTest {
@Test(expected = NoSuchElementException.class) @Test(expected = NoSuchElementException.class)
public void testClose() throws Exception { public void testClose() throws Exception {
final Reader in = new StringReader("# comment\na,b,c\n1,2,3\nx,y,z"); final Reader in = new StringReader("# comment\na,b,c\n1,2,3\nx,y,z");
final CSVParser parser = CSVFormat.DEFAULT.withCommentStart('#').withHeader().parse(in); final CSVParser parser = CSVFormat.DEFAULT.withCommentMarker('#').withHeader().parse(in);
final Iterator<CSVRecord> records = parser.iterator(); final Iterator<CSVRecord> records = parser.iterator();
assertTrue(records.hasNext()); assertTrue(records.hasNext());
parser.close(); parser.close();
@ -288,7 +288,7 @@ public class CSVParserTest {
{"\n", " ", "#"}, {"\n", " ", "#"},
}; };
format = CSVFormat.DEFAULT.withCommentStart('#'); format = CSVFormat.DEFAULT.withCommentMarker('#');
parser.close(); parser.close();
parser = CSVParser.parse(code, format); parser = CSVParser.parse(code, format);
records = parser.getRecords(); records = parser.getRecords();
@ -671,7 +671,7 @@ public class CSVParserTest {
public void testHeaderComment() throws Exception { public void testHeaderComment() throws Exception {
final Reader in = new StringReader("# comment\na,b,c\n1,2,3\nx,y,z"); final Reader in = new StringReader("# comment\na,b,c\n1,2,3\nx,y,z");
final Iterator<CSVRecord> records = CSVFormat.DEFAULT.withCommentStart('#').withHeader().parse(in).iterator(); final Iterator<CSVRecord> records = CSVFormat.DEFAULT.withCommentMarker('#').withHeader().parse(in).iterator();
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
assertTrue(records.hasNext()); assertTrue(records.hasNext());

View File

@ -233,7 +233,7 @@ public class CSVPrinterTest {
@Test @Test
public void testMultiLineComment() throws IOException { public void testMultiLineComment() throws IOException {
final StringWriter sw = new StringWriter(); final StringWriter sw = new StringWriter();
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withCommentStart('#')); final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withCommentMarker('#'));
printer.printComment("This is a comment\non multiple lines"); printer.printComment("This is a comment\non multiple lines");
assertEquals("# This is a comment" + recordSeparator + "# on multiple lines" + recordSeparator, sw.toString()); assertEquals("# This is a comment" + recordSeparator + "# on multiple lines" + recordSeparator, sw.toString());
@ -387,7 +387,7 @@ public class CSVPrinterTest {
@Test @Test
public void testSingleLineComment() throws IOException { public void testSingleLineComment() throws IOException {
final StringWriter sw = new StringWriter(); final StringWriter sw = new StringWriter();
final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withCommentStart('#')); final CSVPrinter printer = new CSVPrinter(sw, CSVFormat.DEFAULT.withCommentMarker('#'));
printer.printComment("This is a comment"); printer.printComment("This is a comment");
assertEquals("# This is a comment" + recordSeparator, sw.toString()); assertEquals("# This is a comment" + recordSeparator, sw.toString());

View File

@ -122,7 +122,7 @@ public class LexerTest {
"third,line,#no-comment\n"+ "third,line,#no-comment\n"+
"# penultimate comment\n"+ "# penultimate comment\n"+
"# Final comment\n"; "# Final comment\n";
final CSVFormat format = CSVFormat.DEFAULT.withCommentStart('#'); final CSVFormat format = CSVFormat.DEFAULT.withCommentMarker('#');
final Lexer parser = getLexer(code, format); final Lexer parser = getLexer(code, format);
assertThat(parser.nextToken(new Token()), matches(TOKEN, "first")); assertThat(parser.nextToken(new Token()), matches(TOKEN, "first"));
@ -158,7 +158,7 @@ public class LexerTest {
"\n"+ // 6b "\n"+ // 6b
"\n"+ // 6c "\n"+ // 6c
"# Final comment\n"; // 7 "# Final comment\n"; // 7
final CSVFormat format = CSVFormat.DEFAULT.withCommentStart('#').withIgnoreEmptyLines(false); final CSVFormat format = CSVFormat.DEFAULT.withCommentMarker('#').withIgnoreEmptyLines(false);
assertFalse("Should not ignore empty lines", format.isIgnoringEmptyLines()); assertFalse("Should not ignore empty lines", format.isIgnoringEmptyLines());
final Lexer parser = getLexer(code, format); final Lexer parser = getLexer(code, format);
@ -279,7 +279,7 @@ public class LexerTest {
* ;; * ;;
*/ */
final String code = "a;'b and '' more\n'\n!comment;;;;\n;;"; final String code = "a;'b and '' more\n'\n!comment;;;;\n;;";
final CSVFormat format = CSVFormat.DEFAULT.withQuoteChar('\'').withCommentStart('!').withDelimiter(';'); final CSVFormat format = CSVFormat.DEFAULT.withQuoteChar('\'').withCommentMarker('!').withDelimiter(';');
final Lexer parser = getLexer(code, format); final Lexer parser = getLexer(code, format);
assertThat(parser.nextToken(new Token()), matches(TOKEN, "a")); assertThat(parser.nextToken(new Token()), matches(TOKEN, "a"));
assertThat(parser.nextToken(new Token()), matches(EORECORD, "b and ' more\n")); assertThat(parser.nextToken(new Token()), matches(EORECORD, "b and ' more\n"));