Payload - The payload type.public abstract class AbstractStack<Payload> extends AbstractSource<Payload> implements Stack<Payload>
AbstractStack is an abstract base implementation of Stack.
An AbstractStack has two sets of protected methods.
| Constructor and Description |
|---|
AbstractStack(Nullity nullity)
Creates a new
AbstractStack. |
| Modifier and Type | Method and Description |
|---|---|
Source<Payload> |
clear()
Removes all payload values.
|
protected abstract Source<Payload> |
doClear()
Removes all payload value.
|
protected abstract Payload |
doGetFirst()
Returns the first (i.e.
|
protected abstract ProtectedIterator<Payload> |
doIterator()
Returns a fail-fast
ProtectedIterator that starts with the
payload value at the given first index, where 0 is the index
of most recently pushed value. |
protected abstract Payload |
doPop()
Removes the first (i.e.
|
protected abstract void |
doPush(Payload payload)
Pushes the given payload value as the new first value.
|
protected abstract Payload |
doReplace(Payload replacement)
Replaces the payload value at the given index with the given replacement
payload value.
|
protected abstract int |
doSize()
Returns the number of payload values of this
Stack. |
boolean |
equals(Object object)
Compares the given object with this
Stack for equality. |
Optional<Integer> |
firstIndexOf(Payload reference)
|
Optional<Integer> |
firstIndexOfMatch(Predicate<? super Payload> predicate)
|
Payload |
get(int index)
Returns the payload value at the given index, where 0 is the
index of most recently
pushed value. |
Nullity |
getNullity()
Returns the
Nullity this AbstractStack has been created
with. |
int |
hashCode()
Returns the hash code of this
Stack. |
ProtectedIterator<Payload> |
iterator()
Returns a fail-fast
ProtectedIterator that starts with the first
(i.e. |
protected void |
onCleared(Source<Payload> iterable)
Called after all payload values have been removed.
|
protected void |
onPopped(Payload payload)
Called after the first (i.e.
|
protected void |
onPushed(Payload payload)
Called after the given payload value has been pushed as the new first
value.
|
Payload |
pop()
Removes the first (i.e.
|
Source<Payload> |
popAll(int number)
Removes the given number of payload values. |
Source<Payload> |
popAllMatches(Predicate<? super Payload> predicate)
Removes the first (i.e.
|
Stack<Payload> |
push(Payload payload)
Pushes the given payload value as the new first value.
|
Stack<Payload> |
pushAll(Iterable<? extends Payload> payloads)
Pushes the given payload values in the given
order. |
Stack<Payload> |
pushAll(Payload... payloads)
Pushes the given payload values in the given
order. |
Payload |
replace(Payload replacement)
Replaces the first (i.e.
|
int |
size()
Returns the number of payload values of this
Source. |
contains, containsAll, containsAll, containsMatch, createPredicate, firstIndexOf, getAll, getAllMatches, getFirst, getFirst, getFirstMatch, isEmpty, toStringclone, finalize, getClass, notify, notifyAll, wait, wait, waitgetFirst, getFirst, getFirstMatchcontains, containsAll, containsAll, containsMatch, getAll, getAllMatches, isEmptyforEach, spliteratorpublic AbstractStack(Nullity nullity) throws IllegalArgumentException
AbstractStack.nullity - The Nullity to be used.IllegalArgumentException - If the given Nullity is null;public final Nullity getNullity()
Nullity this AbstractStack has been created
with.Nullity.public final int size()
SourceSource.protected abstract int doSize()
Stack.Stack.public final Stack<Payload> push(Payload payload) throws IllegalArgumentException
Stackpublic final Stack<Payload> pushAll(Payload... payloads) throws IllegalArgumentException, IllegalStateException
StackpushAll in interface Stack<Payload>payloads - The array of payload values to be pushed.Stack.IllegalArgumentException - If the given array of payload values is null or if
one of the given payload values is null and this
Sequence doesn't allow a null to be added.IllegalStateExceptionpublic final Stack<Payload> pushAll(Iterable<? extends Payload> payloads) throws IllegalArgumentException, IllegalStateException
StackpushAll in interface Stack<Payload>payloads - The Iterable of payload values to be pushed.Stack.IllegalArgumentException - If the given Iterable of payload values is
null or if one of the given payload values is
null and this Sequence doesn't allow a
null to be added.IllegalStateExceptionprotected abstract void doPush(Payload payload)
payload - The payload value to be pushed, which is guaranteed to be not
null, unless the Nullity of this
Stack is Nullity.ALLOW.protected void onPushed(Payload payload)
payload - The pushed payload value, which is guaranteed to be not
null, unless the Nullity of this
Stack is Nullity.ALLOW.public final Payload pop() throws NoSuchElementException
Stackpushed)
payload value.public final Source<Payload> popAll(int number) throws IllegalArgumentException
StackRemoves the given number of payload values.public final Source<Payload> popAllMatches(Predicate<? super Payload> predicate) throws IllegalArgumentException
Stackpushed)
payload values as long as this Stack is not empty and
the first payload value satisfies the given predicate.popAllMatches in interface Stack<Payload>predicate - The Predicate to be used.Source yielding the removed payload values.IllegalArgumentException - If the given Predicate is null.protected abstract Payload doPop()
pushed)
payload value.
Only called if this AbstractStack is not empty.
protected void onPopped(Payload payload)
pushed) payload value has been removed.payload - The popped payload value, which is guaranteed to be not
null, unless the Nullity of this
Stack is Nullity.ALLOW.public final Payload replace(Payload replacement) throws IllegalArgumentException, NoSuchElementException
Stackpushed)
payload value with the given payload value.
replace in interface Stack<Payload>replacement - The payload value to be used.IllegalArgumentException - If the given payload value is null and this
Sequence doesn't allow a null to be added.NoSuchElementException - If this Stack is empty.protected abstract Payload doReplace(Payload replacement)
replacement - The replacement payload value to be used.public final Payload get(int index) throws IndexOutOfBoundsException
Stackpushed value.protected abstract Payload doGetFirst()
pushed)
payload value.
Only called if this AbstractStack is not empty.
doGetFirst in class AbstractSource<Payload>public final Source<Payload> clear()
Stack
This may be a bulk operation and not a short hand for a multiple
pops.
protected abstract Source<Payload> doClear()
Iterable that yields all removed payload values, even
after further structural modifications have been made to this
AbstractStack.protected void onCleared(Source<Payload> iterable)
iterable - An Iterable that yields all removed payload values.public final Optional<Integer> firstIndexOf(Payload reference) throws NoSuchElementException
Stackequality, of the given reference payload value, where 0 is the
index of most recently pushed value.firstIndexOf in interface Stack<Payload>reference - The reference payload value to be used.Optional yielding the index.NoSuchElementExceptionpublic final Optional<Integer> firstIndexOfMatch(Predicate<? super Payload> predicate) throws IllegalArgumentException, NoSuchElementException
StackPredicate, where 0 is the
index of most recently pushed value.firstIndexOfMatch in interface Stack<Payload>predicate - The Predicate value to be used.Optional yielding the index.IllegalArgumentException - If the given Predicate is null.NoSuchElementExceptionpublic final ProtectedIterator<Payload> iterator()
StackProtectedIterator that starts with the first
(i.e. most recently pushed) payload value.iterator in interface Iterable<Payload>iterator in interface Stack<Payload>iterator in interface ProtectedIterable<Payload>ProtectedIterator.protected abstract ProtectedIterator<Payload> doIterator()
ProtectedIterator that starts with the
payload value at the given first index, where 0 is the index
of most recently pushed value.ProtectedIterator.public final int hashCode()
StackStack.
The hash code of a Stack is defined to be the result of the
following calculation:
int hashCode = 1;
Iterator<Payload> iterator = stack.iterator();
while (iterator.hasNext()) {
Payload payload = iterator.next();
hashCode = 31 * hashCode + (null == payload ? 0 : payload.hashCode());
}
Copyright © 2016–2017 Markenwerk – Gesellschaft für markenbildende Maßnahmen mbH. All rights reserved.