@Override public void accept(final Short 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 MutableShort mutate(final ShortFunction varFn) { return set(varFn.apply(get())); }
@Test public void inClosure2(){ MutableShort myInt = new MutableShort(zero); BiFunction<Short,Short,MutableShort> fn = (i,j)-> myInt.set(new Short((short)(i*j))); fn.apply(ten,twenty); assertThat(myInt.getAsShort(), is((short)200)); }
@Test public void inClosure(){ MutableShort myInt = new MutableShort(zero); Function<Integer,Function<Integer,MutableShort>> fn = ((Integer i)-> (Integer j)-> myInt.set(new Short((short)(i*j)))); fn.apply(10).apply(20); assertThat(myInt.getAsShort(), is((short)200)); } @Test
@Test public void externalSet(){ value = 0; MutableShort ext = MutableShort.fromExternal(()->value,v->this.value=v); ext.set(ten); assertThat(value,equalTo((short)10)); }
@Test public void testSet() { assertThat(new MutableShort().set(twenty).getAsShort(),is(twenty)); }
@Override public void accept(final Short 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 MutableShort mutate(final ShortFunction varFn) { return set(varFn.apply(get())); }