Search in sources :

Example 1 with MutableFloat

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

the class MutableFloatTest method testMutate.

@Test
public void testMutate() {
    MutableFloat num = MutableFloat.of(twenty);
    Stream.of(1, 2, 3, 4).map(i -> i * 10).peek(i -> num.mutate(n -> new Float((float) (n + i)))).forEach(System.out::println);
    assertThat(num.getAsFloat(), is((float) 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) MutableFloat(com.oath.cyclops.util.box.MutableFloat) Matchers.not(org.hamcrest.Matchers.not) Matchers.is(org.hamcrest.Matchers.is) Test(org.junit.Test) Function(java.util.function.Function) MutableFloat(com.oath.cyclops.util.box.MutableFloat) MutableFloat(com.oath.cyclops.util.box.MutableFloat) Test(org.junit.Test)

Example 2 with MutableFloat

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

the class MutableFloatTest method inClosure2.

@Test
public void inClosure2() {
    MutableFloat myInt = new MutableFloat(zero);
    BiFunction<Float, Float, MutableFloat> fn = (i, j) -> myInt.set(new Float((float) (i * j)));
    fn.apply(ten, twenty);
    assertThat(myInt.getAsFloat(), is((float) 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) MutableFloat(com.oath.cyclops.util.box.MutableFloat) Matchers.not(org.hamcrest.Matchers.not) Matchers.is(org.hamcrest.Matchers.is) Test(org.junit.Test) Function(java.util.function.Function) MutableFloat(com.oath.cyclops.util.box.MutableFloat) MutableFloat(com.oath.cyclops.util.box.MutableFloat) Test(org.junit.Test)

Example 3 with MutableFloat

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

the class MutableFloatTest method inClosure.

@Test
public void inClosure() {
    MutableFloat myInt = new MutableFloat(zero);
    Function<Integer, Function<Integer, MutableFloat>> fn = ((Integer i) -> (Integer j) -> myInt.set(new Float((float) (i * j))));
    fn.apply(10).apply(20);
    assertThat(myInt.getAsFloat(), is((float) 200));
}
Also used : BiFunction(java.util.function.BiFunction) Function(java.util.function.Function) MutableFloat(com.oath.cyclops.util.box.MutableFloat) MutableFloat(com.oath.cyclops.util.box.MutableFloat) Test(org.junit.Test)

Example 4 with MutableFloat

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

the class MutableFloatTest method externalGet.

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

Example 5 with MutableFloat

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

the class MutableFloatTest method externalSet.

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

Aggregations

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