@Override public Short get() { return getAsShort(); }
@Test public void testMutate(){ MutableShort num = MutableShort.of(twenty); Stream.of(1,2,3,4).map(i->i*10).peek(i-> num.mutate(n->new Short((short)(n+i)))).forEach(System.out::println); assertThat(num.getAsShort(),is((short)120)); } @Test
@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 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 testClosedVar() { assertThat(new MutableShort(ten).getAsShort(),equalTo(ten)); } @Test
@Test public void testSet() { assertThat(new MutableShort().set(twenty).getAsShort(),is(twenty)); }
@Override public Short get() { return getAsShort(); }