Rename readAgain() to getLastChar()

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1397911 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Gary D. Gregory 2012-10-13 17:40:05 +00:00
parent f342cb2caf
commit 9f6d3f5413
6 changed files with 28 additions and 28 deletions

View File

@ -47,7 +47,7 @@ final class CSVLexer extends Lexer {
Token nextToken(final Token token) throws IOException { Token nextToken(final Token token) throws IOException {
// get the last read char (required for empty line detection) // get the last read char (required for empty line detection)
int lastChar = in.readAgain(); int lastChar = in.getLastChar();
// read the next char and set eol // read the next char and set eol
int c = in.read(); int c = in.read();

View File

@ -65,7 +65,7 @@ final class ExtendedBufferedReader extends BufferedReader {
* *
* @return the last character that was read * @return the last character that was read
*/ */
int readAgain() { int getLastChar() {
return lastChar; return lastChar;
} }

View File

@ -47,7 +47,7 @@ class CSVLexer1 extends Lexer {
wsBuf.setLength(0); // reuse wsBuf.setLength(0); // reuse
// get the last read char (required for empty line detection) // get the last read char (required for empty line detection)
int lastChar = in.readAgain(); int lastChar = in.getLastChar();
// read the next char and set eol // read the next char and set eol
/* note: unfortunately isEndOfLine may consumes a character silently. /* note: unfortunately isEndOfLine may consumes a character silently.
@ -56,7 +56,7 @@ class CSVLexer1 extends Lexer {
*/ */
int c = in.read(); int c = in.read();
boolean eol = isEndOfLine(c); boolean eol = isEndOfLine(c);
c = in.readAgain(); c = in.getLastChar();
// empty line detection: eol AND (last char was EOL or beginning) // empty line detection: eol AND (last char was EOL or beginning)
if (format.getIgnoreEmptyLines()) { if (format.getIgnoreEmptyLines()) {
@ -67,7 +67,7 @@ class CSVLexer1 extends Lexer {
lastChar = c; lastChar = c;
c = in.read(); c = in.read();
eol = isEndOfLine(c); eol = isEndOfLine(c);
c = in.readAgain(); c = in.getLastChar();
// reached end of file without any content (empty line at the end) // reached end of file without any content (empty line at the end)
if (isEndOfFile(c)) { if (isEndOfFile(c)) {
tkn.type = EOF; tkn.type = EOF;

View File

@ -45,7 +45,7 @@ class CSVLexer1306663 extends Lexer {
Token nextToken(final Token tkn) throws IOException { Token nextToken(final Token tkn) throws IOException {
// get the last read char (required for empty line detection) // get the last read char (required for empty line detection)
int lastChar = in.readAgain(); int lastChar = in.getLastChar();
// read the next char and set eol // read the next char and set eol
int c = in.read(); int c = in.read();
@ -61,7 +61,7 @@ class CSVLexer1306663 extends Lexer {
* is to call 'readAgain' on the stream... * is to call 'readAgain' on the stream...
*/ */
boolean eol = isEndOfLine(c); boolean eol = isEndOfLine(c);
c = in.readAgain(); c = in.getLastChar();
// empty line detection: eol AND (last char was EOL or beginning) // empty line detection: eol AND (last char was EOL or beginning)
if (ignoreEmptyLines) { if (ignoreEmptyLines) {
@ -70,7 +70,7 @@ class CSVLexer1306663 extends Lexer {
lastChar = c; lastChar = c;
c = in.read(); c = in.read();
eol = isEndOfLine(c); eol = isEndOfLine(c);
c = in.readAgain(); c = in.getLastChar();
// reached end of file without any content (empty line at the end) // reached end of file without any content (empty line at the end)
if (isEndOfFile(c)) { if (isEndOfFile(c)) {
tkn.type = EOF; tkn.type = EOF;

View File

@ -45,7 +45,7 @@ class CSVLexer1306667 extends Lexer {
Token nextToken(final Token tkn) throws IOException { Token nextToken(final Token tkn) throws IOException {
// get the last read char (required for empty line detection) // get the last read char (required for empty line detection)
int lastChar = in.readAgain(); int lastChar = in.getLastChar();
// read the next char and set eol // read the next char and set eol
int c = in.read(); int c = in.read();
@ -55,7 +55,7 @@ class CSVLexer1306667 extends Lexer {
* is to call 'readAgain' on the stream... * is to call 'readAgain' on the stream...
*/ */
boolean eol = isEndOfLine(c); boolean eol = isEndOfLine(c);
c = in.readAgain(); c = in.getLastChar();
// empty line detection: eol AND (last char was EOL or beginning) // empty line detection: eol AND (last char was EOL or beginning)
if (ignoreEmptyLines) { if (ignoreEmptyLines) {
@ -64,7 +64,7 @@ class CSVLexer1306667 extends Lexer {
lastChar = c; lastChar = c;
c = in.read(); c = in.read();
eol = isEndOfLine(c); eol = isEndOfLine(c);
c = in.readAgain(); c = in.getLastChar();
// reached end of file without any content (empty line at the end) // reached end of file without any content (empty line at the end)
if (isEndOfFile(c)) { if (isEndOfFile(c)) {
tkn.type = EOF; tkn.type = EOF;

View File

@ -34,7 +34,7 @@ public class ExtendedBufferedReaderTest {
final ExtendedBufferedReader br = getBufferedReader(""); final ExtendedBufferedReader br = getBufferedReader("");
assertEquals(END_OF_STREAM, br.read()); assertEquals(END_OF_STREAM, br.read());
assertEquals(END_OF_STREAM, br.lookAhead()); assertEquals(END_OF_STREAM, br.lookAhead());
assertEquals(END_OF_STREAM, br.readAgain()); assertEquals(END_OF_STREAM, br.getLastChar());
assertNull(br.readLine()); assertNull(br.readLine());
assertEquals(0, br.read(new char[10], 0, 0)); assertEquals(0, br.read(new char[10], 0, 0));
} }
@ -43,48 +43,48 @@ public class ExtendedBufferedReaderTest {
public void testReadLookahead1() throws Exception { public void testReadLookahead1() throws Exception {
final ExtendedBufferedReader br = getBufferedReader("1\n2\r3\n"); final ExtendedBufferedReader br = getBufferedReader("1\n2\r3\n");
assertEquals('1', br.lookAhead()); assertEquals('1', br.lookAhead());
assertEquals(UNDEFINED, br.readAgain()); assertEquals(UNDEFINED, br.getLastChar());
assertEquals('1', br.read()); assertEquals('1', br.read());
assertEquals('1', br.readAgain()); assertEquals('1', br.getLastChar());
assertEquals(0, br.getLineNumber()); assertEquals(0, br.getLineNumber());
assertEquals('\n', br.lookAhead()); assertEquals('\n', br.lookAhead());
assertEquals(0, br.getLineNumber()); assertEquals(0, br.getLineNumber());
assertEquals('1', br.readAgain()); assertEquals('1', br.getLastChar());
assertEquals('\n', br.read()); assertEquals('\n', br.read());
assertEquals(1, br.getLineNumber()); assertEquals(1, br.getLineNumber());
assertEquals('\n', br.readAgain()); assertEquals('\n', br.getLastChar());
assertEquals(1, br.getLineNumber()); assertEquals(1, br.getLineNumber());
assertEquals('2', br.lookAhead()); assertEquals('2', br.lookAhead());
assertEquals(1, br.getLineNumber()); assertEquals(1, br.getLineNumber());
assertEquals('\n', br.readAgain()); assertEquals('\n', br.getLastChar());
assertEquals(1, br.getLineNumber()); assertEquals(1, br.getLineNumber());
assertEquals('2', br.read()); assertEquals('2', br.read());
assertEquals('2', br.readAgain()); assertEquals('2', br.getLastChar());
assertEquals('\r', br.lookAhead()); assertEquals('\r', br.lookAhead());
assertEquals('2', br.readAgain()); assertEquals('2', br.getLastChar());
assertEquals('\r', br.read()); assertEquals('\r', br.read());
assertEquals('\r', br.readAgain()); assertEquals('\r', br.getLastChar());
assertEquals('3', br.lookAhead()); assertEquals('3', br.lookAhead());
assertEquals('\r', br.readAgain()); assertEquals('\r', br.getLastChar());
assertEquals('3', br.read()); assertEquals('3', br.read());
assertEquals('3', br.readAgain()); assertEquals('3', br.getLastChar());
assertEquals('\n', br.lookAhead()); assertEquals('\n', br.lookAhead());
assertEquals(2, br.getLineNumber()); assertEquals(2, br.getLineNumber());
assertEquals('3', br.readAgain()); assertEquals('3', br.getLastChar());
assertEquals('\n', br.read()); assertEquals('\n', br.read());
assertEquals(3, br.getLineNumber()); assertEquals(3, br.getLineNumber());
assertEquals('\n', br.readAgain()); assertEquals('\n', br.getLastChar());
assertEquals(3, br.getLineNumber()); assertEquals(3, br.getLineNumber());
assertEquals(END_OF_STREAM, br.lookAhead()); assertEquals(END_OF_STREAM, br.lookAhead());
assertEquals('\n', br.readAgain()); assertEquals('\n', br.getLastChar());
assertEquals(END_OF_STREAM, br.read()); assertEquals(END_OF_STREAM, br.read());
assertEquals(END_OF_STREAM, br.readAgain()); assertEquals(END_OF_STREAM, br.getLastChar());
assertEquals(END_OF_STREAM, br.read()); assertEquals(END_OF_STREAM, br.read());
assertEquals(END_OF_STREAM, br.lookAhead()); assertEquals(END_OF_STREAM, br.lookAhead());
@ -101,13 +101,13 @@ public class ExtendedBufferedReaderTest {
ref[2] = 'c'; ref[2] = 'c';
assertEquals(3, br.read(res, 0, 3)); assertEquals(3, br.read(res, 0, 3));
assertArrayEquals(ref, res); assertArrayEquals(ref, res);
assertEquals('c', br.readAgain()); assertEquals('c', br.getLastChar());
assertEquals('d', br.lookAhead()); assertEquals('d', br.lookAhead());
ref[4] = 'd'; ref[4] = 'd';
assertEquals(1, br.read(res, 4, 1)); assertEquals(1, br.read(res, 4, 1));
assertArrayEquals(ref, res); assertArrayEquals(ref, res);
assertEquals('d', br.readAgain()); assertEquals('d', br.getLastChar());
} }
@Test @Test