public Boolean get() { return getAsBoolean(); }
/** * @param varFn New value * @return this object with mutated value */ public MutableBoolean mutate(final BooleanFunction varFn) { return set(varFn.apply(getAsBoolean())); }
@Test public void testMutate(){ MutableBoolean num = MutableBoolean.of(falseB); Stream.of(1,2,3,4).map(i->i*10).peek(i-> num.mutate(n->!n)).forEach(System.out::println); assertThat(num.getAsBoolean(),is(false)); } @Test
@Test public void testClosedVar() { assertThat(new MutableBoolean(trueB).getAsBoolean(),equalTo(trueB)); } @Test
@Test public void inClosure(){ MutableBoolean myInt = new MutableBoolean(zero); Function<Integer,Function<Integer,MutableBoolean>> fn = ( (Integer i)-> (Integer j)-> myInt.set(true)); fn.apply(10).apply(20); assertThat(myInt.getAsBoolean(), is(true)); } @Test
@Test public void inClosure2(){ MutableBoolean myInt = new MutableBoolean(zero); BiFunction<Boolean,Boolean,MutableBoolean> fn = (i,j)-> myInt.set(true); fn.apply(trueB,falseB); assertThat(myInt.getAsBoolean(), is(true)); }
@Test public void testSet() { assertThat(new MutableBoolean().set(falseB).getAsBoolean(),is(falseB)); }
public Boolean get() { return getAsBoolean(); }
/** * @param varFn New value * @return this object with mutated value */ public MutableBoolean mutate(final BooleanFunction varFn) { return set(varFn.apply(getAsBoolean())); }