Interface PStack<E>
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description booleananyMatch(Predicate<E> predicate)Test given predicate on elements and return true if any of elements matches the predicatebooleanisEmpty()Epeek()Epeek(int i)PStack<E>pop()PStack<E>push(E e)intsize()Naive implementation has O(n) time complexity, where n is number of elements.StringtoString()-
Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
-
-
-
Method Detail
-
peek
E peek()
- Returns:
- element at the top of this stack
- Throws:
IllegalStateException- if this stack is empty.
-
peek
E peek(int i)
- Parameters:
i- - index of element to be returned, 0 means top of the stack- Returns:
- i-th element from top of the stack
- Throws:
IllegalStateException- if stack has less than i elements
-
pop
PStack<E> pop()
- Returns:
- new stack with removed element
- Throws:
IllegalStateException- if this stack is empty.
-
isEmpty
boolean isEmpty()
- Returns:
- true if this stack contains no elements
-
anyMatch
boolean anyMatch(Predicate<E> predicate)
Test given predicate on elements and return true if any of elements matches the predicate- Parameters:
predicate- predicate to be tested- Returns:
- true if any of the stack elements satisfies the predicate
-
size
int size()
Naive implementation has O(n) time complexity, where n is number of elements. More clever implementation could take advantage of PStack's immutability- Returns:
- number of elements in the stack
-
-