java.lang.Object
com.github.zafarkhaja.semver.util.Stream<E>
- Type Parameters:
E
- the type of elements held in this stream
- All Implemented Interfaces:
Iterable<E>
A simple stream class used to represent a stream of characters or tokens.
- Since:
- 0.7.0
- Author:
- Zafar Khaja <zafarkhaja@gmail.com>
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
TheElementType
interface represents types of the elements held by this stream and can be used for stream filtering. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionconsume()
Consumes the next element in this stream.final <T extends Stream.ElementType<E>>
Econsume
(T... expected) Consumes the next element in this stream only if it is of the expected types.int
Returns the current offset of this stream.iterator()
Returns an iterator over elements that are left in this stream.Returns the next element in this stream without consuming it.lookahead
(int position) Returns the element at the specified position in this stream without consuming it.final <T extends Stream.ElementType<E>>
booleanpositiveLookahead
(T... expected) Checks if the next element in this stream is of the expected types.final <T extends Stream.ElementType<E>>
booleanpositiveLookaheadBefore
(Stream.ElementType<E> before, T... expected) Checks if there exists an element in this stream of the expected types before the specified type.final <T extends Stream.ElementType<E>>
booleanpositiveLookaheadUntil
(int until, T... expected) Checks if there is an element in this stream of the expected types until the specified position.void
pushBack()
Pushes back one element at a time.E[]
toArray()
Returns an array containing all of the elements that are left in this stream.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
Stream
Constructs a stream containing the specified elements.The stream does not store the real elements but the defensive copy.
- Parameters:
elements
- the elements to be streamed
-
-
Method Details
-
consume
Consumes the next element in this stream.- Returns:
- the next element in this stream
or
null
if no more elements left
-
consume
Consumes the next element in this stream only if it is of the expected types.- Type Parameters:
T
- represents the element type of this stream, removes the "unchecked generic array creation for varargs parameter" warnings- Parameters:
expected
- the types which are expected- Returns:
- the next element in this stream
- Throws:
UnexpectedElementException
- if the next element is of an unexpected type
-
pushBack
public void pushBack()Pushes back one element at a time. -
lookahead
Returns the next element in this stream without consuming it.- Returns:
- the next element in this stream
-
lookahead
Returns the element at the specified position in this stream without consuming it.- Parameters:
position
- the position of the element to return- Returns:
- the element at the specified position
or
null
if no more elements left
-
currentOffset
public int currentOffset()Returns the current offset of this stream.- Returns:
- the current offset of this stream
-
positiveLookahead
@SafeVarargs public final <T extends Stream.ElementType<E>> boolean positiveLookahead(T... expected) Checks if the next element in this stream is of the expected types.- Type Parameters:
T
- represents the element type of this stream, removes the "unchecked generic array creation for varargs parameter" warnings- Parameters:
expected
- the expected types- Returns:
true
if the next element is of the expected types orfalse
otherwise
-
positiveLookaheadBefore
@SafeVarargs public final <T extends Stream.ElementType<E>> boolean positiveLookaheadBefore(Stream.ElementType<E> before, T... expected) Checks if there exists an element in this stream of the expected types before the specified type.- Type Parameters:
T
- represents the element type of this stream, removes the "unchecked generic array creation for varargs parameter" warnings- Parameters:
before
- the type before which to searchexpected
- the expected types- Returns:
true
if there is an element of the expected types before the specified type orfalse
otherwise
-
positiveLookaheadUntil
@SafeVarargs public final <T extends Stream.ElementType<E>> boolean positiveLookaheadUntil(int until, T... expected) Checks if there is an element in this stream of the expected types until the specified position.- Type Parameters:
T
- represents the element type of this stream, removes the "unchecked generic array creation for varargs parameter" warnings- Parameters:
until
- the position until which to searchexpected
- the expected types- Returns:
true
if there is an element of the expected types until the specified position orfalse
otherwise
-
iterator
Returns an iterator over elements that are left in this stream. -
toArray
Returns an array containing all of the elements that are left in this stream.The returned array is a safe copy.
- Returns:
- an array containing all of elements in this stream
-