- All Superinterfaces:
BaseSeq<T>
,IntFunction<T>
,Iterable<T>
,RandomAccess
- All Known Implementing Classes:
ArrayISeq
,ArrayMSeq
,ArraySeq
,CharSeq
,Empty.EmptyISeq
,Empty.EmptyMSeq
Use the
asList()
method to work together with the
Java Collection Framework.- Since:
- 1.0
- Version:
- 5.2
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionReturn a newSeq
with the givenvalues
appended.Return a newSeq
with the givenvalues
appended.default T
apply
(int index) Return the value at the givenindex
.asISeq()
Return this sequence asISeq
instance.asList()
Returns a fixed-size list backed by the specified sequence.asMSeq()
Return this sequence asMSeq
instance.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 boolean
Returnstrue
if this sequence contains the specified element.static <T> Seq<T>
empty()
Return an emptySeq
.static boolean
Unified method for compare to sequences for equality.boolean
Compares the specified object with this sequence for equality.default boolean
Tests whether a predicate holds for all elements of this sequence.int
hashCode()
Returns the hash code value for this sequence.static int
Unified method for calculating the hash code of everySeq
implementation.default int
Returns the index of the first occurrence of the specified element in this sequence, or -1 if this sequence does not contain the element.default int
Returns the index of the first occurrence of the specified element in this sequence, or -1 if this sequence does not contain the element.default int
Returns the index of the first occurrence of the specified element in this sequence, or -1 if this sequence does not contain the element.default int
indexWhere
(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 int
indexWhere
(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 int
indexWhere
(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 boolean
isSorted()
Test whether the given array is sorted in ascending order.default boolean
isSorted
(Comparator<? super T> comparator) Test whether the given array is sorted in ascending order.default int
lastIndexOf
(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 int
lastIndexOf
(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 int
lastIndexOf
(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 int
lastIndexWhere
(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 int
lastIndexWhere
(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 int
lastIndexWhere
(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 newSeq
from 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 newSeq
from the given values.Returns a possibly parallelStream
with this sequence as its source.Return a newSeq
with the givenvalues
prepended.Return a newSeq
with the givenvalues
prepended.default int
size()
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 aCollector
that accumulates the input elements into a newSeq
.toSeq
(int maxSize) Returns aCollector
that accumulates the lastn
input elements into a newSeq
.default String
Create a string representation of the given sequence.default String
Create 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:
apply
in 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:
true
if the given predicate p holds for all elements of this sequence,false
otherwise.- Throws:
NullPointerException
- if the givenpredicate
isnull
.
-
parallelStream
Returns a possibly parallelStream
with this sequence as its source. It is allowable for this method to return a sequential stream.- Returns:
- a possibly parallel
Stream
over the elements in this collection - Since:
- 3.0
-
contains
Returnstrue
if this sequence contains the specified element.- Parameters:
element
- element whose presence in this sequence is to be tested. The tested element can benull
.- Returns:
true
if 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 benull
start
- 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 benull
start
- 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 returnsfalse
for every sequence element. - Throws:
NullPointerException
- if the givenpredicate
isnull
.
-
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 returnsfalse
for every sequence element. - Throws:
NullPointerException
- if the givenpredicate
isnull
.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 returnsfalse
for every sequence element. - Throws:
NullPointerException
- if the givenpredicate
isnull
.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 benull
end
- 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 benull
start
- 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 givenpredicate
isnull
.
-
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 givenpredicate
isnull
.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 givenpredicate
isnull
.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 elementmapper
isnull
.
-
append
Return a newSeq
with the givenvalues
appended.- Parameters:
values
- the values to append- Returns:
- a new
Seq
with the elements ofthis
sequence and the givenvalues
appended. - Throws:
NullPointerException
- if the givenvalues
array isnull
- Since:
- 3.4
-
append
Return a newSeq
with the givenvalues
appended.- Parameters:
values
- the values to append- Returns:
- a new
Seq
with the elements ofthis
sequence and the givenvalues
appended. - Throws:
NullPointerException
- if the givenvalues
iterable isnull
- Since:
- 3.4
-
prepend
Return a newSeq
with the givenvalues
prepended.- Parameters:
values
- the values to append- Returns:
- a new
Seq
with the elements ofthis
sequence and the givenvalues
prepended. - Throws:
NullPointerException
- if the givenvalues
array isnull
- Since:
- 3.4
-
prepend
Return a newSeq
with the givenvalues
prepended.- Parameters:
values
- the values to append- Returns:
- a new
Seq
with the elements ofthis
sequence and the givenvalues
prepended. - Throws:
NullPointerException
- if the givenvalues
array 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 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 givenarray
isnull
.- 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
this
sequence - 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 givengenerator
isnull
.- Since:
- 4.4
-
subSeq
Returns a view of the portion of this sequence between the specifiedstart
, inclusive, andend
, exclusive. (Ifstart
andend
are equal, the returned sequence has the 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 an sequence can be used as a range operation by passing an sub sequence view instead of an whole sequence.
- Parameters:
start
- lower end point (inclusive) of the sub array.- 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. (Ifstart
andend
are equal, the returned sequence has the 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 an sub sequence view instead of an whole sequence.
- Parameters:
start
- low end point (inclusive) of the sub sequence.end
- high end point (exclusive) of the sub sequence.- 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:
true
if the givenarray
is sorted in ascending order,false
otherwise.- Throws:
NullPointerException
- if the given array or one of it's 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:
true
if the givenarray
is sorted in ascending order,false
otherwise.- Throws:
NullPointerException
- if the given array or one of it's element or the comparator isnull
.
-
asMSeq
Return this sequence asMSeq
instance. Ifthis
is not aMSeq
a new seq is created.- Returns:
- a
MSeq
with this values - Since:
- 3.8
-
asISeq
Return this sequence asISeq
instance. Ifthis
is not aISeq
a new seq is created.- Returns:
- a
ISeq
with 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 sequence 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 everySeq
implementation. 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:
true
if the given objects are sequences and contain the same objects in the same order,false
otherwise.- 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 aCollector
that accumulates the input elements into a newSeq
.- Type Parameters:
T
- the type of the input elements- Returns:
- a
Collector
which collects all the input elements into aSeq
, in encounter order
-
toSeq
Returns aCollector
that accumulates the lastn
input elements into a newSeq
.- Type Parameters:
T
- the type of the input elements- Parameters:
maxSize
- the maximal size of the collected sequence- Returns:
- a
Collector
which collects maximalmaxSize
of the input elements into anISeq
, in encounter order - Throws:
IllegalArgumentException
- if themaxSize
is negative- Since:
- 5.0
-
of
Create a newSeq
from the given values.- Type Parameters:
T
- the element type- Parameters:
values
- the array values.- Returns:
- a new
Seq
with the given values. - Throws:
NullPointerException
- if thevalues
array isnull
.
-
of
Create a newSeq
from the given values.- Type Parameters:
T
- the element type- Parameters:
values
- the array values.- Returns:
- a new
Seq
with the given values. - Throws:
NullPointerException
- if thevalues
array 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
- theSupplier
which 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 givenlength
is negativeNullPointerException
- if the givensupplier
isnull
- 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 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 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 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
-