public interface MSeq<T> extends Seq<T>, Copyable<MSeq<T>>
Implementation note:
This implementation is not thread safe. All ISeq
and MSeq
instances created by toISeq()
and subSeq(int)
,
respectively, must be protected by the same lock, when they are accessed
(get/set) by different threads.
ISeq
Modifier and Type | Field and Description |
---|---|
static MSeq<?> |
EMPTY
Single instance of an empty
MSeq . |
Modifier and Type | Method and Description |
---|---|
MSeq<T> |
append(Iterable<? extends T> values)
Return a new
Seq with the given values appended. |
default MSeq<T> |
append(T... values)
Return a new
Seq with the given values appended. |
default List<T> |
asList()
Returns a fixed-size list backed by the specified sequence.
|
static <T> MSeq<T> |
empty()
Return an empty
MSeq . |
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(Iterable<? extends T> values)
Create a new
MSeq from the given values. |
static <T> MSeq<T> |
of(Seq<T> values)
Create a new
MSeq from the values of the given Seq . |
static <T> MSeq<T> |
of(Supplier<? extends T> supplier,
int length)
Creates a new sequence, which is filled with objects created be the given
supplier . |
static <T> MSeq<T> |
of(T... values)
Create a new
MSeq from the given values. |
static <T> MSeq<T> |
ofLength(int length)
Create a new
MSeq with the given length . |
MSeq<T> |
prepend(Iterable<? extends T> values)
Return a new
Seq with the given values prepended. |
default MSeq<T> |
prepend(T... values)
Return a new
Seq with the given values prepended. |
void |
set(int index,
T value)
Set the
value at the given index . |
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 the
array using the given Random object. |
MSeq<T> |
subSeq(int start)
Returns a view of the portion of this sequence between the specified
start , inclusive, and end , exclusive. |
MSeq<T> |
subSeq(int start,
int end)
Returns a view of the portion of this sequence between the specified
start , inclusive, and end , 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.
|
ISeq<T> |
toISeq()
Return a read-only projection of this sequence.
|
static <T> Collector<T,?,MSeq<T>> |
toMSeq()
Returns a
Collector that accumulates the input elements into a
new MSeq . |
contains, equals, equals, forAll, get, hashCode, hashCode, indexOf, indexOf, indexOf, indexWhere, indexWhere, indexWhere, isEmpty, isSorted, isSorted, iterator, lastIndexOf, lastIndexOf, lastIndexOf, lastIndexWhere, lastIndexWhere, lastIndexWhere, length, parallelStream, size, spliterator, stream, toArray, toArray, toSeq, toString, toString
default List<T> asList()
Seq
RandomAccess
.void set(int index, T value)
value
at the given index
.index
- the index of the new value.value
- the new value.IndexOutOfBoundsException
- if the index is out of range
(index < 0 || index >= size())
.default MSeq<T> setAll(Iterator<? extends T> it)
it
- the iterator of the values to fill this sequence.this
sequence.default MSeq<T> setAll(Iterable<? extends T> values)
values
- the values to fill this sequence.this
sequence.default MSeq<T> setAll(T[] values)
values
- the first initial values of this sequencethis
sequence.default MSeq<T> fill(Supplier<? extends T> supplier)
supplier
- the value factory.this
sequence.NullPointerException
- if the given factory
is null
.default void swap(int i, int j)
i
- the index of the first element.j
- the index of the second element.IndexOutOfBoundsException
- if i < 0 || j >= length()
.default void swap(int start, int end, MSeq<T> other, int otherStart)
start end | | this: +---+---+---+---+---+---+---+---+---+---+---+---+ +---------------+ +---------------+ other: +---+---+---+---+---+---+---+---+---+---+---+---+ | otherStart
start
- the start index of this
range, inclusively.end
- the end index of this
range, exclusively.other
- the other array to swap the elements with.otherStart
- the start index of the other
array.IndexOutOfBoundsException
- if start > end
or
if start < 0 || end >= this.length() || otherStart < 0 ||
otherStart + (end - start) >= other.length()
default MSeq<T> shuffle()
array
using the Random
object currently
registered in the RandomRegistry
class. The used shuffling
algorithm is from D. Knuth TAOCP, Seminumerical Algorithms, Third edition,
page 142, Algorithm S (Selection sampling technique).default MSeq<T> shuffle(Random random)
array
using the given Random
object. The used
shuffling algorithm is from D. Knuth TAOCP, Seminumerical Algorithms,
Third edition, page 142, Algorithm S (Selection sampling technique).random
- the Random
object to use for randomize.NullPointerException
- if the random object is null
.default ListIterator<T> listIterator()
listIterator
in interface Seq<T>
MSeq<T> subSeq(int start, int end)
Seq
start
, inclusive, and end
, exclusive. (If start
and end
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.
MSeq<T> subSeq(int start)
Seq
start
, inclusive, and end
, exclusive. (If start
and end
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.
<B> MSeq<B> map(Function<? super T,? extends B> mapper)
Seq
map
in interface Seq<T>
B
- the element type of the returned collection.mapper
- the function to apply to each element.default MSeq<T> append(T... values)
Seq
Seq
with the given values
appended.MSeq<T> append(Iterable<? extends T> values)
Seq
Seq
with the given values
appended.default MSeq<T> prepend(T... values)
Seq
Seq
with the given values
prepended.MSeq<T> prepend(Iterable<? extends T> values)
Seq
Seq
with the given values
prepended.ISeq<T> toISeq()
ISeq
.static <T> Collector<T,?,MSeq<T>> toMSeq()
Collector
that accumulates the input elements into a
new MSeq
.T
- the type of the input elementsCollector
which collects all the input elements into a
MSeq
, in encounter orderstatic <T> MSeq<T> ofLength(int length)
MSeq
with the given length
.T
- the element type of the new MSeq
.length
- the length of the created MSeq
.NegativeArraySizeException
- if the given length
is
negative@SafeVarargs static <T> MSeq<T> of(T... values)
MSeq
from the given values.of
in interface Seq<T>
T
- the element typevalues
- the array values.Meq
with the given values.NullPointerException
- if the values
array is null
.static <T> MSeq<T> of(Iterable<? extends T> values)
MSeq
from the given values.of
in interface Seq<T>
T
- the element typevalues
- the array values.MSeq
with the given values.NullPointerException
- if the values
object is
null
.static <T> MSeq<T> of(Supplier<? extends T> supplier, int length)
supplier
.of
in interface Seq<T>
T
- the element type of the sequencesupplier
- the Supplier
which creates the elements, the
returned sequence is filled withlength
- the length of the returned sequencesupplier
NegativeArraySizeException
- if the given length
is
negativeNullPointerException
- if the given supplier
is
null
static <T> MSeq<T> of(Seq<T> values)
MSeq
from the values of the given Seq
.T
- the element typevalues
- the array values.MSeq
with the given valuesNullPointerException
- if the values
array is null
.© 2007-2016 Franz Wilhelmstötter (2016-04-24 10:25)