Search in sources :

Example 1 with OptionalLong

use of java8.util.OptionalLong in project streamsupport by stefan-zobel.

the class FindAnyOpTest method exerciseLongStream.

void exerciseLongStream(TestData.OfLong data, Function<LongStream, LongStream> fs) {
    OptionalLong or = withData(data).terminal(fs, s -> s.findAny()).equalator(LONG_VALID_ANSWER).exercise();
    if (or.isPresent()) {
        long r = or.getAsLong();
        PrimitiveIterator.OfLong it = fs.apply(data.stream()).iterator();
        boolean contained = false;
        while (!contained && it.hasNext()) {
            contained = r == it.nextLong();
        }
        assertTrue(contained);
    } else {
        assertFalse(fs.apply(data.stream()).iterator().hasNext());
    }
}
Also used : PrimitiveIterator(java8.util.PrimitiveIterator) OptionalLong(java8.util.OptionalLong)

Aggregations

OptionalLong (java8.util.OptionalLong)1 PrimitiveIterator (java8.util.PrimitiveIterator)1