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
- Author:
- Franz Wilhelmstötter
- See Also:
ISeq- Implementation Note:
- This implementation is not thread safe. All
ISeqandMSeqinstances 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 newSeqwith the givenvaluesappended.default MSeq<T>append(T... values)Return a newSeqwith the givenvaluesappended.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 newMSeqfrom the values of the givenSeq.static <T> MSeq<T>of(Iterable<? extends T> values)Create a newMSeqfrom 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 newMSeqfrom the given values.static <T> MSeq<T>ofLength(int length)Create a newMSeqwith the givenlength.MSeq<T>prepend(Iterable<? extends T> values)Return a newSeqwith the givenvaluesprepended.default MSeq<T>prepend(T... values)Return a newSeqwith the givenvaluesprepended.default MSeq<T>reverse()Reverses the order of the elements this sequence (in place).voidset(int index, T value)Set thevalueat 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 thearrayusing the givenRandomobject.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 voidswap(int i, int j)Swap the elements at the two positions.default voidswap(int start, int end, MSeq<T> other, int otherStart)Swap a given range with a range of the same size with another array.default voidswap(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 aCollectorthat 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:SeqReturns 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 thevalueat 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:
thissequence.
-
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:
thissequence.
-
setAll
default MSeq<T> setAll(T[] values)
Fill the sequence with the given values.- Parameters:
values- the first initial values of this sequence- Returns:
thissequence.
-
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:
thissequence.- Throws:
NullPointerException- if the givenfactoryisnull.
-
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 ofthisrange, inclusively.end- the end index ofthisrange, exclusively.other- the other array to swap the elements with.otherStart- the start index of theotherarray.- Throws:
IndexOutOfBoundsException- ifstart > endor 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 theothersequence isnull- Since:
- 4.0
-
shuffle
default MSeq<T> shuffle()
Randomize thearrayusing theRandomobject currently registered in theRandomRegistryclass. 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 thearrayusing the givenRandomobject. The used shuffling algorithm is from D. Knuth TAOCP, Seminumerical Algorithms, Third edition, page 142, Algorithm S (Selection sampling technique).- Parameters:
random- theRandomobject 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 aClassCastExceptionfor any elementse1ande2in the sequence).If the specified comparator is
nullthen all elements in this list must implement theComparableinterface 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- theComparatorused to compare sequence elements. Anullvalue indicates that the elements' Comparable natural ordering should be used- Returns:
thissequence- 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:
thissequence- 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 aClassCastExceptionfor any elementse1ande2in the sequence).If the specified comparator is
nullthen all elements in this list must implement theComparableinterface and the elements' Comparable natural ordering should be used.- Parameters:
start- the start index where to start sorting (inclusively)comparator- theComparatorused to compare sequence elements. Anullvalue indicates that the elements' Comparable natural ordering should be used- Returns:
thissequence- 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:
thissequence- 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 aClassCastExceptionfor any elementse1ande2in the sequence).If the specified comparator is
nullthen all elements in this list must implement theComparableinterface and the elements' Comparable natural ordering should be used.- Parameters:
comparator- theComparatorused to compare sequence elements. Anullvalue indicates that the elements' Comparable natural ordering should be used- Returns:
thissequence- 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:
thissequence- 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:
listIteratorin 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:SeqReturns a view of the portion of this sequence between the specifiedstart, inclusive, andend, exclusive. (Ifstartandendare 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:SeqReturns a view of the portion of this sequence between the specifiedstart, inclusive, andend, exclusive. (Ifstartandendare 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:SeqBuilds a new sequence by applying a function to all elements of this sequence.- Specified by:
mapin 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:SeqReturn a newSeqwith the givenvaluesappended.
-
append
MSeq<T> append(Iterable<? extends T> values)
Description copied from interface:SeqReturn a newSeqwith the givenvaluesappended.
-
prepend
default MSeq<T> prepend(T... values)
Description copied from interface:SeqReturn a newSeqwith the givenvaluesprepended.
-
prepend
MSeq<T> prepend(Iterable<? extends T> values)
Description copied from interface:SeqReturn a newSeqwith the givenvaluesprepended.
-
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 aCollectorthat accumulates the input elements into a newMSeq.- Type Parameters:
T- the type of the input elements- Returns:
- a
Collectorwhich collects all the input elements into aMSeq, in encounter order
-
ofLength
static <T> MSeq<T> ofLength(int length)
Create a newMSeqwith 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 givenlengthis negative
-
of
@SafeVarargs static <T> MSeq<T> of(T... values)
Create a newMSeqfrom the given values.- Type Parameters:
T- the element type- Parameters:
values- the array values.- Returns:
- a new
Meqwith the given values. - Throws:
NullPointerException- if thevaluesarray isnull.
-
of
static <T> MSeq<T> of(Iterable<? extends T> values)
Create a newMSeqfrom the given values.- Type Parameters:
T- the element type- Parameters:
values- the array values.- Returns:
- a new
MSeqwith the given values. - Throws:
NullPointerException- if thevaluesobject 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- 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
-
of
static <T> MSeq<T> of(Seq<? extends T> values)
Create a newMSeqfrom the values of the givenSeq.- Type Parameters:
T- the element type- Parameters:
values- the array values.- Returns:
- an new
MSeqwith the given values - Throws:
NullPointerException- if thevaluesarray isnull.
-
-