- All Superinterfaces:
Iterable<T>
Common superinterface for stack and queue.
Feed can be iterated over but doing so changes its state, i.e.
every item returned by iterator is removed from the feed.
- Since:
- 2.0
-
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Removes all elements from the feed.booleanisEmpty()Returns true if the feed is empty.iterator()State changing iterator of this feed.default booleannonEmpty()Returns true if the feed is non-empty.peek()Returns top element from the feed without removing it.take()Removes top element from the feed and returns it.Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
isEmpty
boolean isEmpty()Returns true if the feed is empty. -
nonEmpty
default boolean nonEmpty()Returns true if the feed is non-empty. -
clear
void clear()Removes all elements from the feed. -
take
Removes top element from the feed and returns it.- Throws:
NoSuchElementException- if the feed is empty.
-
peek
Returns top element from the feed without removing it.- Throws:
NoSuchElementException- if the feed is empty.
-
iterator
State changing iterator of this feed. Elements produced by the iterator are removed from this feed. SpecificallyIterator.next()has the same effect as callingtake(). The iterator does not implementremove()since element returned is already removed from the feed.
-