Class ArrayMSeq<T>

java.lang.Object
ArraySeq<T>
ArrayMSeq<T>
All Implemented Interfaces:
BaseSeq<T>, Copyable<MSeq<T>>, MSeq<T>, Seq<T>, Serializable, Iterable<T>, IntFunction<T>, RandomAccess

public class ArrayMSeq<T> extends ArraySeq<T> implements MSeq<T>
Since:
1.4
Version:
3.4
See Also:
  • Constructor Details

  • Method Details

    • copy

      public MSeq<T> copy()
      Description copied from interface: Copyable
      Return a new copy of type T.
      Specified by:
      copy in interface Copyable<T>
      Returns:
      a new copy of type T.
    • iterator

      public Iterator<T> iterator()
      Specified by:
      iterator in interface BaseSeq<T>
      Specified by:
      iterator in interface Iterable<T>
    • listIterator

      Description copied from interface: MSeq
      Returns a list iterator over the elements in this sequence (in proper sequence).
      Specified by:
      listIterator in interface BaseSeq<T>
      Specified by:
      listIterator in interface MSeq<T>
      Returns:
      a list iterator over the elements in this list (in proper sequence)
    • set

      public void set(int index, T value)
      Description copied from interface: MSeq
      Set the value at the given index.
      Specified by:
      set in interface MSeq<T>
      Parameters:
      index - the index of the new value.
      value - the new value.
    • setAll

      public MSeq<T> setAll(Iterator<? extends T> it)
      Description copied from interface: MSeq
      Fills the sequence with values of the given iterator.
      Specified by:
      setAll in interface MSeq<T>
      Parameters:
      it - the iterator of the values to fill this sequence.
      Returns:
      this sequence.
    • setAll

      public MSeq<T> setAll(Iterable<? extends T> values)
      Description copied from interface: MSeq
      Fills the sequence with values of the given iterable.
      Specified by:
      setAll in interface MSeq<T>
      Parameters:
      values - the values to fill this sequence.
      Returns:
      this sequence.
    • setAll

      public MSeq<T> setAll(T[] values)
      Description copied from interface: MSeq
      Fill the sequence with the given values.
      Specified by:
      setAll in interface MSeq<T>
      Parameters:
      values - the first initial values of this sequence
      Returns:
      this sequence.
    • fill

      public MSeq<T> fill(Supplier<? extends T> supplier)
      Description copied from interface: MSeq
      Fill the sequence with values generated by the given factory.
      Specified by:
      fill in interface MSeq<T>
      Parameters:
      supplier - the value factory.
      Returns:
      this sequence.
    • sort

      public ArrayMSeq<T> sort(int start, int end, Comparator<? super T> comparator)
      Description copied from interface: MSeq
      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.

      Specified by:
      sort in interface MSeq<T>
      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
    • shuffle

      public MSeq<T> shuffle(RandomGenerator random)
      Description copied from interface: MSeq
      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).
      Specified by:
      shuffle in interface MSeq<T>
      Parameters:
      random - the RandomGenerator object to use for randomize.
      Returns:
      this shuffled sequence
    • swap

      public void swap(int i, int j)
      Description copied from interface: MSeq
      Swap the elements at the two positions.
      Specified by:
      swap in interface MSeq<T>
      Parameters:
      i - the index of the first element.
      j - the index of the second element.
    • swap

      public void swap(int start, int end, MSeq<T> other, int otherStart)
      Description copied from interface: MSeq
      Swap a given range with a range of the same size with another array.
                  start                end
                    |                   |
       this:  +---+---+---+---+---+---+---+---+---+---+---+---+
                    +---------------+
                                +---------------+
       other: +---+---+---+---+---+---+---+---+---+---+---+---+
                                |
                            otherStart
       
      Specified by:
      swap in interface MSeq<T>
      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.
    • checkIndex

      protected void checkIndex(int start, int end, int otherStart, int otherLength)
    • subSeq

      public 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 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.

      Specified by:
      subSeq in interface MSeq<T>
      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

      public 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 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.

      Specified by:
      subSeq in interface MSeq<T>
      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

      public <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 MSeq<T>
      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

      public 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 MSeq<T>
      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

      public 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 MSeq<T>
      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

      public ISeq<T> toISeq()
      Description copied from interface: MSeq
      Return a read-only projection of this sequence. Changes to the original sequence will not influence the returned ISeq.
      Specified by:
      toISeq in interface MSeq<T>
      Returns:
      a read-only projection of this sequence