Search in sources :

Example 1 with Builder

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

the class LongStreamExTest method testDropWhile.

@Test
public void testDropWhile() {
    assertArrayEquals(new long[] { 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 }, LongStreamEx.range(100).dropWhile(i -> i % 10 < 5).limit(10).toArray());
    assertEquals(100, LongStreamEx.range(100).dropWhile(i -> i % 10 < 0).count());
    assertEquals(0, LongStreamEx.range(100).dropWhile(i -> i % 10 < 10).count());
    assertEquals(OptionalLong.of(0), LongStreamEx.range(100).dropWhile(i -> i % 10 < 0).findFirst());
    assertEquals(OptionalLong.empty(), LongStreamEx.range(100).dropWhile(i -> i % 10 < 10).findFirst());
    java.util.Spliterator.OfLong spltr = LongStreamEx.range(100).dropWhile(i -> i % 10 < 1).spliterator();
    assertTrue(spltr.tryAdvance((long x) -> assertEquals(1, x)));
    Builder builder = LongStream.builder();
    spltr.forEachRemaining(builder);
    assertArrayEquals(LongStreamEx.range(2, 100).toArray(), builder.build().toArray());
}
Also used : MethodSorters(org.junit.runners.MethodSorters) Arrays(java.util.Arrays) LongBinaryOperator(java.util.function.LongBinaryOperator) Spliterators(java.util.Spliterators) Assert.assertThrows(org.junit.Assert.assertThrows) Scanner(java.util.Scanner) Random(java.util.Random) Builder(java.util.stream.LongStream.Builder) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Assert.assertSame(org.junit.Assert.assertSame) OptionalLong(java.util.OptionalLong) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) OfLong(java.util.PrimitiveIterator.OfLong) LongToDoubleFunction(java.util.function.LongToDoubleFunction) LongToIntFunction(java.util.function.LongToIntFunction) LongStream(java.util.stream.LongStream) LongStreamEx(one.util.streamex.LongStreamEx) LongFunction(java.util.function.LongFunction) TestHelpers.checkSpliterator(one.util.streamex.TestHelpers.checkSpliterator) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Collectors(java.util.stream.Collectors) LongConsumer(java.util.function.LongConsumer) TestHelpers.streamEx(one.util.streamex.TestHelpers.streamEx) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) LongUnaryOperator(java.util.function.LongUnaryOperator) StreamEx(one.util.streamex.StreamEx) Assert.assertFalse(org.junit.Assert.assertFalse) LongBuffer(java.nio.LongBuffer) IntStreamEx(one.util.streamex.IntStreamEx) TestHelpers.longStreamEx(one.util.streamex.TestHelpers.longStreamEx) Comparator(java.util.Comparator) FixMethodOrder(org.junit.FixMethodOrder) Spliterator(java.util.Spliterator) Assert.assertEquals(org.junit.Assert.assertEquals) Builder(java.util.stream.LongStream.Builder) TestHelpers.checkSpliterator(one.util.streamex.TestHelpers.checkSpliterator) Spliterator(java.util.Spliterator) Test(org.junit.Test)

Example 2 with Builder

use of java.util.stream.LongStream.Builder in project taskana by Taskana.

the class WorkingDaysToDaysConverter method isGermanHoliday.

public boolean isGermanHoliday(LocalDate date) {
    if (GERMAN_HOLIDAYS.contains(CustomHoliday.of(date.getDayOfMonth(), date.getMonthValue()))) {
        return true;
    }
    // Easter holidays Good Friday, Easter Monday, Ascension Day, Whit Monday.
    long diffFromEasterSunday = DAYS.between(easterCalculator.getEasterSunday(date.getYear()), date);
    Builder builder = LongStream.builder().add(OFFSET_GOOD_FRIDAY).add(OFFSET_EASTER_MONDAY).add(OFFSET_ASCENSION_DAY).add(OFFSET_WHIT_MONDAY);
    if (corpusChristiEnabled) {
        builder.add(OFFSET_CORPUS_CHRISTI);
    }
    return builder.build().anyMatch(c -> c == diffFromEasterSunday);
}
Also used : Builder(java.util.stream.LongStream.Builder)

Aggregations

Builder (java.util.stream.LongStream.Builder)2 LongBuffer (java.nio.LongBuffer)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Comparator (java.util.Comparator)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 OptionalLong (java.util.OptionalLong)1 OfLong (java.util.PrimitiveIterator.OfLong)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 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Function (java.util.function.Function)1 LongBinaryOperator (java.util.function.LongBinaryOperator)1 LongConsumer (java.util.function.LongConsumer)1 LongFunction (java.util.function.LongFunction)1