Interface MSeq<T>
-
- All Superinterfaces:
BaseSeq<T>
,Copyable<MSeq<T>>
,IntFunction<T>
,Iterable<T>
,RandomAccess
,Seq<T>
public interface MSeq<T> extends Seq<T>, Copyable<MSeq<T>>
Mutable, ordered, fixed sized sequence.- Since:
- 1.0
- Version:
- 5.2
- See Also:
ISeq
- Implementation Note:
- This implementation is not thread safe. All
ISeq
andMSeq
instances created bytoISeq()
andsubSeq(int)
, respectively, must be protected by the same lock, when they are accessed (get/set) by different threads.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description MSeq<T>
append(Iterable<? extends T> values)
Return a newSeq
with the givenvalues
appended.default MSeq<T>
append(T... values)
Return a newSeq
with the givenvalues
appended.default List<T>
asList()
Returns a fixed-size list backed by the specified sequence.static <T> MSeq<T>
concat(MSeq<? extends T> a, MSeq<? 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> MSeq<T>
concat(MSeq<? 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> MSeq<T>
concat(T a, MSeq<? extends T> b)
Return a sequence whose elements are all the elements of the first element followed by all the elements of the sequence.static <T> MSeq<T>
empty()
Return an emptyMSeq
.default MSeq<T>
fill(Supplier<? extends T> supplier)
Fill the sequence with values generated by the given factory.default ListIterator<T>
listIterator()
Returns a list iterator over the elements in this sequence (in proper sequence).<B> MSeq<B>
map(Function<? super T,? extends B> mapper)
Builds a new sequence by applying a function to all elements of this sequence.static <T> MSeq<T>
of(Seq<? extends T> values)
Create a newMSeq
from the values of the givenSeq
.static <T> MSeq<T>
of(Iterable<? extends T> values)
Create a newMSeq
from the given values.static <T> MSeq<T>
of(Supplier<? extends T> supplier, int length)
Creates a new sequence, which is filled with objects created be the givensupplier
.static <T> MSeq<T>
of(T... values)
Create a newMSeq
from the given values.static <T> MSeq<T>
ofLength(int length)
Create a newMSeq
with the givenlength
.MSeq<T>
prepend(Iterable<? extends T> values)
Return a newSeq
with the givenvalues
prepended.default MSeq<T>
prepend(T... values)
Return a newSeq
with the givenvalues
prepended.default MSeq<T>
reverse()
Reverses the order of the elements this sequence (in place).void
set(int index, T value)
Set thevalue
at the givenindex
.default MSeq<T>
setAll(Iterable<? extends T> values)
Fills the sequence with values of the given iterable.default MSeq<T>
setAll(Iterator<? extends T> it)
Fills the sequence with values of the given iterator.default MSeq<T>
setAll(T[] values)
Fill the sequence with the given values.default MSeq<T>
shuffle()
default MSeq<T>
shuffle(Random random)
Randomize thearray
using the givenRandom
object.default MSeq<T>
sort()
Sorts this sequence according to the natural order of the elements.default MSeq<T>
sort(int start)
Sorts this sequence according to the natural order of the elements.default MSeq<T>
sort(int start, int end)
Sorts this sequence according to the natural order of the elements.MSeq<T>
sort(int start, int end, Comparator<? super T> comparator)
Sorts this sequence according to the order induced by the specifiedComparator
.default MSeq<T>
sort(int start, Comparator<? super T> comparator)
Sorts this sequence according to the order induced by the specifiedComparator
.default MSeq<T>
sort(Comparator<? super T> comparator)
Sorts this sequence according to the order induced by the specifiedComparator
.MSeq<T>
subSeq(int start)
Returns a view of the portion of this sequence between the specifiedstart
, inclusive, andend
, exclusive.MSeq<T>
subSeq(int start, int end)
Returns a view of the portion of this sequence between the specifiedstart
, inclusive, andend
, exclusive.default void
swap(int i, int j)
Swap the elements at the two positions.default void
swap(int start, int end, MSeq<T> other, int otherStart)
Swap a given range with a range of the same size with another array.default void
swap(int index, MSeq<T> other)
Swap the elements at the same position.ISeq<T>
toISeq()
Return a read-only projection of this sequence.static <T> Collector<T,?,MSeq<T>>
toMSeq()
Returns aCollector
that accumulates the input elements into a newMSeq
.-
Methods inherited from interface io.jenetics.util.BaseSeq
get, isEmpty, iterator, length, nonEmpty, spliterator, stream
-
Methods inherited from interface io.jenetics.util.Seq
apply, asISeq, asMSeq, contains, equals, forAll, hashCode, indexOf, indexOf, indexOf, indexWhere, indexWhere, indexWhere, isSorted, isSorted, lastIndexOf, lastIndexOf, lastIndexOf, lastIndexWhere, lastIndexWhere, lastIndexWhere, parallelStream, size, toArray, toArray, toArray, toString, toString
-
-
-
-
Method Detail
-
asList
default List<T> asList()
Description copied from interface:Seq
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
.
-
set
void set(int index, T value)
Set thevalue
at the givenindex
.- Parameters:
index
- the index of the new value.value
- the new value.- Throws:
IndexOutOfBoundsException
- if the index is out of range(index < 0 || index >= size())
.
-
setAll
default MSeq<T> setAll(Iterator<? extends T> it)
Fills the sequence with values of the given iterator.- Parameters:
it
- the iterator of the values to fill this sequence.- Returns:
this
sequence.
-
setAll
default MSeq<T> setAll(Iterable<? extends T> values)
Fills the sequence with values of the given iterable.- Parameters:
values
- the values to fill this sequence.- Returns:
this
sequence.
-
setAll
default MSeq<T> setAll(T[] values)
Fill the sequence with the given values.- Parameters:
values
- the first initial values of this sequence- Returns:
this
sequence.
-
fill
default MSeq<T> fill(Supplier<? extends T> supplier)
Fill the sequence with values generated by the given factory.- Parameters:
supplier
- the value factory.- Returns:
this
sequence.- Throws:
NullPointerException
- if the givenfactory
isnull
.
-
swap
default void swap(int i, int j)
Swap the elements at the two positions.- Parameters:
i
- the index of the first element.j
- the index of the second element.- Throws:
IndexOutOfBoundsException
- ifi < 0 || j >= length()
.
-
swap
default void swap(int start, int end, MSeq<T> other, int otherStart)
Swap a given range with a range of the same size with another array.start end | | this: +---+---+---+---+---+---+---+---+---+---+---+---+ +---------------+ +---------------+ other: +---+---+---+---+---+---+---+---+---+---+---+---+ | otherStart
- Parameters:
start
- the start index ofthis
range, inclusively.end
- the end index ofthis
range, exclusively.other
- the other array to swap the elements with.otherStart
- the start index of theother
array.- Throws:
IndexOutOfBoundsException
- ifstart > end
or ifstart < 0 || end >= this.length() || otherStart < 0 || otherStart + (end - start) >= other.length()
-
swap
default void swap(int index, MSeq<T> other)
Swap the elements at the same position.- Parameters:
index
- the index of swapped element.other
- the other array to swap the elements with.- Throws:
IndexOutOfBoundsException
- ifindex < 0 || index >= this.length() || index >= other.length()
.NullPointerException
- if theother
sequence isnull
- Since:
- 4.0
-
shuffle
default MSeq<T> shuffle()
Randomize thearray
using theRandom
object currently registered in theRandomRegistry
class. The used shuffling algorithm is from D. Knuth TAOCP, Seminumerical Algorithms, Third edition, page 142, Algorithm S (Selection sampling technique).- Returns:
- this shuffled sequence
-
shuffle
default MSeq<T> shuffle(Random random)
Randomize thearray
using the givenRandom
object. The used shuffling algorithm is from D. Knuth TAOCP, Seminumerical Algorithms, Third edition, page 142, Algorithm S (Selection sampling technique).- Parameters:
random
- theRandom
object to use for randomize.- Returns:
- this shuffled sequence
- Throws:
NullPointerException
- if the random object isnull
.
-
sort
MSeq<T> sort(int start, int end, Comparator<? super T> comparator)
Sorts this sequence according to the order induced by the specifiedComparator
.All elements in this sequence must be mutually comparable using the specified comparator (that is,
c.compare(e1, e2)
must not throw aClassCastException
for any elementse1
ande2
in the sequence).If the specified comparator is
null
then all elements in this list must implement theComparable
interface and the elements' Comparable natural ordering should be used.- Parameters:
start
- the start index where to start sorting (inclusively)end
- the end index where to stop sorting (exclusively)comparator
- theComparator
used to compare sequence elements. Anull
value indicates that the elements' Comparable natural ordering should be used- Returns:
this
sequence- Throws:
ClassCastException
- if the sequence contains elements that are not mutually comparable using the specified comparator
-
sort
default MSeq<T> sort(int start, int end)
Sorts this sequence according to the natural order of the elements.- Parameters:
start
- the start index where to start sorting (inclusively)end
- the end index where to stop sorting (exclusively)- Returns:
this
sequence- Throws:
ClassCastException
- if the sequence contains elements that are not mutually comparable using the specified comparator
-
sort
default MSeq<T> sort(int start, Comparator<? super T> comparator)
Sorts this sequence according to the order induced by the specifiedComparator
.All elements in this sequence must be mutually comparable using the specified comparator (that is,
c.compare(e1, e2)
must not throw aClassCastException
for any elementse1
ande2
in the sequence).If the specified comparator is
null
then all elements in this list must implement theComparable
interface and the elements' Comparable natural ordering should be used.- Parameters:
start
- the start index where to start sorting (inclusively)comparator
- theComparator
used to compare sequence elements. Anull
value indicates that the elements' Comparable natural ordering should be used- Returns:
this
sequence- Throws:
ClassCastException
- if the sequence contains elements that are not mutually comparable using the specified comparator
-
sort
default MSeq<T> sort(int start)
Sorts this sequence according to the natural order of the elements.- Parameters:
start
- the start index where to start sorting (inclusively)- Returns:
this
sequence- Throws:
ClassCastException
- if the sequence contains elements that are not mutually comparable using the specified comparator
-
sort
default MSeq<T> sort(Comparator<? super T> comparator)
Sorts this sequence according to the order induced by the specifiedComparator
.All elements in this sequence must be mutually comparable using the specified comparator (that is,
c.compare(e1, e2)
must not throw aClassCastException
for any elementse1
ande2
in the sequence).If the specified comparator is
null
then all elements in this list must implement theComparable
interface and the elements' Comparable natural ordering should be used.- Parameters:
comparator
- theComparator
used to compare sequence elements. Anull
value indicates that the elements' Comparable natural ordering should be used- Returns:
this
sequence- Throws:
ClassCastException
- if the sequence contains elements that are not mutually comparable using the specified comparator
-
sort
default MSeq<T> sort()
Sorts this sequence according to the natural order of the elements.- Returns:
this
sequence- Throws:
ClassCastException
- if the sequence contains elements that are not mutually comparable using the specified comparator
-
reverse
default MSeq<T> reverse()
Reverses the order of the elements this sequence (in place).- Returns:
- this sequence with reverse order or the elements
-
listIterator
default ListIterator<T> listIterator()
Returns a list iterator over the elements in this sequence (in proper sequence).- Specified by:
listIterator
in interfaceBaseSeq<T>
- Returns:
- a list iterator over the elements in this list (in proper sequence)
-
subSeq
MSeq<T> subSeq(int start, int end)
Description copied from interface:Seq
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.
-
subSeq
MSeq<T> subSeq(int start)
Description copied from interface:Seq
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.
-
map
<B> MSeq<B> map(Function<? super T,? extends B> mapper)
Description copied from interface:Seq
Builds a new sequence by applying a function to all elements of this sequence.- Specified by:
map
in interfaceSeq<T>
- 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.
-
append
default MSeq<T> append(T... values)
Description copied from interface:Seq
Return a newSeq
with the givenvalues
appended.
-
append
MSeq<T> append(Iterable<? extends T> values)
Description copied from interface:Seq
Return a newSeq
with the givenvalues
appended.
-
prepend
default MSeq<T> prepend(T... values)
Description copied from interface:Seq
Return a newSeq
with the givenvalues
prepended.
-
prepend
MSeq<T> prepend(Iterable<? extends T> values)
Description copied from interface:Seq
Return a newSeq
with the givenvalues
prepended.
-
toISeq
ISeq<T> toISeq()
Return a read-only projection of this sequence. Changes to the original sequence will not influence the returnedISeq
.- Returns:
- a read-only projection of this sequence
-
concat
static <T> MSeq<T> concat(T a, MSeq<? 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> MSeq<T> concat(MSeq<? 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> MSeq<T> concat(MSeq<? extends T> a, MSeq<? 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> MSeq<T> empty()
Return an emptyMSeq
.- Type Parameters:
T
- the element type of the returnedMSeq
.- Returns:
- an empty
MSeq
.
-
toMSeq
static <T> Collector<T,?,MSeq<T>> toMSeq()
Returns aCollector
that accumulates the input elements into a newMSeq
.- Type Parameters:
T
- the type of the input elements- Returns:
- a
Collector
which collects all the input elements into aMSeq
, in encounter order
-
ofLength
static <T> MSeq<T> ofLength(int length)
Create a newMSeq
with the givenlength
.- Type Parameters:
T
- the element type of the newMSeq
.- Parameters:
length
- the length of the createdMSeq
.- Returns:
- the new mutable sequence.
- Throws:
NegativeArraySizeException
- if the givenlength
is negative
-
of
@SafeVarargs static <T> MSeq<T> of(T... values)
Create a newMSeq
from the given values.- Type Parameters:
T
- the element type- Parameters:
values
- the array values.- Returns:
- a new
Meq
with the given values. - Throws:
NullPointerException
- if thevalues
array isnull
.
-
of
static <T> MSeq<T> of(Iterable<? extends T> values)
Create a newMSeq
from the given values.- Type Parameters:
T
- the element type- Parameters:
values
- the array values.- Returns:
- a new
MSeq
with the given values. - Throws:
NullPointerException
- if thevalues
object isnull
.
-
of
static <T> MSeq<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
-
of
static <T> MSeq<T> of(Seq<? extends T> values)
Create a newMSeq
from the values of the givenSeq
.- Type Parameters:
T
- the element type- Parameters:
values
- the array values.- Returns:
- an new
MSeq
with the given values - Throws:
NullPointerException
- if thevalues
array isnull
.
-
-