public class StringPeekerator extends Object implements Peekerator<String>
Peekerator<String>
with various methods that check for string equality or pattern
matching.
Notice that null
is a perfectly valid element value, and all methods handle null
values in a
defined manner.
StringStream
,
AbstractParser
Constructor and Description |
---|
StringPeekerator(Iterator<String> delegate)
Equivalent with
new StringPeekerator(Peekerators.from(delegate)) . |
StringPeekerator(ListIterator<String> delegate)
Equivalent with
new StringPeekerator(Peekerators.from(delegate)) . |
StringPeekerator(Peekerator<String> delegate) |
Modifier and Type | Method and Description |
---|---|
boolean |
hasNext() |
String |
next()
Consumes and returns the next element in this iteration.
|
int |
nextEquals(String... expected)
Verifies that the next element equals any of the expected strings, and consumes it.
|
void |
nextEquals(String expected)
Verifies that the next element equals the expected string, and consumes it.
|
int |
nextEqualsIgnoreCase(String... expected)
Verifies that the next element equals (ignoring case) any of the the expected string, and consumes it.
|
void |
nextEqualsIgnoreCase(String expected)
Verifies that the next element equals (ignoring case) the expected string, and consumes it.
|
int |
nextIfEquals(String... expected)
Consumes the next element iff it equals any of the expected strings.
|
boolean |
nextIfEquals(String expected)
Consumes the next element iff it equals the expected string.
|
int |
nextIfEqualsIgnoreCase(String... expected)
Consumes the next element iff it equals (ignoring case) any of the expected strings.
|
boolean |
nextIfEqualsIgnoreCase(String expected)
Consumes the next element iff it equals (ignoring case) the expected string.
|
Matcher |
nextIfMatches(Pattern pattern)
Consumes the next element iff it matches the given pattern.
|
void |
nextMatches(Pattern pattern)
Verifies that the next element matches the given pattern.
|
String |
peek()
Just like
Peekerator.next() , but does not consume the next element. |
Matcher |
peek(Pattern pattern)
Matches the next element against the given pattern, and returns the successful matcher.
|
boolean |
peek(String expected)
Checks whether the next element equals the expected string, but does consusme it.
|
boolean |
peekIgnoreCase(String expected)
Checks whether the next element equals (ignoring case) the expected string, but does not consume it.
|
void |
remove()
Removes the last element returned by
Peekerator.next() or Peekerator.peek() from the underlying collection. |
String[] |
rest()
Consumes and returns all remaining elements.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEachRemaining
public StringPeekerator(Peekerator<String> delegate)
public StringPeekerator(Iterator<String> delegate)
new StringPeekerator(Peekerators.from(delegate))
.public StringPeekerator(ListIterator<String> delegate)
new StringPeekerator(Peekerators.from(delegate))
.public void remove()
Peekerator
Peekerator.next()
or Peekerator.peek()
from the underlying collection.public String peek()
Peekerator
Peekerator.next()
, but does not consume the next element.
I.e. the next invocation of Peekerator.peek()
of Peekerator.next()
will return the same element that this
invocation returns.peek
in interface Peekerator<String>
public boolean peek(@Nullable String expected)
Object.equals(Object)
public boolean peekIgnoreCase(String expected)
@Nullable public Matcher peek(Pattern pattern)
null
iff the next element is null
, or if it does not match the pattern@Nullable public String next()
Peekerator
public boolean nextIfEquals(@Nullable String expected)
ObjectUtil.equals(Object, Object)
public boolean nextIfEqualsIgnoreCase(@Nullable String expected)
StringUtil.equalsIgnoreCase(String, String)
public int nextIfEquals(String... expected)
Object.equals(Object)
public int nextIfEqualsIgnoreCase(String... expected)
StringUtil.equalsIgnoreCase(String, String)
@Nullable public Matcher nextIfMatches(Pattern pattern)
null
if the next element is null
, or does not match the given patternpublic void nextEquals(String expected)
NoSuchElementException
- This peekerator has no more elementsNoSuchElementException
- The next element does equal the expected stringObjectUtil.equals(Object, Object)
public void nextEqualsIgnoreCase(String expected)
NoSuchElementException
- This peekerator has no more elementsNoSuchElementException
- The next element does equal the expected stringStringUtil.equalsIgnoreCase(String, String)
public int nextEquals(String... expected)
NoSuchElementException
- This peekerator has no more elementsNoSuchElementException
- The next element does equal any of the expected stringsObjectUtil.equals(Object, Object)
public int nextEqualsIgnoreCase(String... expected)
NoSuchElementException
- This peekerator has no more elementsNoSuchElementException
- The next element does equal any of the expected
stringsStringUtil.equalsIgnoreCase(String, String)
public void nextMatches(Pattern pattern)
NoSuchElementException
- This peekerator has no more elementsNoSuchElementException
- The next element is null
NoSuchElementException
- The next element does match the patternpublic String[] rest()
Copyright © 2018 Arno Unkrig. All rights reserved.