de.caff.generics

## Interface MutableBooleanIndexable

- All Superinterfaces:
    BooleanIndexable, Copyable<MutableBooleanIndexable>, java.lang.Iterable<java.lang.Boolean>, PrimitiveBooleanIterable, Sizeable
  All Known Implementing Classes:
    MutableBooleanIndexable.Base

      public interface MutableBooleanIndexable
      extends BooleanIndexable, Copyable<MutableBooleanIndexable>

  Primitive boolean indexable with fixed length but mutable content. This may be used as a substitute for `boolean[]` as it eg allows read-only views or transparent views of subsets of the array.
  Since:
    November 01, 2019
  Author:
    Rammi

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Interface and Description
    --- | ---
    `static class` | `MutableBooleanIndexable.Base` Abstract base class which provides useful implementations for `Object.equals(Object)`, `Object.hashCode()`, `Object.toString()`.

    - ### Nested classes/interfaces inherited from interface de.caff.generics.BooleanIndexable

      `BooleanIndexable.EntryConsumer`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static MutableBooleanIndexable.Base` | `EMPTY` Empty mutable indexable.

    - ### Fields inherited from interface de.caff.generics.BooleanIndexable

      `SINGLE_FALSE, SINGLE_TRUE`

    - ### Fields inherited from interface de.caff.generics.PrimitiveBooleanIterable

      `EMPTY_BOOLEAN_ITERATOR`

    - ### Fields inherited from interface de.caff.generics.Sizeable

      `NULL`

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Default Methods
    Modifier and Type | Method and Description
    --- | ---
    `default java.util.List<java.lang.Boolean>` | `asList()` View this indexable as a standard list.
    `static MutableBooleanIndexable.Base` | `based(MutableBooleanIndexable indexable)` View any mutable boolean indexable as a base boolean indexable.
    `static <IN> MutableBooleanIndexable.Base` | `copy(java.util.Collection<IN> collection, java.util.function.Predicate<IN> copier)` Create a mutable indexable which is initialized from copied elements of a given collection.
    `static MutableBooleanIndexable.Base` | `copyOf(java.util.Collection<? extends java.lang.Boolean> collection)` Create a mutable indexable which is initialized from a given collection.
    `static MutableBooleanIndexable.Base` | `empty()`
    `static MutableBooleanIndexable.Base` | `fromArray(boolean... elements)` Create a mutable indexable which is initialized from elements of the given array.
    `static MutableBooleanIndexable.Base` | `fromArray(boolean[] elements, int startIndex, int length)` Create a mutable indexable which is initialized from elements of the given array.
    `static MutableBooleanIndexable.Base` | `fromBooleanIndexable(BooleanIndexable indexable)` Return a mutable boolean indexable initialized with the content of a standard boolean indexable.
    `static MutableBooleanIndexable.Base` | `fromIndexable(Indexable<? extends java.lang.Boolean> indexable)` Create a mutable indexable which is the copy of a standard indexable.
    `static <B> MutableBooleanIndexable.Base` | `fromIndexable(Indexable<B> indexable, java.util.function.Predicate<? super B> converter)` Create a mutable indexable which is the copy of a standard indexable.
    `static MutableBooleanIndexable.Base` | `fromIterable(int size, java.lang.Iterable<? extends java.lang.Boolean> iter)` Create a mutable indexable from an iterable or a part of it.
    `default MutableBooleanIndexable` | `getCopy()` Get a copy of this object.
    `default MutableBooleanIndexable.Base` | `headSet(int toIndex)` Create an indexable subset from the last elements of this indexable set.
    `static MutableBooleanIndexable.Base` | `init(int size, boolean value)` Create a mutable
    `static MutableBooleanIndexable.Base` | `init(int size, java.util.function.BooleanSupplier creator)` Initialize a mutable indexable to a given size.
    `static MutableBooleanIndexable.Base` | `initByIndex(int size, java.util.function.IntPredicate producer)` Get a mutable boolean indexable of a given size which contains elements created by index.
    `default void` | `initByIndex(IntPredicate1 setter)` Set all values of this boolean indexable by index.
    `default MutableBooleanIndexable.Base` | `reverse()` Get this indexable but with inverted order.
    `void` | `set(int index, boolean value)` Set the element at the given index.
    `default int` | `setFrom(java.lang.Iterable<? extends java.lang.Boolean> iterable)` Set the values of this mutable boolean indexable one after the other from the given Number iterable until either the iterable is emptied or `Sizeable.size()` elements are set.
    `default int` | `setFrom(java.lang.Iterable<? extends java.lang.Boolean> iterable, int startIndex, int numElements)` Set the values of this mutable boolean indexable one after the other from the given iterable until either the iterable is emptied or `numElements` elements are set.
    `default void` | `setMulti(int from, int len, boolean value)` Set multiple elements to the same value.
    `default void` | `shuffle(java.util.Random random)` Randomize the content of this mutable indexable.
    `default MutableBooleanIndexable.Base` | `subSet(int fromIndex, int toIndex)` Get an indexable subset.
    `default void` | `swap(int idx1, int idx2)` Swap the values at two indices.
    `default void` | `swyp(int idx1, int idx2)` Swap the values at two indices using Pythonesque indices.
    `default MutableBooleanIndexable.Base` | `sybSet(int fromIndex, int toIndex)` Get an indexable subset.
    `default void` | `syt(int index, boolean value)` Pythonesque set.
    `default MutableBooleanIndexable.Base` | `tailSet(int fromIndex)` Create an indexable subset from the last elements of this indexable set.
    `static MutableBooleanIndexable.Base` | `viewArray(boolean[] array)` Mutable indexable view which operates on the given array.
    `static <T> MutableBooleanIndexable.Base` | `viewIndexable(Indexable<T> indexable, java.util.function.Predicate<? super T> getter, BooleanSetter<? super T> setter)` View a generic indexable as a mutable boolean indexable by accessing a boolean property of the elements of the underlying generic indexable.
    `static MutableBooleanIndexable.Base` | `viewList(java.util.List<java.lang.Boolean> list)` Mutable indexable view which operates on the given array.

    - ### Methods inherited from interface de.caff.generics.BooleanIndexable

      `addAllTo, addToArray, addToArray, asBase, asCollection, asIndexable, booleanIterator, booleanIterator, compare, emptyIndexable, equal, equal, firstMatch, foldLeft, forEachBoolEntry, frozen, get, getMod, gyt, hash, indexes, initByIndex, intIndexes, isEmpty, iterator, lastMatch, listIterator, nextMatch, previousMatch, rotated, singleton, toArray, toList, toString, view, viewArray, viewArray, viewByIndex, viewIndexable, viewIndexable, viewIndexable, viewList, viewList, viewList, withAppendedValue, withCachedHash, withExchangedValueAt, withInsertedValueAt, withRemovedValueAt, withSwappedValuesAt`

    - ### Methods inherited from interface de.caff.generics.PrimitiveBooleanIterable

      `and, containsBool, containsFalse, containsTrue, forEachBool, forEachBooleanFragile, forEachBoolFragile, or, xor`

    - ### Methods inherited from interface java.lang.Iterable

      `forEach, spliterator`

    - ### Methods inherited from interface de.caff.generics.Sizeable

      `size`

    - ### Methods inherited from interface de.caff.generics.Copyable

      `copy`

- - ### Field Detail

    - #### EMPTY

          static final MutableBooleanIndexable.Base EMPTY

      Empty mutable indexable. Use `empty()` instead.

  - ### Method Detail

    - #### set

          void set(int index,
                   boolean value)

      Set the element at the given index.
      Parameters:
        `index` - index between `0` and `size() - 1`
        `value` - value to put to the given index

    - #### syt

          default void syt(int index,
                           boolean value)

      Pythonesque set. This allows to access elements from the back by using negative indexes, e.g. `-1` references the last element, `-2` its predecessor, and so on.
      Parameters:
        `index` - index between `-size()` and `size() - 1`
        `value` - value to put to the given index

    - #### setFrom

          default int setFrom(@NotNull
                              java.lang.Iterable<? extends java.lang.Boolean> iterable)

      Set the values of this mutable boolean indexable one after the other from the given Number iterable until either the iterable is emptied or `Sizeable.size()` elements are set.
      Parameters:
        `iterable` - iterable from which this indexable is filled
      Returns:
        number of elements set

    - #### setFrom

          default int setFrom(@NotNull
                              java.lang.Iterable<? extends java.lang.Boolean> iterable,
                              int startIndex,
                              int numElements)

      Set the values of this mutable boolean indexable one after the other from the given iterable until either the iterable is emptied or `numElements` elements are set.
      Parameters:
        `iterable` - iterable from which this indexable is filled
        `startIndex` - start index where the setting begins
        `numElements` - number of elements to set
      Returns:
        number of elements set

    - #### setMulti

          default void setMulti(int from,
                                int len,
                                boolean value)

      Set multiple elements to the same value.
      Parameters:
        `from` - first index to be set (Pythonesque)
        `len` - number of elements to be set (non-negative)
        `value` - value to be set

    - #### swap

          default void swap(int idx1,
                            int idx2)

      Swap the values at two indices.
      Parameters:
        `idx1` - first index
        `idx2` - second index

    - #### swyp

          default void swyp(int idx1,
                            int idx2)

      Swap the values at two indices using Pythonesque indices.
      Parameters:
        `idx1` - first index (`Pythonesque`)
        `idx2` - second index (`Pythonesque`)

    - #### shuffle

          default void shuffle(@NotNull
                               java.util.Random random)

      Randomize the content of this mutable indexable. This will reorder the elements randomly.
      Parameters:
        `random` - random number generator

    - #### subSet

          @NotNull
          default MutableBooleanIndexable.Base subSet(int fromIndex,
                                                               int toIndex)

      Description copied from interface: `BooleanIndexable`
      Get an indexable subset. The subset includes indices `fromIndex` to `toIndex - 1`.
      Specified by:
        `subSet` in interface `BooleanIndexable`
      Parameters:
        `fromIndex` - start index of sub set
        `toIndex` - index after last index
      Returns:
        indxable subset view of this indexable

    - #### sybSet

          @NotNull
          default MutableBooleanIndexable.Base sybSet(int fromIndex,
                                                               int toIndex)

      Description copied from interface: `BooleanIndexable`
      Get an indexable subset. This is the Pythonesque version which allows negative indexes.
      Specified by:
        `sybSet` in interface `BooleanIndexable`
      Parameters:
        `fromIndex` - start index of sub set
        `toIndex` - end index of sub set
      Returns:
        indexable subset view of this indexable set

    - #### tailSet

          @NotNull
          default MutableBooleanIndexable.Base tailSet(int fromIndex)

      Description copied from interface: `BooleanIndexable`
      Create an indexable subset from the last elements of this indexable set. This already allows Pythonesquew indexing.
      Specified by:
        `tailSet` in interface `BooleanIndexable`
      Parameters:
        `fromIndex` - index to start with, negative counts from the back
      Returns:
        indexable subset view of this indexable set

    - #### headSet

          @NotNull
          default MutableBooleanIndexable.Base headSet(int toIndex)

      Description copied from interface: `BooleanIndexable`
      Create an indexable subset from the last elements of this indexable set. This already allows Pythonesquew indexing.
      Specified by:
        `headSet` in interface `BooleanIndexable`
      Parameters:
        `toIndex` - index one after the end (equal to the length of the returned set), negative counts from the back
      Returns:
        indexable subset view of this indexable set

    - #### reverse

          @NotNull
          default MutableBooleanIndexable.Base reverse()

      Description copied from interface: `BooleanIndexable`
      Get this indexable but with inverted order.
      Specified by:
        `reverse` in interface `BooleanIndexable`
      Returns:
        a view to this indexable which accesses the elements in reverse order

    - #### initByIndex

          default void initByIndex(@NotNull
                                   IntPredicate1 setter)

      Set all values of this boolean indexable by index.
      Parameters:
        `setter` - setter which provides the value to be set for a given index

    - #### asList

          @NotNull
          default java.util.List<java.lang.Boolean> asList()

      View this indexable as a standard list. Overwritten to allow for modifications. The returned list will allow usage of the `List.set(int, Object)` method, but neither any adding nor deleting methods. Standard sorting algorithms will work on the returned list as a sorting algorithm is expected to neither move nor add elements.
      Specified by:
        `asList` in interface `BooleanIndexable`
      Returns:
        list allowing setting elements
      See Also:
        `BooleanIndexable.toList()`

    - #### getCopy

          @NotNull
          default MutableBooleanIndexable getCopy()

      Description copied from interface: `Copyable`
      Get a copy of this object. Immutable objects are allowed to return themselves. The copy needs not to be of the same class, it just has to fulfill the type restriction.
      Specified by:
        `getCopy` in interface `Copyable<MutableBooleanIndexable>`
      Returns:
        independent copy of this object

    - #### based

          @NotNull
          static MutableBooleanIndexable.Base based(@NotNull
                                                             MutableBooleanIndexable indexable)

      View any mutable boolean indexable as a base boolean indexable. The latter provides various standard methods for comparison, output and hanshing.
      Parameters:
        `indexable` - mutqable boolean indexable to view as a `MutableBooleanIndexable.Base` mutable boolean indexable
      Returns:
        base view of given indexable, or the indexable itself if it is already a Base

    - #### init

          @NotNull
          static MutableBooleanIndexable.Base init(int size,
                                                            @NotNull
                                                            java.util.function.BooleanSupplier creator)

      Initialize a mutable indexable to a given size.
      Parameters:
        `size` - size of indexable
        `creator` - creator for the initial elements
      Returns:
        mutable indexable with the given size
      See Also:
        `init(int, boolean)`, `init(int, BooleanSupplier)`

    - #### copyOf

          @NotNull
          static MutableBooleanIndexable.Base copyOf(@NotNull
                                                              java.util.Collection<? extends java.lang.Boolean> collection)

      Create a mutable indexable which is initialized from a given collection.
      Parameters:
        `collection` - collection
      Returns:
        mutable indexable

    - #### copy

          @NotNull
          static <IN> MutableBooleanIndexable.Base copy(@NotNull
                                                                 java.util.Collection<IN> collection,
                                                                 @NotNull
                                                                 java.util.function.Predicate<IN> copier)

      Create a mutable indexable which is initialized from copied elements of a given collection.
      Type Parameters:
        `IN` - incoming element type
      Parameters:
        `collection` - collection
        `copier` - element copier
      Returns:
        mutable indexable

    - #### empty

          @NotNull
          static MutableBooleanIndexable.Base empty()

    - #### fromArray

          @NotNull
          static MutableBooleanIndexable.Base fromArray(@NotNull
                                                                 boolean... elements)

      Create a mutable indexable which is initialized from elements of the given array.
      Parameters:
        `elements` - elements
      Returns:
        mutable indexable independent of `elements`

    - #### fromArray

          @NotNull
          static MutableBooleanIndexable.Base fromArray(@NotNull
                                                                 boolean[] elements,
                                                                 int startIndex,
                                                                 int length)

      Create a mutable indexable which is initialized from elements of the given array.
      Parameters:
        `elements` - array of elements
        `startIndex` - index of first element used in the returned indxable
        `length` - length number of elements used in the returned indexable
      Returns:
        mutable indexable independnet of `eleements`

    - #### viewArray

          @NotNull
          static MutableBooleanIndexable.Base viewArray(@NotNull
                                                                 boolean[] array)

      Mutable indexable view which operates on the given array. Any changes done by the returned indexable will be forwarded to the array.
      Specified by:
        `viewArray` in interface `BooleanIndexable`
      Parameters:
        `array` - array
      Returns:
        mutable indexable view of the given array

    - #### viewList

          @NotNull
          static MutableBooleanIndexable.Base viewList(@NotNull
                                                                java.util.List<java.lang.Boolean> list)

      Mutable indexable view which operates on the given array. Any changes done by the returned indexable will be forwarded to the list.
      Parameters:
        `list` - list
      Returns:
        mutable indexable view of the given list

    - #### fromIndexable

          @NotNull
          static MutableBooleanIndexable.Base fromIndexable(@NotNull
                                                                     Indexable<? extends java.lang.Boolean> indexable)

      Create a mutable indexable which is the copy of a standard indexable.
      Parameters:
        `indexable` - standard indexable
      Returns:
        mutable indexable initialize from the standard indexable

    - #### fromIndexable

          @NotNull
          static <B> MutableBooleanIndexable.Base fromIndexable(@NotNull
                                                                         Indexable<B> indexable,
                                                                         @NotNull
                                                                         java.util.function.Predicate<? super B> converter)

      Create a mutable indexable which is the copy of a standard indexable. This especieally allows to copy each element during the initialization.
      Type Parameters:
        `B` - element type of incoming idexable
      Parameters:
        `indexable` - base indexable
        `converter` - converter from base indexable type to result element type,
      Returns:
        mutable indexable

    - #### viewIndexable

          @NotNull
          static <T> MutableBooleanIndexable.Base viewIndexable(@NotNull
                                                                         Indexable<T> indexable,
                                                                         @NotNull
                                                                         java.util.function.Predicate<? super T> getter,
                                                                         @NotNull
                                                                         BooleanSetter<? super T> setter)

      View a generic indexable as a mutable boolean indexable by accessing a boolean property of the elements of the underlying generic indexable.

      This is useful if you have complex items, but are interested into only one (boolean) property of each item.

      Type Parameters:
        `T` - element type of the underlying indexable
      Parameters:
        `indexable` - underlying generic indexable
        `getter` - function used to extract the property of interest
        `setter` - procedure used to set the property of interest
      Returns:
        mutable boolean indexable view of the underlying indexable

    - #### fromBooleanIndexable

          @NotNull
          static MutableBooleanIndexable.Base fromBooleanIndexable(@NotNull
                                                                            BooleanIndexable indexable)

      Return a mutable boolean indexable initialized with the content of a standard boolean indexable.
      Parameters:
        `indexable` - boolean indexable
      Returns:
        mutable indexable initialized with the values of the given boolean indexable

    - #### fromIterable

          @NotNull
          static MutableBooleanIndexable.Base fromIterable(int size,
                                                                    @NotNull
                                                                    java.lang.Iterable<? extends java.lang.Boolean> iter)

      Create a mutable indexable from an iterable or a part of it.
      Parameters:
        `size` - maximum size of returned indexable
        `iter` - iterable used for initializing the indexable
      Returns:
        mutable indexable

    - #### init

          @NotNull
          static MutableBooleanIndexable.Base init(int size,
                                                            boolean value)

      Create a mutable
      Specified by:
        `init` in interface `BooleanIndexable`
      Parameters:
        `size` - required size of returned mutable boolean indexable
        `value` - initial value of all elements
      Returns:
        mutable boolean indexable of the given size initialized with `value`
      See Also:
        `init(int, BooleanSupplier)`

    - #### initByIndex

          @NotNull
          static MutableBooleanIndexable.Base initByIndex(int size,
                                                                   @NotNull
                                                                   java.util.function.IntPredicate producer)

      Get a mutable boolean indexable of a given size which contains elements created by index.
      Parameters:
        `size` - size of the returned indexable
        `producer` - producer which is called with an index and expected to return the associated value
      Returns:
        a mutable boolean indexable with the given size with elements initialized by calling the `producer`