Search in sources :

Example 1 with MutableByte

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

the class MutableByteTest method externalSet.

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

Example 2 with MutableByte

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

the class MutableByteTest method externalGet.

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

Example 3 with MutableByte

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

the class MutableByteTest method inClosure2.

@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));
}
Also used : Assert.assertThat(org.junit.Assert.assertThat) 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) MutableByte(com.oath.cyclops.util.box.MutableByte) MutableByte(com.oath.cyclops.util.box.MutableByte) MutableByte(com.oath.cyclops.util.box.MutableByte) Test(org.junit.Test)

Example 4 with MutableByte

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

the class MutableByteTest method testMutate.

@Test
public void testMutate() {
    MutableByte num = MutableByte.of(twenty);
    Stream.of(1, 2, 3, 4).map(i -> i * 10).peek(i -> num.mutate(n -> new Byte((byte) (n + i)))).forEach(System.out::println);
    assertThat(num.getAsByte(), is((byte) 120));
}
Also used : Assert.assertThat(org.junit.Assert.assertThat) 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) MutableByte(com.oath.cyclops.util.box.MutableByte) MutableByte(com.oath.cyclops.util.box.MutableByte) MutableByte(com.oath.cyclops.util.box.MutableByte) Test(org.junit.Test)

Example 5 with MutableByte

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

the class MutableByteTest method inClosure.

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

Aggregations

MutableByte (com.oath.cyclops.util.box.MutableByte)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