- All Superinterfaces:
BaseSeq<T>,IntFunction<T>,Iterable<T>,RandomAccess
- All Known Implementing Classes:
io.jenetics.internal.collection.ArrayISeq,io.jenetics.internal.collection.ArraySeq,CharSeq
Use the
asList() method to work together with the
Java Collection Framework.- Since:
- 1.0
- Version:
- 5.2
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionReturn a newSeqwith the givenvaluesappended.Return a newSeqwith the givenvaluesappended.default Tapply(int index) Return the value at the givenindex.asISeq()Return this sequence asISeqinstance.asList()Returns a fixed-size list backed by the specified sequence.asMSeq()Return this sequence asMSeqinstance.static <T> Seq<T> Return a sequence whose elements are all the elements of the first sequence followed by all the elements of the second sequence.static <T> Seq<T> Return a sequence whose elements are all the elements of the first sequence followed by all the elements of the vararg array.static <T> Seq<T> Return a sequence whose elements are all the elements of the first element followed by all the elements of the sequence.default booleanReturnstrueif this sequence contains the specified element.static <T> Seq<T> empty()Return an emptySeq.static booleanUnified method for compare to sequences for equality.booleanCompares the specified object with this sequence for equality.default booleanTests whether a predicate holds for all elements of this sequence.inthashCode()Returns the hash code value for this sequence.static intUnified method for calculating the hash code of everySeqimplementation.default intReturns the index of the first occurrence of the specified element in this sequence, or -1 if this sequence does not contain the element.default intReturns the index of the first occurrence of the specified element in this sequence, or -1 if this sequence does not contain the element.default intReturns the index of the first occurrence of the specified element in this sequence, or -1 if this sequence does not contain the element.default intindexWhere(Predicate<? super T> predicate) Returns the index of the first element on which the given predicate returnstrue, or -1 if the predicate returns false for every sequence element.default intindexWhere(Predicate<? super T> predicate, int start) Returns the index of the first element on which the given predicate returnstrue, or -1 if the predicate returns false for every sequence element.default intindexWhere(Predicate<? super T> predicate, int start, int end) Returns the index of the first element on which the given predicate returnstrue, or -1 if the predicate returns false for every sequence element.default booleanisSorted()Test whether the given array is sorted in ascending order.default booleanisSorted(Comparator<? super T> comparator) Test whether the given array is sorted in ascending order.default intlastIndexOf(Object element) Returns the index of the last occurrence of the specified element in this sequence, or -1 if this sequence does not contain the element.default intlastIndexOf(Object element, int end) Returns the index of the last occurrence of the specified element in this sequence, or -1 if this sequence does not contain the element.default intlastIndexOf(Object element, int start, int end) Returns the index of the last occurrence of the specified element in this sequence, or -1 if this sequence does not contain the element.default intlastIndexWhere(Predicate<? super T> predicate) Returns the index of the last element on which the given predicate returnstrue, or -1 if the predicate returns false for every sequence element.default intlastIndexWhere(Predicate<? super T> predicate, int end) Returns the index of the last element on which the given predicate returnstrue, or -1 if the predicate returns false for every sequence element.default intlastIndexWhere(Predicate<? super T> predicate, int start, int end) Returns the index of the last element on which the given predicate returnstrue, or -1 if the predicate returns false for every sequence element.<B> Seq<B> Builds a new sequence by applying a function to all elements of this sequence.static <T> Seq<T> Create a newSeqfrom the given values.static <T> Seq<T> Creates a new sequence, which is filled with objects created be the givensupplier.static <T> Seq<T> of(T... values) Create a newSeqfrom the given values.Returns a possibly parallelStreamwith this sequence as its source.Return a newSeqwith the givenvaluesprepended.Return a newSeqwith the givenvaluesprepended.default intsize()subSeq(int start) Returns a view of the portion of this sequence between the specifiedstart, inclusive, andend, exclusive.subSeq(int start, int end) Returns a view of the portion of this sequence between the specifiedstart, inclusive, andend, exclusive.default Object[]toArray()Return an array containing all of the elements in this sequence in right order.default <B> B[]toArray(B[] array) Return an array containing all of the elements in this sequence in right order; the runtime type of the returned array is that of the specified array.default <B> B[]toArray(IntFunction<B[]> generator) Returns an array containing the elements of this sequence, using the provided generator function to allocate the returned array.toSeq()Returns aCollectorthat accumulates the input elements into a newSeq.toSeq(int maxSize) Returns aCollectorthat accumulates the lastninput elements into a newSeq.default StringCreate a string representation of the given sequence.default StringCreate a string representation of the given sequence.static <T> Seq<T> Returns a sequence backed by the specifiedseq.static <T> Seq<T> Returns a sequence backed by the specified list.static <T> Seq<T> viewOf(T[] array) Returns a fixed-size sequence backed by the specified array.Methods inherited from interface io.jenetics.util.BaseSeq
forEach, get, isEmpty, iterator, length, listIterator, nonEmpty, spliterator, stream
-
Field Details
-
EMPTY
Single instance of an emptySeq.- Since:
- 3.3
-
-
Method Details
-
apply
Return the value at the givenindex.- Specified by:
applyin interfaceIntFunction<T>- Parameters:
index- index of the element to return.- Returns:
- the value at the given
index. - Throws:
IndexOutOfBoundsException- if the index is out of rangeindex < 0 || index >= size().- Since:
- 3.9
- See Also:
-
size
- Returns:
- the size of this sequence
- See Also:
-
forAll
Tests whether a predicate holds for all elements of this sequence.- Parameters:
predicate- the predicate to use to test the elements.- Returns:
trueif the given predicate p holds for all elements of this sequence,falseotherwise.- Throws:
NullPointerException- if the givenpredicateisnull.
-
parallelStream
Returns a possibly parallelStreamwith this sequence as its source. It is allowable for this method to return a sequential stream.- Returns:
- a possibly parallel
Streamover the elements in this collection - Since:
- 3.0
-
contains
Returnstrueif this sequence contains the specified element.- Parameters:
element- element whose presence in this sequence is to be tested. The tested element can benull.- Returns:
trueif this sequence contains the specified element
-
indexOf
Returns the index of the first occurrence of the specified element in this sequence, or -1 if this sequence does not contain the element.- Parameters:
element- element to search for, can benull- Returns:
- the index of the first occurrence of the specified element in this sequence, or -1 if this sequence does not contain the element
-
indexOf
Returns the index of the first occurrence of the specified element in this sequence, or -1 if this sequence does not contain the element.- Parameters:
element- element to search for, can benullstart- the start index (inclusively) for the element search.- Returns:
- the index of the first occurrence of the specified element in this sequence, or -1 if this sequence does not contain the element
- Throws:
IndexOutOfBoundsException- for an illegal end point index value (start < 0 || start > length()).
-
indexOf
Returns the index of the first occurrence of the specified element in this sequence, or -1 if this sequence does not contain the element.- Parameters:
element- element to search for, can benullstart- the start index (inclusively) for the element search.end- the end index (exclusively) for the element search.- Returns:
- the index of the first occurrence of the specified element in this sequence, or -1 if this sequence does not contain the element
- Throws:
IndexOutOfBoundsException- for an illegal end point index value (start < 0 || end > length() || start > end).
-
indexWhere
Returns the index of the first element on which the given predicate returns
true, or -1 if the predicate returns false for every sequence element.// Finding index of first null value. final int index = seq.indexOf(o -> o == null); // Assert of no null values. assert (sequence.indexOf(o -> o == null) == -1);- Parameters:
predicate- the search predicate.- Returns:
- the index of the first element on which the given predicate
returns
true, or -1 if the predicate returnsfalsefor every sequence element. - Throws:
NullPointerException- if the givenpredicateisnull.
-
indexWhere
Returns the index of the first element on which the given predicate returns
true, or -1 if the predicate returns false for every sequence element.// Finding index of first null value. final int index = seq.indexOf(o -> o == null); // Assert of no null values. assert (sequence.indexOf(o -> o == null) == -1);- Parameters:
predicate- the search predicate.start- the search start index- Returns:
- the index of the first element on which the given predicate
returns
true, or -1 if the predicate returnsfalsefor every sequence element. - Throws:
NullPointerException- if the givenpredicateisnull.IndexOutOfBoundsException- for an illegal end point index value (start < 0 || start > length()).
-
indexWhere
Returns the index of the first element on which the given predicate returns
true, or -1 if the predicate returns false for every sequence element.// Finding index of first null value. final int index = seq.indexOf(o -> o == null); // Assert of no null values. assert (sequence.indexOf(o -> o == null) == -1);- Parameters:
predicate- the search predicate.start- the search start indexend- the search end index- Returns:
- the index of the first element on which the given predicate
returns
true, or -1 if the predicate returnsfalsefor every sequence element. - Throws:
NullPointerException- if the givenpredicateisnull.IndexOutOfBoundsException- for an illegal end point index value (start < 0 || end > length() || start > end).
-
lastIndexOf
Returns the index of the last occurrence of the specified element in this sequence, or -1 if this sequence does not contain the element.- Parameters:
element- element to search for, can benull- Returns:
- the index of the last occurrence of the specified element in this sequence, or -1 if this sequence does not contain the element
-
lastIndexOf
Returns the index of the last occurrence of the specified element in this sequence, or -1 if this sequence does not contain the element.- Parameters:
element- element to search for, can benullend- the search end index- Returns:
- the index of the last occurrence of the specified element in this sequence, or -1 if this sequence does not contain the element
- Throws:
IndexOutOfBoundsException- for an illegal end point index value (end < 0 || end > length()).
-
lastIndexOf
Returns the index of the last occurrence of the specified element in this sequence, or -1 if this sequence does not contain the element.- Parameters:
element- element to search for, can benullstart- the search start indexend- the search end index- Returns:
- the index of the last occurrence of the specified element in this sequence, or -1 if this sequence does not contain the element
- Throws:
IndexOutOfBoundsException- for an illegal end point index value (start < 0 || end > length() || start > end).
-
lastIndexWhere
Returns the index of the last element on which the given predicate returnstrue, or -1 if the predicate returns false for every sequence element.- Parameters:
predicate- the search predicate.- Returns:
- the index of the last element on which the given predicate
returns
true, or -1 if the predicate returns false for every sequence element. - Throws:
NullPointerException- if the givenpredicateisnull.
-
lastIndexWhere
Returns the index of the last element on which the given predicate returnstrue, or -1 if the predicate returns false for every sequence element.- Parameters:
predicate- the search predicate.end- the search end index- Returns:
- the index of the last element on which the given predicate
returns
true, or -1 if the predicate returns false for every sequence element. - Throws:
NullPointerException- if the givenpredicateisnull.IndexOutOfBoundsException- for an illegal end point index value (end < 0 || end > length()).
-
lastIndexWhere
Returns the index of the last element on which the given predicate returnstrue, or -1 if the predicate returns false for every sequence element.- Parameters:
predicate- the search predicate.start- the search start indexend- the search end index- Returns:
- the index of the last element on which the given predicate
returns
true, or -1 if the predicate returns false for every sequence element. - Throws:
NullPointerException- if the givenpredicateisnull.IndexOutOfBoundsException- for an illegal end point index value (start < 0 || end > length() || start > end).
-
map
Builds a new sequence by applying a function to all elements of this sequence.- Type Parameters:
B- the element type of the returned collection.- Parameters:
mapper- the function to apply to each element.- Returns:
- a new sequence of type That resulting from applying the given function f to each element of this sequence and collecting the results.
- Throws:
NullPointerException- if the elementmapperisnull.
-
append
Return a newSeqwith the givenvaluesappended.- Parameters:
values- the values to append- Returns:
- a new
Seqwith the elements ofthissequence and the givenvaluesappended. - Throws:
NullPointerException- if the givenvaluesarray isnull- Since:
- 3.4
-
append
Return a newSeqwith the givenvaluesappended.- Parameters:
values- the values to append- Returns:
- a new
Seqwith the elements ofthissequence and the givenvaluesappended. - Throws:
NullPointerException- if the givenvaluesiterable isnull- Since:
- 3.4
-
prepend
Return a newSeqwith the givenvaluesprepended.- Parameters:
values- the values to append- Returns:
- a new
Seqwith the elements ofthissequence and the givenvaluesprepended. - Throws:
NullPointerException- if the givenvaluesarray isnull- Since:
- 3.4
-
prepend
Return a newSeqwith the givenvaluesprepended.- Parameters:
values- the values to append- Returns:
- a new
Seqwith the elements ofthissequence and the givenvaluesprepended. - Throws:
NullPointerException- if the givenvaluesarray isnull- Since:
- 3.4
-
asList
Returns a fixed-size list backed by the specified sequence. (Changes to the returned list "write through" to the array.) The returned list is fixed size, serializable and implementsRandomAccess.- Returns:
- a list view of this sequence
-
toArray
Return an array containing all of the elements in this sequence in right order. The returned array will be "safe" in that no references to it are maintained by this sequence. (In other words, this method must allocate a new array.) The caller is thus free to modify the returned array.- Returns:
- an array containing all of the elements in this list in the right order
- See Also:
-
toArray
Return an array containing all of the elements in this sequence in right order; the runtime type of the returned array is that of the specified array. If this sequence fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the length of this array.If this sequence fits in the specified array with room to spare (i.e., the array has more elements than this array); the element in the array immediately following the end of this array is set to null. (This is useful in determining the length of the array only if the caller knows that the list does not contain any null elements.)
- Type Parameters:
B- the runtime type of the array to contain the sequence- Parameters:
array- the array into which the elements of this array are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.- Returns:
- an array containing the elements of this array
- Throws:
ArrayStoreException- if the runtime type of the specified array is not a super type of the runtime type of every element in this arrayNullPointerException- if the givenarrayisnull.- See Also:
-
toArray
Returns an array containing the elements of this sequence, using the provided generator function to allocate the returned array.- Type Parameters:
B- the element type of the resulting array- Parameters:
generator- a function which produces a new array of the desired type and the provided length- Returns:
- an array containing the elements in
thissequence - Throws:
ArrayStoreException- if the runtime type of the specified array is not a super type of the runtime type of every element in this arrayNullPointerException- if the givengeneratorisnull.- Since:
- 4.4
-
subSeq
Returns a view of the portion of this sequence between the specifiedstart, inclusive, andend, exclusive. (Ifstartandendare equal, the returned sequence has length zero.) The returned sequence is backed by this sequence, so non-structural changes in the returned sequence are reflected in this sequence, and vice versa.This method eliminates the need for explicit range operations (of the populationSort that commonly exist for arrays). Any operation that expects a sequence can be used as a range operation by passing a subsequence view instead of a whole sequence.
- Parameters:
start- lower end point (inclusive) of the subarray.- Returns:
- a view of the specified range within this array.
- Throws:
IndexOutOfBoundsException- for an illegal end point index value (start < 0 || start > length()).
-
subSeq
Returns a view of the portion of this sequence between the specifiedstart, inclusive, andend, exclusive. (Ifstartandendare equal, the returned sequence has length zero.) The returned sequence is backed by this sequence, so non-structural changes in the returned sequence are reflected in this array, and vice versa.This method eliminates the need for explicit range operations (of the populationSort that commonly exist for arrays). Any operation that expects an array can be used as a range operation by passing a subsequence view instead of a whole sequence.
- Parameters:
start- low-end point (inclusive) of the subsequence.end- high-end point (exclusive) of the subsequence.- Returns:
- a view of the specified range within this sequence.
- Throws:
IndexOutOfBoundsException- for an illegal end point index value (start < 0 || end > length() || start > end).
-
isSorted
Test whether the given array is sorted in ascending order.- Returns:
trueif the givenarrayis sorted in ascending order,falseotherwise.- Throws:
NullPointerException- if the given array or one of its element isnull.
-
isSorted
Test whether the given array is sorted in ascending order. The order of the array elements is defined by the given comparator.- Parameters:
comparator- the comparator which defines the order.- Returns:
trueif the givenarrayis sorted in ascending order,falseotherwise.- Throws:
NullPointerException- if the given array or one of its elements or the comparator isnull.
-
asMSeq
Return this sequence asMSeqinstance. Ifthisis not aMSeqa new seq is created.- Returns:
- a
MSeqwith this values - Since:
- 3.8
-
asISeq
Return this sequence asISeqinstance. Ifthisis not aISeqa new seq is created.- Returns:
- a
ISeqwith this values - Since:
- 3.8
-
hashCode
int hashCode()Returns the hash code value for this sequence. The hash code is defined as followed:int hashCode = 1; final Iterator<E> it = seq.iterator(); while (it.hasNext()) { final E obj = it.next(); hashCode = 31*hashCode + (obj == null ? 0 : obj.hashCode()); } -
equals
Compares the specified object with this sequence for equality. Returns true if and only if the specified object is also a sequence, both sequences have the same size, and all corresponding pairs of elements in the two sequences are equal. (Two elements e1 and e2 are equal if (e1==null ? e2==null : e1.equals(e2)).) This definition ensures that the equals method works properly across different implementations of the Seq interface. -
toString
Create a string representation of the given sequence.- Parameters:
prefix- the prefix of the string representation; e.g'['.separator- the separator of the array elements; e.g.','.suffix- the suffix of the string representation; e.g.']'.- Returns:
- the string representation of this sequence.
-
toString
Create a string representation of the given sequence.- Parameters:
separator- the separator of the array elements; e.g.','.- Returns:
- the string representation of this sequence.
-
hashCode
Unified method for calculating the hash code of everySeqimplementation. The hash code is defined as followed:int hashCode = 1; final Iterator<E> it = seq.iterator(); while (it.hasNext()) { final E obj = it.next(); hashCode = 31*hashCode + (obj == null ? 0 : obj.hashCode()); }- Parameters:
seq- the sequence to calculate the hash code for.- Returns:
- the hash code of the given sequence.
- See Also:
-
equals
Unified method for compare to sequences for equality.- Parameters:
seq- the sequence to test for equality.obj- the object to test for equality with the sequence.- Returns:
trueif the given objects are sequences and contain the same objects in the same order,falseotherwise.- See Also:
-
concat
Return a sequence whose elements are all the elements of the first element followed by all the elements of the sequence.- Type Parameters:
T- the type of the sequence elements- Parameters:
a- the first elementb- the appending sequence- Returns:
- the concatenation of the two inputs
- Throws:
NullPointerException- if one of the second arguments isnull- Since:
- 5.0
-
concat
Return a sequence whose elements are all the elements of the first sequence followed by all the elements of the vararg array.- Type Parameters:
T- the type of the sequence elements- Parameters:
a- the first sequenceb- the vararg elements- Returns:
- the concatenation of the two inputs
- Throws:
NullPointerException- if one of the arguments isnull- Since:
- 5.0
-
concat
Return a sequence whose elements are all the elements of the first sequence followed by all the elements of the second sequence.- Type Parameters:
T- the type of the sequence elements- Parameters:
a- the first sequenceb- the second sequence- Returns:
- the concatenation of the two input sequences
- Throws:
NullPointerException- if one of the arguments isnull- Since:
- 5.0
-
empty
Return an emptySeq.- Type Parameters:
T- the element type of the returnedSeq.- Returns:
- an empty
Seq. - Since:
- 3.3
-
toSeq
Returns aCollectorthat accumulates the input elements into a newSeq.- Type Parameters:
T- the type of the input elements- Returns:
- a
Collectorwhich collects all the input elements into aSeq, in encounter order
-
toSeq
Returns aCollectorthat accumulates the lastninput elements into a newSeq.- Type Parameters:
T- the type of the input elements- Parameters:
maxSize- the maximal size of the collected sequence- Returns:
- a
Collectorwhich collects maximalmaxSizeof the input elements into anISeq, in encounter order - Throws:
IllegalArgumentException- if themaxSizeis negative- Since:
- 5.0
-
of
Create a newSeqfrom the given values.- Type Parameters:
T- the element type- Parameters:
values- the array values.- Returns:
- a new
Seqwith the given values. - Throws:
NullPointerException- if thevaluesarray isnull.
-
of
Create a newSeqfrom the given values.- Type Parameters:
T- the element type- Parameters:
values- the array values.- Returns:
- a new
Seqwith the given values. - Throws:
NullPointerException- if thevaluesarray isnull.
-
of
Creates a new sequence, which is filled with objects created be the givensupplier.- Type Parameters:
T- the element type of the sequence- Parameters:
supplier- theSupplierwhich creates the elements, the returned sequence is filled withlength- the length of the returned sequence- Returns:
- a new sequence filled with elements given by the
supplier - Throws:
NegativeArraySizeException- if the givenlengthis negativeNullPointerException- if the givensupplierisnull- Since:
- 3.3
-
viewOf
Returns a sequence backed by the specifiedseq. (Changes to the given sequence (if writeable) are "write through" to the returned sequence.) This method acts as a bridge between basic sequences and sequence-based APIs.- Type Parameters:
T- the element type- Parameters:
seq- the basic sequence containing the elements- Returns:
- a sequence view of the given
seq - Throws:
NullPointerException- if the given list isnull- Since:
- 6.0
-
viewOf
Returns a sequence backed by the specified list. (Changes to the given list are "write through" to the returned sequence.) This method acts as a bridge between collection-based and sequence-based APIs.- Type Parameters:
T- the element type- Parameters:
list- the list containing the elements- Returns:
- a sequence view of the given
list - Throws:
NullPointerException- if the given list isnull- Since:
- 4.2
-
viewOf
Returns a fixed-size sequence backed by the specified array. (Changes to the given array are "write through" to the returned sequence.) This method acts as a bridge between array-based and sequence-based APIs.- Type Parameters:
T- the element type- Parameters:
array- the array containing the sequence elements- Returns:
- a sequence view of the given
array - Throws:
NullPointerException- if the given array isnull- Since:
- 4.2
-