Interface Seq<T>
-
- All Superinterfaces:
BaseSeq<T>
,IntFunction<T>
,Iterable<T>
,RandomAccess
- All Known Implementing Classes:
ArrayISeq
,ArraySeq
,CharSeq
public interface Seq<T> extends BaseSeq<T>, IntFunction<T>
General interface for a ordered, fixed sized, object sequence.
Use theasList()
method to work together with the Java Collection Framework.- Since:
- 1.0
- Version:
- 5.2
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Seq<T>
append(Iterable<? extends T> values)
Return a newSeq
with the givenvalues
appended.default Seq<T>
append(T... values)
Return a newSeq
with the givenvalues
appended.default T
apply(int index)
Return the value at the givenindex
.default ISeq<T>
asISeq()
Return this sequence asISeq
instance.default List<T>
asList()
Returns a fixed-size list backed by the specified sequence.default MSeq<T>
asMSeq()
Return this sequence asMSeq
instance.static <T> Seq<T>
concat(Seq<? extends T> a, Seq<? extends T> b)
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>
concat(Seq<? extends T> a, T... b)
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>
concat(T a, Seq<? extends T> b)
Return a sequence whose elements are all the elements of the first element followed by all the elements of the sequence.default boolean
contains(Object element)
Returnstrue
if this sequence contains the specified element.static <T> Seq<T>
empty()
Return an emptySeq
.static boolean
equals(BaseSeq<?> seq, Object obj)
Unified method for compare to sequences for equality.boolean
equals(Object object)
Compares the specified object with this sequence for equality.default boolean
forAll(Predicate<? super T> predicate)
Tests whether a predicate holds for all elements of this sequence.int
hashCode()
Returns the hash code value for this sequence.static int
hashCode(BaseSeq<?> seq)
Unified method for calculating the hash code of everySeq
implementation.default int
indexOf(Object element)
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
indexOf(Object element, int start)
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
indexOf(Object element, int start, int end)
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>
map(Function<? super T,? extends B> mapper)
Builds a new sequence by applying a function to all elements of this sequence.static <T> Seq<T>
of(Iterable<? extends T> values)
Create a newSeq
from the given values.static <T> Seq<T>
of(Supplier<? extends T> supplier, int length)
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.default Stream<T>
parallelStream()
Returns a possibly parallelStream
with this sequence as its source.Seq<T>
prepend(Iterable<? extends T> values)
Return a newSeq
with the givenvalues
prepended.default Seq<T>
prepend(T... values)
Return a newSeq
with the givenvalues
prepended.default int
size()
Seq<T>
subSeq(int start)
Returns a view of the portion of this sequence between the specifiedstart
, inclusive, andend
, exclusive.Seq<T>
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.static <T> Collector<T,?,Seq<T>>
toSeq()
Returns aCollector
that accumulates the input elements into a newSeq
.static <T> Collector<T,?,Seq<T>>
toSeq(int maxSize)
Returns aCollector
that accumulates the lastn
input elements into a newSeq
.default String
toString(String separator)
Create a string representation of the given sequence.default String
toString(String prefix, String separator, String suffix)
Create a string representation of the given sequence.static <T> Seq<T>
viewOf(BaseSeq<? extends T> seq)
Returns a sequence backed by the specifiedseq
.static <T> Seq<T>
viewOf(List<? extends T> list)
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
-
-
-
-
Method Detail
-
apply
default T apply(int index)
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:
BaseSeq.get(int)
-
size
default int size()
- Returns:
- the size of this sequence
- See Also:
BaseSeq.length()
-
forAll
default boolean forAll(Predicate<? super T> predicate)
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
default Stream<T> 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
default boolean contains(Object element)
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
default int indexOf(Object element)
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
default int indexOf(Object element, int start)
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
default int indexOf(Object element, int start, int end)
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
default int indexWhere(Predicate<? super T> predicate)
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
default int indexWhere(Predicate<? super T> predicate, int start)
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
default int indexWhere(Predicate<? super T> predicate, int start, int end)
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
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.- 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
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.- 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
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.- 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
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.- 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
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.- 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
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.- 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
<B> Seq<B> map(Function<? super T,? extends B> mapper)
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
default Seq<T> append(T... values)
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
Seq<T> append(Iterable<? extends T> values)
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
default Seq<T> prepend(T... values)
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
Seq<T> prepend(Iterable<? extends T> values)
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
default List<T> 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
default Object[] 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:
Collection.toArray()
-
toArray
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. 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:
Collection.toArray(Object[])
-
toArray
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.- 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
Seq<T> subSeq(int start)
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
- low 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
Seq<T> subSeq(int start, int end)
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
default boolean 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
default boolean isSorted(Comparator<? super T> comparator)
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
default MSeq<T> 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
default ISeq<T> 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()); }
- Overrides:
hashCode
in classObject
- Returns:
- the hash code value for this list
- See Also:
List.hashCode()
,hashCode(BaseSeq)
-
equals
boolean equals(Object object)
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.- Overrides:
equals
in classObject
- Parameters:
object
- the object to be compared for equality with this sequence.- Returns:
true
if the specified object is equal to this sequence,false
otherwise.- See Also:
List.equals(Object)
,equals(BaseSeq, Object)
-
toString
default String toString(String prefix, String separator, String suffix)
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
default String toString(String separator)
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
static int hashCode(BaseSeq<?> seq)
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:
hashCode()
,List.hashCode()
-
equals
static boolean equals(BaseSeq<?> seq, Object obj)
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:
equals(Object)
-
concat
static <T> Seq<T> concat(T a, Seq<? extends T> b)
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
static <T> Seq<T> concat(Seq<? extends T> a, T... b)
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
static <T> Seq<T> concat(Seq<? extends T> a, Seq<? extends T> b)
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
static <T> Seq<T> empty()
Return an emptySeq
.- Type Parameters:
T
- the element type of the returnedSeq
.- Returns:
- an empty
Seq
. - Since:
- 3.3
-
toSeq
static <T> Collector<T,?,Seq<T>> 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
static <T> Collector<T,?,Seq<T>> toSeq(int maxSize)
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
@SafeVarargs static <T> Seq<T> of(T... values)
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
static <T> Seq<T> of(Iterable<? extends T> values)
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
static <T> Seq<T> of(Supplier<? extends T> supplier, int length)
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
static <T> Seq<T> viewOf(BaseSeq<? extends T> seq)
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
static <T> Seq<T> viewOf(List<? extends T> list)
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
static <T> Seq<T> viewOf(T[] array)
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
-
-