public interface BooleanIndexable extends PrimitiveBooleanIterable, Sizeable
The EMPTY
constant or emptyIndexable()
method provide the same
useful return value to indicate emptiness.
Simple implementations should extend BooleanIndexable.Base
because
that provides useful implementations for standard Object methods and implements
Comparable
.
Modifier and Type | Interface and Description |
---|---|
static class |
BooleanIndexable.Base
Abstract base class which provides useful implementations
for
Object.equals(Object) , Object.hashCode() ,
Object.toString() . |
static interface |
BooleanIndexable.EntryConsumer
Consumer for index-value pairs with
int values. |
Modifier and Type | Field and Description |
---|---|
static BooleanIndexable.Base |
EMPTY
An empty indexable.
|
static BooleanIndexable |
SINGLE_FALSE
Boolean indexable with a single
false value. |
static BooleanIndexable |
SINGLE_TRUE
Boolean indexable with a single
false value. |
EMPTY_BOOLEAN_ITERATOR
Modifier and Type | Method and Description |
---|---|
default void |
addAllTo(java.util.Collection<? super java.lang.Boolean> collection)
Add all elements of this indexable to the given collection.
|
default int |
addToArray(boolean[] array,
int pos)
Add the content of this indexable to the given array.
|
default int |
addToArray(boolean[] array,
int arrayPos,
int index,
int length)
Add a part of the content of this indexable to the given array.
|
default BooleanIndexable.Base |
asBase()
Make this boolean indexable usable as a class with defined standard Object methods.
|
default java.util.Collection<java.lang.Boolean> |
asCollection()
Get a view on this indexable as an unmodifiable collection.
|
default Indexable<java.lang.Boolean> |
asIndexable()
Get a view of this indexable as a standard object-based indexable.
|
default java.util.List<java.lang.Boolean> |
asList()
Get a view on this indexable as an unmodifiable list.
|
default PrimitiveBooleanIterator |
booleanIterator()
Get an primitive boolean iterator.
|
default PrimitiveBooleanIterator |
booleanIterator(int from,
int to)
Get a boolean iterator from the given sub set.
|
static int |
compare(BooleanIndexable indexable1,
BooleanIndexable indexable2)
Compare two boolean indexables.
|
static BooleanIndexable.Base |
emptyIndexable()
Get an empty indexable set.
|
static boolean |
equal(BooleanIndexable indexable1,
BooleanIndexable indexable2)
Are two boolean indexables equal?
|
static boolean |
equal(BooleanIndexable indexable1,
java.lang.Object indexable2)
Are two boolean indexables equal?
|
default int |
firstMatch(BooleanPredicate1 check)
Get the first index for which the given check is fulfilled.
|
default boolean |
foldLeft(boolean initialValue,
BooleanOperator2 foldOperation)
Go over all values and do a cumulative calculation.
|
default void |
forEachBoolEntry(BooleanIndexable.EntryConsumer consumer)
Call an entry consumer foreach entry in this indexable.
|
default BooleanIndexable |
frozen()
Get a frozen version of this indexable.
|
boolean |
get(int index)
Get the element at the given index.
|
default boolean |
getMod(int index)
Get an element modulo size.
|
default boolean |
gyt(int index)
Pythonesque get.
|
static int |
hash(BooleanIndexable indexable)
Calculate a hashcode for a boolean indexable.
|
default BooleanIndexable.Base |
headSet(int toIndex)
Create an indexable subset from the last elements of this indexable set.
|
default java.lang.Iterable<java.lang.Integer> |
indexes()
Get the indexes of this indexable as an iterable range.
|
static BooleanIndexable.Base |
init(int size,
boolean value)
Get a boolean indexable of a given size which always returns the same value.
|
static BooleanIndexable |
initByIndex(int size,
IntPredicate1 producer)
Get a boolean indexable of a given size which returns elements created by index.
|
default IntIndexable |
intIndexes()
Get the indexes of this indexable as an integer indexable.
|
default boolean |
isEmpty()
Is this indexable empty?
|
default java.util.Iterator<java.lang.Boolean> |
iterator()
Returns an iterator over elements of type
T . |
default int |
lastMatch(BooleanPredicate1 check)
Get the last index for which the given check is fulfilled.
|
default java.util.ListIterator<java.lang.Boolean> |
listIterator()
Returns a list iterator over elements of type
T . |
default int |
nextMatch(int startIndex,
BooleanPredicate1 check)
Get the next index for which the given check is fulfilled.
|
default int |
previousMatch(int startIndex,
BooleanPredicate1 check)
Get the previous index for which the given check is fulfilled.
|
default BooleanIndexable.Base |
reverse()
Get this indexable but with inverted order.
|
default BooleanIndexable |
rotated(int steps)
Get a rotated view of this boolean indexable.
|
static BooleanIndexable.Base |
singleton(boolean value)
View a single boolean value as a boolean indexable of size 1.
|
default BooleanIndexable.Base |
subSet(int fromIndex,
int toIndex)
Get an indexable subset.
|
default BooleanIndexable.Base |
sybSet(int fromIndex,
int toIndex)
Get an indexable subset.
|
default BooleanIndexable.Base |
tailSet(int fromIndex)
Create an indexable subset from the last elements of this indexable set.
|
default boolean[] |
toArray()
Convert this indexable into a Java array.
|
default java.util.ArrayList<java.lang.Boolean> |
toList()
Create a list from this boolean indexable.
|
static java.lang.String |
toString(BooleanIndexable indexable)
Create a string representation of the given indexable.
|
default <T> Indexable<T> |
view(BooleanFunction1<? extends T> mapper)
Return a mapped view on this boolean indexable.
|
static BooleanIndexable.Base |
viewArray(boolean... array)
View an int array as an Indexable.
|
static BooleanIndexable.Base |
viewArray(boolean[] array,
int start,
int length)
View part of an integer array as an Indexable.
|
static <T> BooleanIndexable.Base |
viewArray(T[] array,
java.util.function.Predicate<? super T> valueExtract)
View an object array as a boolean indexable.
|
static BooleanIndexable.Base |
viewByIndex(int size,
IntPredicate1 producer)
Get a boolean indexable of a given size which returns elements created by index.
|
static BooleanIndexable.Base |
viewIndexable(Indexable<? extends java.lang.Boolean> indexable)
View a generic Number indexable as integer indexable.
|
static BooleanIndexable.Base |
viewIndexable(Indexable<? extends java.lang.Boolean> indexable,
boolean nullFallback)
View a generic Number indexable as integer indexable.
|
static <T> BooleanIndexable.Base |
viewIndexable(Indexable<T> indexable,
java.util.function.Predicate<? super T> extractor)
View a generic indexable as a boolean indexable.
|
static BooleanIndexable.Base |
viewList(java.util.List<? extends java.lang.Boolean> list)
View a list as an Indexable.
|
static BooleanIndexable.Base |
viewList(java.util.List<? extends java.lang.Boolean> list,
boolean nullFallback)
View a list as an Indexable.
|
static <T> BooleanIndexable.Base |
viewList(java.util.List<T> list,
java.util.function.Predicate<? super T> extractor)
View a generic list as a boolean indexable.
|
default BooleanIndexable |
withAppendedValue(boolean value)
Create a view with of this indexable with another value added at the end.
|
static BooleanIndexable.Base |
withCachedHash(BooleanIndexable indexable)
Wrap an indexable with one which caches the hash value.
|
default BooleanIndexable |
withExchangedValueAt(int index,
boolean value)
Create a view of this boolean indexable with an exchanged value.
|
default BooleanIndexable |
withInsertedValueAt(int index,
boolean value)
Create a view of this boolean indexable with an inserted value.
|
default BooleanIndexable |
withRemovedValueAt(int index)
Create a view of this indexable with one value removed.
|
default BooleanIndexable |
withSwappedValuesAt(int index1,
int index2)
Create a view of this boolean indexable with two values swapped.
|
and, containsBool, containsFalse, containsTrue, forEachBool, forEachBooleanFragile, forEachBoolFragile, or, xor
static final BooleanIndexable SINGLE_FALSE
false
value.static final BooleanIndexable SINGLE_TRUE
false
value.@NotNull static final BooleanIndexable.Base EMPTY
boolean get(int index)
index
- index between 0
and size() - 1
default boolean gyt(int index)
-1
references the last element, -2
its predecessor, and so on.index
- index between -size()
and size() - 1
default boolean getMod(int index)
This maps the given index
into the range of this indexable
by applying a modulo Sizeable.size()
operation. For empty indexable
this will throw an IndexOutOfBoundsException
as there is no
possible index to get.
index
- index, possibly out of range, possibly even negative
for Pythonesque access@NotNull default BooleanIndexable.Base reverse()
default boolean isEmpty()
true
: there are no elements in this indexablefalse
: this indexable has elements@NotNull default PrimitiveBooleanIterator booleanIterator()
booleanIterator
in interface PrimitiveBooleanIterable
boolean
iterator which iterates over this indexable@NotNull default PrimitiveBooleanIterator booleanIterator(int from, int to)
from
- first index of iteratorto
- one past last index of iterator@NotNull default java.util.Iterator<java.lang.Boolean> iterator()
T
.iterator
in interface java.lang.Iterable<java.lang.Boolean>
iterator
in interface PrimitiveBooleanIterable
@NotNull default java.util.ListIterator<java.lang.Boolean> listIterator()
T
.@NotNull default BooleanIndexable.Base subSet(int fromIndex, int toIndex)
fromIndex
to toIndex - 1
.fromIndex
- start index of sub settoIndex
- index after last index@NotNull default BooleanIndexable.Base sybSet(int fromIndex, int toIndex)
fromIndex
- start index of sub settoIndex
- end index of sub set@NotNull default BooleanIndexable.Base tailSet(int fromIndex)
fromIndex
- index to start with, negative counts from the back@NotNull default BooleanIndexable.Base headSet(int toIndex)
toIndex
- index one after the end (equal to the length of the returned set),
negative counts from the back@NotNull default <T> Indexable<T> view(@NotNull BooleanFunction1<? extends T> mapper)
T
- result type pf mappermapper
- mapper@NotNull default java.util.Collection<java.lang.Boolean> asCollection()
Collection.addAll(Collection)
.@NotNull default java.util.List<java.lang.Boolean> asList()
Collection.addAll(Collection)
.toList()
@NotNull default java.util.ArrayList<java.lang.Boolean> toList()
asList()
default void addAllTo(@NotNull java.util.Collection<? super java.lang.Boolean> collection)
collection
- collection to add to@NotNull default Indexable<java.lang.Boolean> asIndexable()
Boolean
values@NotNull default boolean[] toArray()
default int addToArray(@NotNull boolean[] array, int pos)
array
- array where the content is addedpos
- position in the array where the content of this indexable is addeddefault int addToArray(@NotNull boolean[] array, int arrayPos, int index, int length)
array
- array where the content is addedarrayPos
- position in hte array where the content is addedindex
- start index of this indexable which is added firstlength
- number of entries of this indexable added to the array@NotNull default java.lang.Iterable<java.lang.Integer> indexes()
intIndexes()
,
Range.indexes(int)
@NotNull default IntIndexable intIndexes()
indexes()
,
IntIndexable.rangeFromSize(int)
default boolean foldLeft(boolean initialValue, @NotNull BooleanOperator2 foldOperation)
initialValue
- start value for the operation, will be returned if this iterable is emptyfoldOperation
- operation applied to each value, will get the accumulated value as its
first and the current element value as its second argument@NotNull default BooleanIndexable withInsertedValueAt(int index, boolean value)
As this creates a view of this indexable, changes to this indexable might result in a disaster when using the returned indexable!
index
- index where the value is inserted before the current index
(not Pythonesque, because it is possible to add an value at index == size()
,
and it is expected that most insertion will happen at 0 or at the end)value
- inserted value at that indexwithAppendedValue(boolean)
@NotNull default BooleanIndexable withAppendedValue(boolean value)
value
- value to addwithInsertedValueAt(int, boolean)
@NotNull default BooleanIndexable withExchangedValueAt(int index, boolean value)
As this creates a view of this indexable, changes to this indexable could lead to unexpected results when using the returned indexable!
index
- index where the element is exchanged, hiding the current element.
(Pythonesque)value
- exchanged value at that index@NotNull default BooleanIndexable withRemovedValueAt(int index)
index
- index of the removed value (Pythonesque)@NotNull default BooleanIndexable withSwappedValuesAt(int index1, int index2)
index1
- index of the first value (Pythonesque)index2
- index of the second value (Pythonesque)@NotNull default BooleanIndexable rotated(int steps)
steps
will rotate left, i.e. any index will be accessed
as if the number of steps is added before extraction (modulo length).
E.g. a rotation of -1
will return the last element when index 0
is
requested, and the first element for index 1
.steps
- steps to rotatefrozen()
to create an indexable which no longer depends on this one@NotNull static BooleanIndexable.Base viewList(@NotNull java.util.List<? extends java.lang.Boolean> list)
list
- list used as a base, required to have only non-null elements@NotNull static BooleanIndexable.Base viewList(@NotNull java.util.List<? extends java.lang.Boolean> list, boolean nullFallback)
list
- list used as a base, required to have only non-null elementsnullFallback
- value returned for null
elements in the list@NotNull static <T> BooleanIndexable.Base viewList(@NotNull java.util.List<T> list, @NotNull java.util.function.Predicate<? super T> extractor)
T
- element type of listlist
- generic listextractor
- extractor function which extracts a boolean from the elements of list
list
@NotNull static BooleanIndexable.Base viewIndexable(@NotNull Indexable<? extends java.lang.Boolean> indexable)
indexable
- generic indexable with Number elements, required to have only non-null elements@NotNull static BooleanIndexable.Base viewIndexable(@NotNull Indexable<? extends java.lang.Boolean> indexable, boolean nullFallback)
indexable
- generic indexable with Number elementsnullFallback
- fallback for null
elements@NotNull static <T> BooleanIndexable.Base viewIndexable(@NotNull Indexable<T> indexable, @NotNull java.util.function.Predicate<? super T> extractor)
T
- element type of indexableindexable
- generic indexableextractor
- extractor function which extracts a boolean from the elements of indexable
indexable
@NotNull static BooleanIndexable.Base viewArray(@NotNull boolean... array)
viewArray(boolean[], int, int)
.array
- array used as base@NotNull static BooleanIndexable.Base viewArray(@NotNull boolean[] array, int start, int length)
array
- array used as basestart
- start index into the arraylength
- number of booleans use from the array@NotNull static <T> BooleanIndexable.Base viewArray(@NotNull T[] array, @NotNull java.util.function.Predicate<? super T> valueExtract)
T
- array element typearray
- viewed arrayvalueExtract
- converter from array elements to the boolean values of this indexable@NotNull static BooleanIndexable.Base singleton(boolean value)
value
- single value@NotNull static BooleanIndexable.Base init(int size, boolean value)
size
- size of the returned indexablevalue
- value returned for each elementsize
with always the same element@NotNull static BooleanIndexable.Base viewByIndex(int size, @NotNull IntPredicate1 producer)
producer
when an element is requested.
Use frozen()
on the result to create an indexable which avoids this.size
- size of the returned indexableproducer
- producer which is called with an index and expected to return the associated valueproducer
initByIndex(int, IntPredicate1)
@NotNull static BooleanIndexable initByIndex(int size, @NotNull IntPredicate1 producer)
size
- size of the returned indexableproducer
- producer which is called with an index and expected to return the associated valueproducer
viewByIndex(int, IntPredicate1)
@NotNull static BooleanIndexable.Base emptyIndexable()
@NotNull static java.lang.String toString(@NotNull BooleanIndexable indexable)
indexable
- indexablestatic boolean equal(@NotNull BooleanIndexable indexable1, @NotNull BooleanIndexable indexable2)
indexable1
- first indexableindexable2
- second indexabletrue
if both indexables contain the same values in the same sequencefalse
if sizes or values differstatic boolean equal(@NotNull BooleanIndexable indexable1, @Nullable java.lang.Object indexable2)
Object.equals(Object)
method.indexable1
- first indexableindexable2
- object expected to be an indexable itselftrue
if both indexables contain the same values in the same sequencefalse
if the second object is not an indexable, of if sizes or values differstatic int compare(@NotNull BooleanIndexable indexable1, @NotNull BooleanIndexable indexable2)
indexable1
- first indexableindexable2
- second indexable< 0>
if indexable1 < indxable2
,
0
if indexable1 == indexable2
, or
> 0
if indexable1 > indexable2
static int hash(@NotNull BooleanIndexable indexable)
indexable
- indexable for which the hash code is required@NotNull static BooleanIndexable.Base withCachedHash(@NotNull BooleanIndexable indexable)
The wrapped indexable must not change after it is wrapped, otherwise strange things are expected to happen.
indexable
- wrapped indexable, must not changeindexable
, but also provides
useful implementations for Object.hashCode()
, Object.equals(Object)
,
and Object.toString()
default int nextMatch(int startIndex, @NotNull BooleanPredicate1 check)
startIndex
- start index for checking, Pythonesque
indexing supportedcheck
- check to perform on elements of this indexable until true
startIndex
for which the check returns true
,
Pythonesque.UNMAPPABLE
if nonedefault int firstMatch(@NotNull BooleanPredicate1 check)
check
- check to perform on elements of this indexable until true
true
,
-1
if nonedefault int previousMatch(int startIndex, @NotNull BooleanPredicate1 check)
startIndex
- start index for checking, Pythonesque
indexing supportedcheck
- check to perform on elements of this indexable until true
startIndex
for which the check returns true
,
Pythonesque.UNMAPPABLE
if nonedefault int lastMatch(@NotNull BooleanPredicate1 check)
check
- check to perform on elements of this indexable until true
true
,
-1
if none@NotNull default BooleanIndexable frozen()
Often Indexables are used as a view to underlying collections. Although this interface is immutable, the underlying colelction might nevertheless change. This copies the current state of this indexable into an unmodifiable state, and returns an Indexable which is stable in size and will return always the same element for a given index. Beware: it is still possible that any element itself changes when the elements are mutable.
Calling frozen()
again on the returned object will just return
the object itself, so you can safely call this method more than once.
default void forEachBoolEntry(@NotNull BooleanIndexable.EntryConsumer consumer)
consumer
- consumer to be called@NotNull default BooleanIndexable.Base asBase()