Search in sources :

Example 11 with DoubleStream

use of com.annimon.stream.DoubleStream in project Lightweight-Stream-API by aNNiMON.

the class OnCloseTest method testOnClose.

@Test
public void testOnClose() {
    final boolean[] state = new boolean[] { false };
    DoubleStream stream = DoubleStream.of(0, 1, 2).onClose(new Runnable() {

        @Override
        public void run() {
            state[0] = true;
        }
    });
    stream.findFirst();
    stream.close();
    assertTrue(state[0]);
}
Also used : DoubleStream(com.annimon.stream.DoubleStream) Test(org.junit.Test)

Example 12 with DoubleStream

use of com.annimon.stream.DoubleStream in project Lightweight-Stream-API by aNNiMON.

the class OnCloseTest method testOnCloseWithOtherOperators.

@Test
public void testOnCloseWithOtherOperators() {
    final boolean[] state = new boolean[] { false };
    DoubleStream stream = DoubleStream.of(0, 1, 2, 2, 3, 4, 4, 5).filter(new DoublePredicate() {

        @Override
        public boolean test(double value) {
            return value < 4;
        }
    }).onClose(new Runnable() {

        @Override
        public void run() {
            state[0] = true;
        }
    }).distinct().limit(2);
    stream.findFirst();
    stream.close();
    assertTrue(state[0]);
}
Also used : DoublePredicate(com.annimon.stream.function.DoublePredicate) DoubleStream(com.annimon.stream.DoubleStream) Test(org.junit.Test)

Aggregations

DoubleStream (com.annimon.stream.DoubleStream)12 Test (org.junit.Test)10 CustomOperators (com.annimon.stream.CustomOperators)1 IntStream (com.annimon.stream.IntStream)1 DoubleBinaryOperator (com.annimon.stream.function.DoubleBinaryOperator)1 DoublePredicate (com.annimon.stream.function.DoublePredicate)1 DoubleSupplier (com.annimon.stream.function.DoubleSupplier)1 Function (com.annimon.stream.function.Function)1 LongToDoubleFunction (com.annimon.stream.function.LongToDoubleFunction)1 PrimitiveIterator (com.annimon.stream.iterator.PrimitiveIterator)1