I'd suggest placing a @link
here. http://stackoverflow.com/questions/10097199/javadoc-see-or-link https://stackoverflow.com/questions/10097199/javadoc-see-or-link
I'd suggest placing a @link
here. http://stackoverflow.com/questions/10097199/javadoc-see-or-link
I'd suggest placing a @link
here. https://stackoverflow.com/questions/10097199/javadoc-see-or-link
private final List<E> peekedElements = new ArrayList<>();
@Override
public boolean hasNext() {
Optional<E> peekElement = peek();
return peekElement.isPresent();
}
@Override
public E next() {
if (!peekedElements.isEmpty()) {
return peekedElements.remove(0);
}
return iterator.next();
}
@Override
public boolean nextMatches(final Predicate<? super E> condition) {
Objects.requireNonNull(condition, "condition");
Optional<E> peekElement = peek();
return (peekElement.isPresent() && condition.test(peekElement.get()));
}
/**
* Returns an optional containing the next element, or an empty optional if there is none.
*
* @return The optional containing the next element, or the empty optional if there is none.
*/
private Optional<E> peek() {
if (!peekedElements.isEmpty()) {
return Optional.ofNullable(peekedElements.get(0));
}
if (!iterator.hasNext()) {
return Optional.empty();
}
E element = iterator.next();
peekedElements.add(element);
return Optional.ofNullable(element);
}
private final List<E> peekedElements = new ArrayList<>();
@Override
public boolean hasNext() {
Optional<E> peekElement = peek();
return peekElement.isPresent();
}
@Override
public E next() {
if (!peekedElements.isEmpty()) {
return peekedElements.remove(0);
}
return iterator.next();
}
@Override
public boolean nextMatches(final Predicate<? super E> condition) {
Objects.requireNonNull(condition, "condition");
Optional<E> peekElement = peek();
return (peekElement.isPresent() && condition.test(peekElement.get()));
}
/**
* Returns an optional containing the next element, or an empty optional if there is none.
*
* @return The optional containing the next element, or the empty optional if there is none.
*/
private Optional<E> peek() {
if (!peekedElements.isEmpty()) {
return Optional.ofNullable(peekedElements.get(0));
}
if (!iterator.hasNext()) {
return Optional.empty();
}
E element = iterator.next();
peekedElements.add(element);
return Optional.ofNullable(element);
}
private final List<E> peekedElements = new ArrayList<>();
@Override
public boolean hasNext() {
Optional<E> peekElement = peek();
return peekElement.isPresent();
}
@Override
public E next() {
if (!peekedElements.isEmpty()) {
return peekedElements.remove(0);
}
return iterator.next();
}
@Override
public boolean nextMatches(final Predicate<? super E> condition) {
Objects.requireNonNull(condition, "condition");
Optional<E> peekElement = peek();
return (peekElement.isPresent() && condition.test(peekElement.get()));
}
/**
* Returns an optional containing the next element, or an empty optional if there is none.
*
* @return The optional containing the next element, or the empty optional if there is none.
*/
private Optional<E> peek() {
if (!peekedElements.isEmpty()) {
return Optional.ofNullable(peekedElements.get(0));
}
if (!iterator.hasNext()) {
return Optional.empty();
}
E element = iterator.next();
peekedElements.add(element);
return Optional.ofNullable(element);
}
The Design
A LogReader
reads a log, filters the unwanted stuff and converts it into LogEntries
. According to your design.
That's a bit much. Split it up.
Make one LogReader
that just reads the file and presents you with endless strings. Oh wait, that's a BufferedReader
! I'd see the LogReader
basically as an iterator wrapper for BufferedReader
.
Make a LogParser
that takes a Iterable<String>
and parses them into LogEntries
. Then make a LogFilter
that takes a bunch of LogEntries
and returns only the ones you want.
Because the input and the output of the LogFilter
are the same type, it's now optional for a caller. This simplifies your API when it comes to simple tasks.
The Design
A LogReader
reads a log, filters the unwanted stuff and converts it into LogEntries
. According to your design.
That's a bit much. Split it up.
Make one LogReader
that just reads the file and presents you with endless strings. Oh wait, that's a BufferedReader
! I'd see the LogReader
basically as an iterator wrapper for BufferedReader
.
Make a LogParser
that takes a Iterable<String>
and parses them into LogEntries
. Then make a LogFilter
that takes a bunch of LogEntries
and returns only the ones you want.
Because the input and the output of the LogFilter
are the same type, it's now optional for a caller. This simplifies your API when it comes to simple tasks.