T - Type held inside closed varpublic class MutableBoolean extends java.lang.Object implements java.util.function.BooleanSupplier, java.util.function.Consumer<java.lang.Boolean>, Matchable.ValueAndOptionalMatcher<java.lang.Boolean>
boolean var = true;
Runnable r = () -> var =false;
Won't compile because var is treated as if it is final.
This can be 'worked around' by using a wrapping object or array.
e.g.
MutableBoolean var = MutableBoolean.of(true);
Runnable r = () -> var.set(false);
| Modifier and Type | Class and Description |
|---|---|
static interface |
MutableBoolean.BooleanFunction |
Value.ValueImpl<T>Convertable.SupplierToConvertable<T>| Constructor and Description |
|---|
MutableBoolean() |
| Modifier and Type | Method and Description |
|---|---|
void |
accept(java.lang.Boolean t) |
static MutableBoolean |
fromExternal(java.util.function.BooleanSupplier s,
java.util.function.Consumer<java.lang.Boolean> c)
Construct a MutableBoolean that gets and sets an external value using the provided Supplier and Consumer
e.g.
|
java.lang.Boolean |
get() |
boolean |
getAsBoolean() |
<T1> Mutable<T1> |
mapInputToObj(java.util.function.Function<T1,java.lang.Boolean> fn)
Use the supplied function to perform a lazy map operation when get is called
|
<R> Mutable<R> |
mapOutputToObj(java.util.function.Function<java.lang.Boolean,R> fn)
Use the supplied function to perform a lazy map operation when get is called
|
MutableBoolean |
mutate(MutableBoolean.BooleanFunction varFn) |
static <T> MutableBoolean |
of(boolean var)
Create a Mutable variable, which can be mutated inside a Closure
e.g.
|
MutableBoolean |
set(boolean var) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waititerator, toOptional, visitmatchescollect, fold, fold, generate, iterate, mapReduce, mkString, newSubscriber, of, stream, subscribe, test, toDequeX, toEvalAlways, toEvalLater, toEvalNow, toFeatureToggle, toFutureStream, toFutureStream, toIor, toLazyImmutable, toList, toListX, toMaybe, toMutable, toPBagX, toPOrderedSetX, toPQueueX, toPSetX, toPStackX, toPVectorX, toQueueX, toSetX, toSimpleReact, toSimpleReact, toSortedSetX, toTry, toTry, toTry, toXor, toXor, unapplyendsWith, endsWithIterable, findAny, findFirst, firstValue, foldable, foldRight, foldRight, foldRight, foldRightMapToType, get, groupBy, join, join, join, mapReduce, print, print, printErr, printOut, reduce, reduce, reduce, reduce, reduce, reduce, reduce, schedule, scheduleFixedDelay, scheduleFixedRate, single, single, singleOptional, startsWith, startsWithIterable, toConcurrentLazyCollection, toConcurrentLazyStreamable, toLazyCollection, validate, xMatchcollect, fromSupplier, isPresent, orElse, orElseGet, orElseThrow, toAtomicReference, toCompletableFuture, toCompletableFutureAsync, toCompletableFutureAsync, toFutureW, toFutureWAsync, toFutureWAsync, toOptionalAtomicReference, toStreampublic static <T> MutableBoolean of(boolean var)
MutableBoolean num = MutableBoolean.of(true);
num.mutate(n->!n))
System.out.println(num.getAsBoolean());
//prints false
var - Initial value of Mutablepublic static MutableBoolean fromExternal(java.util.function.BooleanSupplier s, java.util.function.Consumer<java.lang.Boolean> c)
MutableBoolean mutable = MutableBoolean.fromExternal(()->!this.value,val->!this.value);
s - Supplier of an external valuec - Consumer that sets an external valuepublic <R> Mutable<R> mapOutputToObj(java.util.function.Function<java.lang.Boolean,R> fn)
MutableBoolean mutable = MutableBoolean.fromExternal(()->!this.value,val->!this.value);
Mutable<Boolean> withOverride = mutable.mapOutput(b->{
if(override)
return true;
return b;
});
fn - Map function to be applied to the result when get is calledpublic <T1> Mutable<T1> mapInputToObj(java.util.function.Function<T1,java.lang.Boolean> fn)
MutableBoolean mutable = MutableBoolean.fromExternal(()->!this.value,val->!this.value);
Mutable<Boolean> withOverride = mutable.mapInput(b->{
if(override)
return true;
return b;
});
fn - Map function to be applied to the input when set is calledpublic boolean getAsBoolean()
getAsBoolean in interface java.util.function.BooleanSupplierpublic MutableBoolean set(boolean var)
var - New valuepublic MutableBoolean mutate(MutableBoolean.BooleanFunction varFn)
varFn - New valuepublic void accept(java.lang.Boolean t)
accept in interface java.util.function.Consumer<java.lang.Boolean>public java.lang.Boolean get()
get in interface Convertable<java.lang.Boolean>get in interface java.util.function.Supplier<java.lang.Boolean>