guava icon indicating copy to clipboard operation
guava copied to clipboard

Add LineReader.lines() for parity with BufferedReader

Open JanecekPetr opened this issue 3 years ago • 5 comments

LineReader currently only has the readLine() method. However, already since Java 8 there's lines(), too.

Not to mention that it'd be nice to also maybe have readAllLines() and maybe even a getLineNumber() from LineNumberReader.

Yes, I know, there's CharStreams.readLines(), that's fine.

JanecekPetr avatar May 31 '22 08:05 JanecekPetr

so there are 3 methods to be implemented: lines(), readAllLines() and getLineNumber(). Right?

ritikBhandari avatar Jun 01 '22 17:06 ritikBhandari

Not really. I will say lines() definitely is needed to bring LineReader to where BufferedReader is. The other methods are up for a debate as they could be slightly controversial / unneeded:

  • How often do you really need a line count? It's probably not worth it for the component to keep track of it all the time if only a small percentage of use-cases will use it.
  • It's unclear whether readAllLines() belongs here because CharStreams.readLines() exists. Doing one thing multiple ways is usually frowned upon in good API design. That said, LineReader kinda screams for the method. Not my call. This requires more API designing and discussions and, let's be frank, nobody is going to spend precious time on arguing whether the method belongs there or not, so it's not going to be there.

Let's only focus on lines() here.

JanecekPetr avatar Jun 01 '22 19:06 JanecekPetr

Makes sense. So its lines() for now. Should I resolve it?

ritikBhandari avatar Jun 01 '22 23:06 ritikBhandari

I have added the lines method in this pull request https://github.com/google/guava/pull/6142 Can anyone review it.

maxmielchen avatar Aug 09 '22 18:08 maxmielchen

I have raised a cr for this.

ayushsinghal90 avatar Jan 22 '23 11:01 ayushsinghal90