Search in sources :

Example 1 with MutableShort

use of com.oath.cyclops.util.box.MutableShort in project cyclops by aol.

the class MutableShortTest method inClosure2.

@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));
}
Also used : Assert.assertThat(org.junit.Assert.assertThat) MutableShort(com.oath.cyclops.util.box.MutableShort) Stream(java.util.stream.Stream) Mutable(com.oath.cyclops.util.box.Mutable) Matchers.equalTo(org.hamcrest.Matchers.equalTo) BiFunction(java.util.function.BiFunction) Matchers.not(org.hamcrest.Matchers.not) Matchers.is(org.hamcrest.Matchers.is) Test(org.junit.Test) Function(java.util.function.Function) MutableShort(com.oath.cyclops.util.box.MutableShort) MutableShort(com.oath.cyclops.util.box.MutableShort) Test(org.junit.Test)

Example 2 with MutableShort

use of com.oath.cyclops.util.box.MutableShort in project cyclops by aol.

the class MutableShortTest method externalSet.

@Test
public void externalSet() {
    value = 0;
    MutableShort ext = MutableShort.fromExternal(() -> value, v -> this.value = v);
    ext.set(ten);
    assertThat(value, equalTo((short) 10));
}
Also used : MutableShort(com.oath.cyclops.util.box.MutableShort) Test(org.junit.Test)

Example 3 with MutableShort

use of com.oath.cyclops.util.box.MutableShort in project cyclops by aol.

the class MutableShortTest method testMutate.

@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));
}
Also used : Assert.assertThat(org.junit.Assert.assertThat) MutableShort(com.oath.cyclops.util.box.MutableShort) Stream(java.util.stream.Stream) Mutable(com.oath.cyclops.util.box.Mutable) Matchers.equalTo(org.hamcrest.Matchers.equalTo) BiFunction(java.util.function.BiFunction) Matchers.not(org.hamcrest.Matchers.not) Matchers.is(org.hamcrest.Matchers.is) Test(org.junit.Test) Function(java.util.function.Function) MutableShort(com.oath.cyclops.util.box.MutableShort) MutableShort(com.oath.cyclops.util.box.MutableShort) Test(org.junit.Test)

Example 4 with MutableShort

use of com.oath.cyclops.util.box.MutableShort in project cyclops by aol.

the class MutableShortTest method inClosure.

@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));
}
Also used : BiFunction(java.util.function.BiFunction) Function(java.util.function.Function) MutableShort(com.oath.cyclops.util.box.MutableShort) MutableShort(com.oath.cyclops.util.box.MutableShort) Test(org.junit.Test)

Example 5 with MutableShort

use of com.oath.cyclops.util.box.MutableShort in project cyclops by aol.

the class MutableShortTest method externalGet.

@Test
public void externalGet() {
    value = 100;
    MutableShort ext = MutableShort.fromExternal(() -> value, v -> this.value = v);
    assertThat(ext.get(), equalTo((short) 100));
}
Also used : MutableShort(com.oath.cyclops.util.box.MutableShort) Test(org.junit.Test)

Aggregations

MutableShort (com.oath.cyclops.util.box.MutableShort)5 Test (org.junit.Test)5 BiFunction (java.util.function.BiFunction)3 Function (java.util.function.Function)3 Mutable (com.oath.cyclops.util.box.Mutable)2 Stream (java.util.stream.Stream)2 Matchers.equalTo (org.hamcrest.Matchers.equalTo)2 Matchers.is (org.hamcrest.Matchers.is)2 Matchers.not (org.hamcrest.Matchers.not)2 Assert.assertThat (org.junit.Assert.assertThat)2