Search in sources :

Example 1 with Builder

use of java.util.stream.DoubleStream.Builder in project streamex by amaembo.

the class DoubleStreamExTest method testDropWhile.

@Test
public void testDropWhile() {
    assertArrayEquals(new double[] { 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }, LongStreamEx.range(100).asDoubleStream().dropWhile(i -> i % 10 < 5).limit(10).toArray(), 0.0);
    assertEquals(100, LongStreamEx.range(100).asDoubleStream().sorted().dropWhile(i -> i % 10 < 0).count());
    assertEquals(0, LongStreamEx.range(100).asDoubleStream().dropWhile(i -> i % 10 < 10).count());
    assertEquals(OptionalDouble.of(0), LongStreamEx.range(100).asDoubleStream().dropWhile(i -> i % 10 < 0).findFirst());
    assertEquals(OptionalDouble.empty(), LongStreamEx.range(100).asDoubleStream().dropWhile(i -> i % 10 < 10).findFirst());
    java.util.Spliterator.OfDouble spltr = LongStreamEx.range(100).asDoubleStream().dropWhile(i -> i % 10 < 1).spliterator();
    assertTrue(spltr.tryAdvance((double x) -> assertEquals(1, x, 0.0)));
    Builder builder = DoubleStream.builder();
    spltr.forEachRemaining(builder);
    assertArrayEquals(LongStreamEx.range(2, 100).asDoubleStream().toArray(), builder.build().toArray(), 0.0);
}
Also used : MethodSorters(org.junit.runners.MethodSorters) Arrays(java.util.Arrays) Spliterators(java.util.Spliterators) DoubleStreamEx(one.util.streamex.DoubleStreamEx) OptionalDouble(java.util.OptionalDouble) DoubleFunction(java.util.function.DoubleFunction) Scanner(java.util.Scanner) Random(java.util.Random) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) Supplier(java.util.function.Supplier) DoubleUnaryOperator(java.util.function.DoubleUnaryOperator) ArrayList(java.util.ArrayList) OfDouble(java.util.PrimitiveIterator.OfDouble) Assert.assertSame(org.junit.Assert.assertSame) DoubleBinaryOperator(java.util.function.DoubleBinaryOperator) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Locale(java.util.Locale) Map(java.util.Map) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) Builder(java.util.stream.DoubleStream.Builder) LongStream(java.util.stream.LongStream) LongStreamEx(one.util.streamex.LongStreamEx) DoubleBuffer(java.nio.DoubleBuffer) TestHelpers.checkSpliterator(one.util.streamex.TestHelpers.checkSpliterator) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) DoubleToIntFunction(java.util.function.DoubleToIntFunction) DoubleStream(java.util.stream.DoubleStream) TestHelpers.streamEx(one.util.streamex.TestHelpers.streamEx) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) DoubleToLongFunction(java.util.function.DoubleToLongFunction) StreamEx(one.util.streamex.StreamEx) Assert.assertFalse(org.junit.Assert.assertFalse) IntStreamEx(one.util.streamex.IntStreamEx) Comparator(java.util.Comparator) FixMethodOrder(org.junit.FixMethodOrder) Spliterator(java.util.Spliterator) Assert.assertEquals(org.junit.Assert.assertEquals) Builder(java.util.stream.DoubleStream.Builder) TestHelpers.checkSpliterator(one.util.streamex.TestHelpers.checkSpliterator) Spliterator(java.util.Spliterator) Test(org.junit.Test)

Aggregations

DoubleBuffer (java.nio.DoubleBuffer)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 OptionalDouble (java.util.OptionalDouble)1 OfDouble (java.util.PrimitiveIterator.OfDouble)1 Random (java.util.Random)1 Scanner (java.util.Scanner)1 Spliterator (java.util.Spliterator)1 Spliterators (java.util.Spliterators)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 DoubleBinaryOperator (java.util.function.DoubleBinaryOperator)1 DoubleFunction (java.util.function.DoubleFunction)1 DoubleToIntFunction (java.util.function.DoubleToIntFunction)1 DoubleToLongFunction (java.util.function.DoubleToLongFunction)1 DoubleUnaryOperator (java.util.function.DoubleUnaryOperator)1