Payload - The payload type.public abstract class AbstractSequence<Payload> extends AbstractIndexedSource<Payload> implements Sequence<Payload>
AbstractSequence is an abstract base implementation of a
Sequence.| Constructor and Description |
|---|
AbstractSequence(Nullity nullity)
Creates a new
AbstractSequence. |
| Modifier and Type | Method and Description |
|---|---|
Sequence<Payload> |
append(Payload payload)
Appends the given payload value.
|
Sequence<Payload> |
appendAll(Iterable<? extends Payload> payloads)
Appends the given payload values.
|
Sequence<Payload> |
appendAll(Payload... payloads)
Appends the given payload values.
|
Source<Payload> |
clear()
Removes all payload values.
|
protected abstract Source<Payload> |
doClear()
Removes all payload values.
|
protected abstract void |
doInsert(int index,
Payload payload)
Inserts the given payload value as the new first value.
|
protected abstract Payload |
doRemove(int index)
Removes the payload value at the given index.
|
protected abstract Source<Payload> |
doRemoveAll(Predicate<? super Payload> predicate,
boolean satisfying)
Removes the payload values that satisfy the given
Predicate. |
protected abstract Payload |
doReplace(int index,
Payload replacement)
Replaces the payload value at the given index with the given replacement
payload value.
|
boolean |
equals(Object object)
Compares the given object with this
Sequence for equality. |
Nullity |
getNullity()
Returns the
Nullity this AbstractSequence has been
created with. |
int |
hashCode()
Returns the hash code of this
Sequence. |
Sequence<Payload> |
insert(int index,
Payload payload)
Inserts the given payload value at the given index.
|
Sequence<Payload> |
insertAll(int index,
Iterable<? extends Payload> payloads)
Inserts the given payload values starting at the given index.
|
Sequence<Payload> |
insertAll(int index,
Payload... payloads)
Inserts the given payload values starting at the given index.
|
protected void |
onInserted(Payload payload)
Called after the given payload value has been inserted.
|
protected void |
onRemoved(Payload payload)
Called after the given payload value has been removed.
|
protected void |
onRemoved(Source<Payload> payloads)
Called after the given payload values have been removed.
|
Sequence<Payload> |
prepend(Payload payload)
Prepends the given payload value.
|
Sequence<Payload> |
prependAll(Iterable<? extends Payload> payloads)
Prepends the given payload values.
|
Sequence<Payload> |
prependAll(Payload... payloads)
Prepends the given payload values.
|
Payload |
remove(int index)
Removes the payload value at the given index.
|
Source<Payload> |
removeAll(Payload reference)
Removes all occurrences, by
equality, of
the given reference payload value. |
Source<Payload> |
removeAllMatches(Predicate<? super Payload> predicate)
Removes the payload values that satisfy the given
Predicate. |
Payload |
removeFirst()
Removes the first payload value.
|
Optional<Payload> |
removeFirst(Payload reference)
Removes the first occurrence, by
equality,
of the given reference payload value. |
Optional<Payload> |
removeFirstMatch(Predicate<? super Payload> predicate)
Removes the first payload value that satisfies the given
Predicate |
Payload |
removeLast()
Removes the last payload value.
|
Optional<Payload> |
removeLast(Payload reference)
Removes the last occurrence, by
equality,
of the given payload value. |
Optional<Payload> |
removeLastMatch(Predicate<? super Payload> predicate)
Removes the last payload value that satisfies the given
Predicate |
Payload |
replace(int index,
Payload replacement)
Replaces the payload value at the given index with the given replacement
payload value.
|
Source<Payload> |
replaceAll(Payload reference,
Provider<? extends Payload> provider)
Replaces all occurrences of the the given reference payload value with
payload values yielded by the given
Provider. |
Source<Payload> |
replaceAllMatches(Predicate<? super Payload> predicate,
Provider<? extends Payload> provider)
|
Payload |
replaceFirst(Payload replacement)
Replaces the first payload value with the given replacement payload
value.
|
Optional<Payload> |
replaceFirst(Payload reference,
Payload replacement)
Replaces the first occurrence of the given reference payload value with
the given replacement payload value.
|
Optional<Payload> |
replaceFirstMatch(Predicate<? super Payload> predicate,
Payload replacement)
Replaces the first payload value that satisfy the given
Predicate
with the given replacement payload value. |
Payload |
replaceLast(Payload replacement)
Replaces the last payload value with the given replacement payload value.
|
Optional<Payload> |
replaceLast(Payload reference,
Payload replacement)
Replaces last occurrence of the the given reference payload value with
the given replacement payload value.
|
Optional<Payload> |
replaceLastMatch(Predicate<? super Payload> predicate,
Payload replacement)
Replaces the last payload value that satisfy the given
Predicate
with the given replacement payload value. |
Source<Payload> |
retainAll(Payload reference)
Removes all but the given payload value.
|
Source<Payload> |
retainAllMatches(Predicate<? super Payload> predicate)
Removes all but the payload values that satisfy the given
Predicate. |
doGet, doGetFirst, doIterator, firstIndexOf, firstIndexOfMatch, get, getLast, getLast, getLastMatch, isFirst, isLast, iterator, iterator, lastIndexOf, lastIndexOfMatchcontains, containsAll, containsAll, containsMatch, createPredicate, firstIndexOf, getAll, getAllMatches, getFirst, getFirst, getFirstMatch, isEmpty, toStringclone, finalize, getClass, notify, notifyAll, wait, wait, waitfirstIndexOf, firstIndexOfMatch, get, getFirst, getFirst, getFirstMatch, getLast, getLast, getLastMatch, isFirst, isLast, iterator, lastIndexOf, lastIndexOfMatchcontains, containsAll, containsAll, containsMatch, getAll, getAllMatches, isEmpty, sizeiteratoriteratorforEach, spliteratorpublic AbstractSequence(Nullity nullity) throws IllegalArgumentException
AbstractSequence.nullity - The Nullity to be used.IllegalArgumentException - If the given Nullity is null.public final Nullity getNullity()
Nullity this AbstractSequence has been
created with.Nullity.public final Sequence<Payload> insert(int index, Payload payload) throws IllegalArgumentException
Sequencepublic final Sequence<Payload> insertAll(int index, Payload... payloads) throws IllegalArgumentException, IllegalStateException
SequenceinsertAll in interface Sequence<Payload>index - The index to be used.payloads - The array of payload values to be inserted.Sequence.IllegalArgumentException - If the given array of payload values is null or if
any of the given payload values is null and this
Sequence doesn't allow a null to be added.IllegalStateExceptionpublic final Sequence<Payload> insertAll(int index, Iterable<? extends Payload> payloads) throws IllegalArgumentException, IllegalStateException
SequenceinsertAll in interface Sequence<Payload>index - The index to be used.payloads - The Iterable of payload values to be inserted.Sequence.IllegalArgumentException - If the given Iterable of payload values is
null or if any of the given payload values is
null and this Sequence doesn't allow a
null to be added.IllegalStateExceptionprotected abstract void doInsert(int index,
Payload payload)
index - The index to be used.payload - The payload value to be inserted, which is guaranteed to be
not null, unless the Nullity of this
Sequence is Nullity.ALLOW.protected void onInserted(Payload payload)
payload - The inserted payload value, which is guaranteed to be not
null, unless the Nullity of this
Sequence is Nullity.ALLOW.public final Sequence<Payload> prepend(Payload payload) throws IllegalArgumentException
Sequencepublic final Sequence<Payload> prependAll(Payload... payloads) throws IllegalArgumentException
SequenceprependAll in interface Sequence<Payload>payloads - The array of payload values to be inserted.Sequence.IllegalArgumentException - If the given array of payload values is null or if
any of the given payload values is null and this
Sequence doesn't allow a null to be added.public final Sequence<Payload> prependAll(Iterable<? extends Payload> payloads) throws IllegalArgumentException
SequenceprependAll in interface Sequence<Payload>payloads - The Iterable of payload values to be inserted.Sequence.IllegalArgumentException - If the given Iterable of payload values is
null or if any of the given payload values is
null and this Sequence doesn't allow a
null to be added.public final Sequence<Payload> append(Payload payload) throws IllegalArgumentException
Sequencepublic final Sequence<Payload> appendAll(Payload... payloads) throws IllegalArgumentException
SequenceappendAll in interface Sequence<Payload>payloads - The array of payload values to be appended.Sequence.IllegalArgumentException - If the given array of payload values is null or if
any of the given payload values is null and this
Sequence doesn't allow a null to be added.public final Sequence<Payload> appendAll(Iterable<? extends Payload> payloads) throws IllegalArgumentException
SequenceappendAll in interface Sequence<Payload>payloads - The Iterable of payload values to be appended.Sequence.IllegalArgumentException - If the given Iterable of payload values is
null or if any of the given payload values is
null and this Sequence doesn't allow a
null to be added.public final Payload remove(int index) throws IndexOutOfBoundsException
Sequenceprotected abstract Payload doRemove(int index)
index - The index to be used which is guaranteed to be not negative
and not larger then or equal to the
size of this
AbstractSequence.protected void onRemoved(Payload payload)
payload - The removed payload value, which is guaranteed to be not
null, unless the Nullity of this
Sequence is Nullity.ALLOW.protected void onRemoved(Source<Payload> payloads)
payloads - The removed payload values, which are guaranteed to be not
null, unless the Nullity of this
Sequence is Nullity.ALLOW.public final Payload removeFirst() throws NoSuchElementException
SequenceremoveFirst in interface Sequence<Payload>NoSuchElementException - If this Sequence is empty.public final Optional<Payload> removeFirst(Payload reference) throws IllegalArgumentException
Sequenceequality,
of the given reference payload value.removeFirst in interface Sequence<Payload>reference - The reference payload to be removed.Optional yielding the removed payload value.IllegalArgumentExceptionpublic final Optional<Payload> removeFirstMatch(Predicate<? super Payload> predicate) throws IllegalArgumentException
SequencePredicateremoveFirstMatch in interface Sequence<Payload>predicate - The Predicate to be used.Optional yielding the removed payload value.IllegalArgumentException - If the given predicate is null.public final Payload removeLast() throws NoSuchElementException
SequenceremoveLast in interface Sequence<Payload>NoSuchElementException - If this Sequence is empty.public final Optional<Payload> removeLast(Payload reference) throws IllegalArgumentException
Sequenceequality,
of the given payload value.removeLast in interface Sequence<Payload>reference - The reference payload to be removed.Optional yielding the removed payload value.IllegalArgumentExceptionpublic final Optional<Payload> removeLastMatch(Predicate<? super Payload> predicate) throws IllegalArgumentException
SequencePredicateremoveLastMatch in interface Sequence<Payload>predicate - The Predicate to be used.Optional yielding the removed payload value.IllegalArgumentException - If the given predicate is null.public final Source<Payload> removeAll(Payload reference)
Sequenceequality, of
the given reference payload value.public final Source<Payload> removeAllMatches(Predicate<? super Payload> predicate) throws IllegalArgumentException
SequencePredicate.removeAllMatches in interface Sequence<Payload>predicate - The Predicate to be used.Source yielding the removed payload values.IllegalArgumentException - If the given Predicate is null.protected abstract Source<Payload> doRemoveAll(Predicate<? super Payload> predicate, boolean satisfying)
Predicate.public final Source<Payload> retainAll(Payload reference)
Sequencepublic final Source<Payload> retainAllMatches(Predicate<? super Payload> predicate) throws IllegalArgumentException
SequencePredicate.retainAllMatches in interface Sequence<Payload>predicate - The Predicate to be used.Source yielding the removed payload values.IllegalArgumentException - If the given Predicate is null.public final Source<Payload> clear()
Sequenceprotected abstract Source<Payload> doClear()
Source yielding the removed payload values.public final Payload replace(int index, Payload replacement) throws IllegalArgumentException, IndexOutOfBoundsException
Sequencereplace in interface Sequence<Payload>index - The index to be used.replacement - The replacement payload value to be used.IllegalArgumentException - If the given replacement payload value is null and
this IndexedSource doesn't allow a null to
be added.IndexOutOfBoundsException - If the given index is negative or if the given index is
larger or equal to the size of
this IndexedSource.protected abstract Payload doReplace(int index, Payload replacement)
index - The index to be used which is guaranteed to be not negative
and not larger then or equal to the
size of this
AbstractSequence.replacement - The replacement payload value to be used.public final Payload replaceFirst(Payload replacement) throws IllegalArgumentException, NoSuchElementException
SequencereplaceFirst in interface Sequence<Payload>replacement - The replacement payload value to be used.IllegalArgumentException - If the given replacement payload value is null and
this IndexedSource doesn't allow a null to
be added.NoSuchElementException - If this IndexedSource is
empty.public final Optional<Payload> replaceFirst(Payload reference, Payload replacement) throws IllegalArgumentException
SequencereplaceFirst in interface Sequence<Payload>reference - The reference payload value to be used.replacement - The replacement payload to be used.Optional yielding the removed payload value, if any.IllegalArgumentException - If the given replacement payload value is null and
this IndexedSource doesn't allow a null to
be added.public final Optional<Payload> replaceFirstMatch(Predicate<? super Payload> predicate, Payload replacement) throws IllegalArgumentException
SequencePredicate
with the given replacement payload value.replaceFirstMatch in interface Sequence<Payload>predicate - The Predicate to be used.replacement - The replacement payload to be used.Optional yielding the removed payload value, if any.IllegalArgumentException - If the give Predicate is null or if the
given replacement payload value is null and this
IndexedSource doesn't allow a null to be
added.public final Payload replaceLast(Payload replacement) throws IllegalArgumentException, NoSuchElementException
SequencereplaceLast in interface Sequence<Payload>replacement - The replacement payload value to be used.IllegalArgumentException - If the given replacement payload value is null and
this IndexedSource doesn't allow a null to
be added.NoSuchElementException - If this IndexedSource is
empty.public final Optional<Payload> replaceLast(Payload reference, Payload replacement) throws IllegalArgumentException
SequencereplaceLast in interface Sequence<Payload>reference - The replacement reference payload value to be used.replacement - The payload to be used.Optional yielding the removed payload value, if any.IllegalArgumentException - If the given replacement payload value is null and
this IndexedSource doesn't allow a null to
be added.public Optional<Payload> replaceLastMatch(Predicate<? super Payload> predicate, Payload replacement) throws IllegalArgumentException
SequencePredicate
with the given replacement payload value.replaceLastMatch in interface Sequence<Payload>predicate - The Predicate to be used.replacement - The replacement payload to be used.Optional yielding the removed payload value, if any.IllegalArgumentException - If the give Predicate is null or if the
given replacement payload value is null and this
IndexedSource doesn't allow a null to be
added.public final Source<Payload> replaceAll(Payload reference, Provider<? extends Payload> provider) throws IllegalArgumentException, ProvisioningException
SequenceProvider.replaceAll in interface Sequence<Payload>reference - The reference payload value to be used.provider - The Provider to be used.Source yielding the replaced payload values.IllegalArgumentException - If the given Provider is null.ProvisioningException - If the given Provider yields null and this
IndexedSource doesn't allow a null to be
added.public final Source<Payload> replaceAllMatches(Predicate<? super Payload> predicate, Provider<? extends Payload> provider) throws IllegalArgumentException, ProvisioningException
SequencePredicate with
payload values yielded by the given Provider.replaceAllMatches in interface Sequence<Payload>predicate - The Predicate to be used.provider - The Provider to be used.Source yielding the replaced payload values.IllegalArgumentException - If the give Predicate is null or if the
given Provider is null.ProvisioningException - If the given Provider yields null and this
IndexedSource doesn't allow a null to be
added.public final int hashCode()
SequenceSequence.
The hash code of a Sequence is defined to be the result of the
following calculation:
int hashCode = 1;
Iterator<Payload> iterator = sequence.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.