Interface MSeq<T>

All Superinterfaces:
BaseSeq<T>, Copyable<MSeq<T>>, IntFunction<T>, Iterable<T>, RandomAccess, Seq<T>
All Known Implementing Classes:
ArrayMSeq, Empty.EmptyMSeq

public interface MSeq<T> extends Seq<T>, Copyable<MSeq<T>>
Mutable, ordered, fixed sized sequence.
Since:
1.0
Version:
5.2
See Also:
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.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final MSeq<?>
    Single instance of an empty MSeq.
  • Method Summary

    Modifier and Type
    Method
    Description
    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>
    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>
    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>
    Returns a list iterator over the elements in this sequence (in a 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 new MSeq from the values of the given Seq.
    static <T> MSeq<T>
    of(Iterable<? extends T> values)
    Create a new MSeq 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 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.
    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.
    default MSeq<T>
    Reverses the order of the elements this sequence (in place).
    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>
    Randomize the array using the RandomGenerator object currently registered in the RandomRegistry class.
    default MSeq<T>
    Randomize the array using the given RandomGenerator object.
    default MSeq<T>
    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.
    sort(int start, int end, Comparator<? super T> comparator)
    Sorts this sequence according to the order induced by the specified Comparator.
    default MSeq<T>
    sort(int start, Comparator<? super T> comparator)
    Sorts this sequence according to the order induced by the specified Comparator.
    default MSeq<T>
    sort(Comparator<? super T> comparator)
    Sorts this sequence according to the order induced by the specified Comparator.
    subSeq(int start)
    Returns a view of the portion of this sequence between the specified start, inclusive, and end, exclusive.
    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.
    default void
    swap(int index, MSeq<T> other)
    Swap the elements at the same position.
    Return a read-only projection of this sequence.
    static <T> Collector<T,?,MSeq<T>>
    Returns a Collector that accumulates the input elements into a new MSeq.

    Methods inherited from interface io.jenetics.util.BaseSeq

    forEach, get, isEmpty, iterator, length, nonEmpty, spliterator, stream

    Methods inherited from interface io.jenetics.util.Copyable

    copy
  • Field Details

    • EMPTY

      static final MSeq<?> EMPTY
      Single instance of an empty MSeq.
  • Method Details

    • 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 implements RandomAccess.
      Specified by:
      asList in interface Seq<T>
      Returns:
      a list view of this sequence
    • set

      void set(int index, T value)
      Set the value at the given index.
      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 given factory is null.
    • 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 - if i < 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 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.
      Throws:
      IndexOutOfBoundsException - if start > end or if start < 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 - if index < 0 || index >= this.length() || index >= other.length().
      NullPointerException - if the other sequence is null
      Since:
      4.0
    • shuffle

      default MSeq<T> shuffle()
      Randomize the array using the RandomGenerator 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).
      Returns:
      this shuffled sequence
    • shuffle

      default MSeq<T> shuffle(RandomGenerator random)
      Randomize the array using the given RandomGenerator object. The used shuffling algorithm is from D. Knuth TAOCP, Seminumerical Algorithms, Third edition, page 142, Algorithm S (Selection sampling technique).
      Parameters:
      random - the RandomGenerator object to use for randomize.
      Returns:
      this shuffled sequence
      Throws:
      NullPointerException - if the random object is null.
    • sort

      MSeq<T> sort(int start, int end, Comparator<? super T> comparator)
      Sorts this sequence according to the order induced by the specified Comparator.

      All elements in this sequence must be mutually comparable using the specified comparator (that is, c.compare(e1, e2) must not throw a ClassCastException for any elements e1 and e2 in the sequence).

      If the specified comparator is null then all elements in this list must implement the Comparable 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 - the Comparator used to compare sequence elements. A null 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 specified Comparator.

      All elements in this sequence must be mutually comparable using the specified comparator (that is, c.compare(e1, e2) must not throw a ClassCastException for any elements e1 and e2 in the sequence).

      If the specified comparator is null then all elements in this list must implement the Comparable interface and the elements' Comparable natural ordering should be used.

      Parameters:
      start - the start index where to start sorting (inclusively)
      comparator - the Comparator used to compare sequence elements. A null 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 specified Comparator.

      All elements in this sequence must be mutually comparable using the specified comparator (that is, c.compare(e1, e2) must not throw a ClassCastException for any elements e1 and e2 in the sequence).

      If the specified comparator is null then all elements in this list must implement the Comparable interface and the elements' Comparable natural ordering should be used.

      Parameters:
      comparator - the Comparator used to compare sequence elements. A null 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

      Returns a list iterator over the elements in this sequence (in a proper sequence).
      Specified by:
      listIterator in interface BaseSeq<T>
      Returns:
      a list iterator over the elements in this list (in a 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 specified start, inclusive, and end, exclusive. (If start and end are equal, the returned sequence has 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 a subsequence view instead of a whole sequence.

      Specified by:
      subSeq in interface Seq<T>
      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.
    • subSeq

      MSeq<T> subSeq(int start)
      Description copied from interface: Seq
      Returns a view of the portion of this sequence between the specified start, inclusive, and end, exclusive. (If start and end are equal, the returned sequence has 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 a sequence can be used as a range operation by passing a sub-sequence view instead of a whole sequence.

      Specified by:
      subSeq in interface Seq<T>
      Parameters:
      start - lower end point (inclusive) of the sub array.
      Returns:
      a view of the specified range within this array.
    • 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 interface Seq<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 new Seq with the given values appended.
      Specified by:
      append in interface Seq<T>
      Parameters:
      values - the values to append
      Returns:
      a new Seq with the elements of this sequence and the given values appended.
    • append

      MSeq<T> append(Iterable<? extends T> values)
      Description copied from interface: Seq
      Return a new Seq with the given values appended.
      Specified by:
      append in interface Seq<T>
      Parameters:
      values - the values to append
      Returns:
      a new Seq with the elements of this sequence and the given values appended.
    • prepend

      default MSeq<T> prepend(T... values)
      Description copied from interface: Seq
      Return a new Seq with the given values prepended.
      Specified by:
      prepend in interface Seq<T>
      Parameters:
      values - the values to append
      Returns:
      a new Seq with the elements of this sequence and the given values prepended.
    • prepend

      MSeq<T> prepend(Iterable<? extends T> values)
      Description copied from interface: Seq
      Return a new Seq with the given values prepended.
      Specified by:
      prepend in interface Seq<T>
      Parameters:
      values - the values to append
      Returns:
      a new Seq with the elements of this sequence and the given values prepended.
    • toISeq

      Return a read-only projection of this sequence. Changes to the original sequence will not influence the returned ISeq.
      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 element
      b - the appending sequence
      Returns:
      the concatenation of the two inputs
      Throws:
      NullPointerException - if one of the second arguments is null
      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 sequence
      b - the vararg elements
      Returns:
      the concatenation of the two inputs
      Throws:
      NullPointerException - if one of the arguments is null
      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 sequence
      b - the second sequence
      Returns:
      the concatenation of the two input sequences
      Throws:
      NullPointerException - if one of the arguments is null
      Since:
      5.0
    • empty

      static <T> MSeq<T> empty()
      Return an empty MSeq.
      Type Parameters:
      T - the element type of the returned MSeq.
      Returns:
      an empty MSeq.
    • toMSeq

      static <T> Collector<T,?,MSeq<T>> toMSeq()
      Returns a Collector that accumulates the input elements into a new MSeq.
      Type Parameters:
      T - the type of the input elements
      Returns:
      a Collector which collects all the input elements into a MSeq, in encounter order
    • ofLength

      static <T> MSeq<T> ofLength(int length)
      Create a new MSeq with the given length.
      Type Parameters:
      T - the element type of the new MSeq.
      Parameters:
      length - the length of the created MSeq.
      Returns:
      the new mutable sequence.
      Throws:
      NegativeArraySizeException - if the given length is negative
    • of

      @SafeVarargs static <T> MSeq<T> of(T... values)
      Create a new MSeq 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 the values array is null.
    • of

      static <T> MSeq<T> of(Iterable<? extends T> values)
      Create a new MSeq 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 the values object is null.
    • of

      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.
      Type Parameters:
      T - the element type of the sequence
      Parameters:
      supplier - the Supplier which creates the elements, the returned sequence is filled with
      length - the length of the returned sequence
      Returns:
      a new sequence filled with elements given by the supplier
      Throws:
      NegativeArraySizeException - if the given length is negative
      NullPointerException - if the given supplier is null
      Since:
      3.3
    • of

      static <T> MSeq<T> of(Seq<? extends T> values)
      Create a new MSeq from the values of the given Seq.
      Type Parameters:
      T - the element type
      Parameters:
      values - the array values.
      Returns:
      a new MSeq with the given values
      Throws:
      NullPointerException - if the values array is null.