Class Stream<E>
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>
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceTheElementTypeinterface represents types of the elements held by this stream and can be used for stream filtering. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionconsume()Consumes the next element in this stream.<T extends Stream.ElementType<E>>
Econsume(T... expected) Consumes the next element in this stream only if it is of the expected types.intReturns 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.<T extends Stream.ElementType<E>>
booleanpositiveLookahead(T... expected) Checks if the next element in this stream is of the expected types.<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.<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.voidpushBack()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 Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Iterable
forEach, spliterator
-
Field Details
-
elements
The array holding all the elements of this stream. -
offset
private int offsetThe current offset which is incremented when an element is consumed.- See Also:
-
-
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
nullif 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
nullif no more elements left
-
currentOffset
public int currentOffset()Returns the current offset of this stream.- Returns:
- the current offset of this stream
-
positiveLookahead
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:
trueif the next element is of the expected types orfalseotherwise
-
positiveLookaheadBefore
public <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:
trueif there is an element of the expected types before the specified type orfalseotherwise
-
positiveLookaheadUntil
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:
trueif there is an element of the expected types until the specified position orfalseotherwise
-
iterator
-
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
-