Package org.sonar.java.collections
Interface PStack<E>
-
- Type Parameters:
E
- the type of elements maintained by this stack
public interface PStack<E>
Persistent (functional) Stack.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
anyMatch(Predicate<E> predicate)
Test given predicate on elements and return true if any of elements matches the predicatevoid
forEach(Consumer<E> action)
Performs the given action for each element in this stack until all elements have been processed or the action throws an exception.boolean
isEmpty()
E
peek()
E
peek(int i)
PStack<E>
pop()
PStack<E>
push(E e)
int
size()
Naive implementation has O(n) time complexity, where n is number of elements.String
toString()
-
-
-
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
-
forEach
void forEach(Consumer<E> action)
Performs the given action for each element in this stack until all elements have been processed or the action throws an exception.
-
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
-
-