T
- Type held inside closed varpublic class MutableFloat extends java.lang.Object implements To<MutableFloat>, java.util.function.Supplier<java.lang.Float>, java.util.function.Consumer<java.lang.Float>, Matchable.ValueAndOptionalMatcher<java.lang.Float>
float 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.
MutableFloat var = MutableFloat.of(true);
Runnable r = () -> var.set(false);
Modifier and Type | Class and Description |
---|---|
static interface |
MutableFloat.FloatFunction |
Value.ValueImpl<T>
Convertable.SupplierToConvertable<T>
Constructor and Description |
---|
MutableFloat() |
Modifier and Type | Method and Description |
---|---|
void |
accept(java.lang.Float t) |
static MutableFloat |
fromExternal(java.util.function.Supplier<java.lang.Float> s,
java.util.function.Consumer<java.lang.Float> c)
Construct a MutableFloat that gets and sets an external value using the provided Supplier and Consumer
e.g.
|
java.lang.Float |
get() |
float |
getAsFloat() |
<T1> Mutable<T1> |
mapInputToObj(java.util.function.Function<T1,java.lang.Float> 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.Float,R> fn)
Use the supplied function to perform a lazy map operation when get is called
|
MutableFloat |
mutate(MutableFloat.FloatFunction varFn) |
static <T> MutableFloat |
of(float var)
Create a Mutable variable, which can be mutated inside a Closure
e.g.
|
MutableFloat |
set(float var) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
iterator, toOptional, visit
matches
collect, 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, unapply
endsWith, 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, xMatch
collect, fromSupplier, isPresent, orElse, orElseGet, orElseThrow, toAtomicReference, toCompletableFuture, toCompletableFutureAsync, toCompletableFutureAsync, toFutureW, toFutureWAsync, toFutureWAsync, toOptionalAtomicReference, toStream
public static <T> MutableFloat of(float var)
MutableFloat num = MutableFloat.of(true);
num.mutate(n->!n))
System.out.println(num.getAsFloat());
//prints false
var
- Initial value of Mutablepublic static MutableFloat fromExternal(java.util.function.Supplier<java.lang.Float> s, java.util.function.Consumer<java.lang.Float> c)
MutableFloat mutable = MutableFloat.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.Float,R> fn)
MutableFloat mutable = MutableFlaot.fromExternal(()->!this.value,val->!this.value);
Mutable<Float> withOverride = mutable.mapOutputToObj(b->{
if(override)
return 1f;
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.Float> fn)
MutableFloat mutable = MutableBoolean.fromExternal(()->!this.value,val->!this.value);
Mutable<Float> withOverride = mutable.mapInputToObj(b->{
if(override)
return 2f;
return b;
});
fn
- Map function to be applied to the input when set is calledpublic float getAsFloat()
public MutableFloat set(float var)
var
- New valuepublic MutableFloat mutate(MutableFloat.FloatFunction varFn)
varFn
- New valuepublic java.lang.Float get()
get
in interface Convertable<java.lang.Float>
get
in interface java.util.function.Supplier<java.lang.Float>
public void accept(java.lang.Float t)
accept
in interface java.util.function.Consumer<java.lang.Float>