@Override public void accept(final Byte t) { set(t); }
@Override public Mutable<T1> set(final T1 value) { host.set(fn.apply(value)); return this; }
/** * @param varFn New value * @return this object with mutated value */ public MutableByte mutate(final ByteFunction varFn) { return set(varFn.apply(getAsByte())); }
@Test public void inClosure(){ MutableByte myInt = new MutableByte(zero); Function<Integer,Function<Integer,MutableByte>> fn = ((Integer i)-> (Integer j)-> myInt.set(new Byte((byte)(i*j)))); fn.apply(10).apply(20); assertThat(myInt.getAsByte(), is((byte)200)); } @Test
@Test public void inClosure2(){ MutableByte myInt = new MutableByte(zero); BiFunction<Byte,Byte,MutableByte> fn = (i,j)-> myInt.set(new Byte((byte)(i*j))); fn.apply(ten,twenty); assertThat(myInt.getAsByte(), is((byte)200)); }
@Test public void externalSet(){ value = 0; MutableByte ext = MutableByte.fromExternal(()->value,v->this.value=v); ext.set(ten); assertThat(value,equalTo((byte)10)); }
@Test public void testSet() { assertThat(new MutableByte().set(twenty).getAsByte(),is(twenty)); }
@Override public void accept(final Byte t) { set(t); }
@Override public Mutable<T1> set(final T1 value) { host.set(fn.apply(value)); return this; }
/** * @param varFn New value * @return this object with mutated value */ public MutableByte mutate(final ByteFunction varFn) { return set(varFn.apply(getAsByte())); }