Search in sources :

Example 1 with LongConsumer

use of java.util.function.LongConsumer in project jdk8u_jdk by JetBrains.

the class LongPipeline method forEachWithCancel.

@Override
final void forEachWithCancel(Spliterator<Long> spliterator, Sink<Long> sink) {
    Spliterator.OfLong spl = adapt(spliterator);
    LongConsumer adaptedSink = adapt(sink);
    do {
    } while (!sink.cancellationRequested() && spl.tryAdvance(adaptedSink));
}
Also used : LongConsumer(java.util.function.LongConsumer) ObjLongConsumer(java.util.function.ObjLongConsumer) Spliterator(java.util.Spliterator)

Example 2 with LongConsumer

use of java.util.function.LongConsumer in project jdk8u_jdk by JetBrains.

the class SerializedLambdaTest method testDiscardReturnBound.

//Test throwing away return type
public void testDiscardReturnBound() throws IOException, ClassNotFoundException {
    List<String> list = new ArrayList<>();
    Consumer<String> c = (Consumer<String> & Serializable) list::add;
    assertSerial(c, cc -> {
        assertTrue(cc instanceof Consumer);
    });
    AtomicLong a = new AtomicLong();
    LongConsumer lc = (LongConsumer & Serializable) a::addAndGet;
    assertSerial(lc, plc -> {
        plc.accept(3);
    });
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) LongConsumer(java.util.function.LongConsumer) LongConsumer(java.util.function.LongConsumer) Consumer(java.util.function.Consumer) ArrayList(java.util.ArrayList)

Example 3 with LongConsumer

use of java.util.function.LongConsumer in project Bytecoder by mirkosertic.

the class LongPipeline method forEachWithCancel.

@Override
final boolean forEachWithCancel(Spliterator<Long> spliterator, Sink<Long> sink) {
    Spliterator.OfLong spl = adapt(spliterator);
    LongConsumer adaptedSink = adapt(sink);
    boolean cancelled;
    do {
    } while (!(cancelled = sink.cancellationRequested()) && spl.tryAdvance(adaptedSink));
    return cancelled;
}
Also used : LongConsumer(java.util.function.LongConsumer) ObjLongConsumer(java.util.function.ObjLongConsumer) Spliterator(java.util.Spliterator)

Example 4 with LongConsumer

use of java.util.function.LongConsumer in project fmv by f-agu.

the class PIDProcessOperator method consume.

// *********************************************
/**
 * @param process
 * @param cls
 * @param field
 * @throws NoSuchFieldException
 * @throws IllegalAccessException
 */
private void consume(Process process, Class<? extends Process> cls, String field) throws NoSuchFieldException, IllegalAccessException {
    Field f = cls.getDeclaredField(field);
    f.setAccessible(true);
    pid = f.getLong(process);
    for (LongConsumer pidConsumer : pidConsumers) {
        pidConsumer.accept(pid);
    }
    f.setAccessible(false);
}
Also used : Field(java.lang.reflect.Field) LongConsumer(java.util.function.LongConsumer)

Example 5 with LongConsumer

use of java.util.function.LongConsumer in project robozonky by RoboZonky.

the class EntityCollectionPageSourceTest method firstPage.

@Test
void firstPage() {
    final List<Integer> allResults = FUNCTION.apply(null);
    final List<Integer> subpage = allResults.subList(0, PAGE_SIZE);
    final PaginatedApi<Integer, Object> api = mock(PaginatedApi.class);
    when(api.execute(eq(FUNCTION), eq(SELECT), eq(ORDERING), eq(0), eq(PAGE_SIZE))).thenReturn(new PaginatedResult<>(subpage, allResults.size()));
    final PageSource<Integer> source = new EntityCollectionPageSource<Integer, Object>(api, FUNCTION, SELECT, ORDERING, PAGE_SIZE);
    final LongConsumer consumer = mock(LongConsumer.class);
    final List<Integer> result = source.fetch(0, 1, consumer);
    assertThat(result).containsExactly(subpage.toArray(new Integer[PAGE_SIZE]));
    verify(consumer).accept(eq((long) allResults.size()));
}
Also used : LongConsumer(java.util.function.LongConsumer) Test(org.junit.jupiter.api.Test)

Aggregations

LongConsumer (java.util.function.LongConsumer)14 Spliterator (java.util.Spliterator)4 ObjLongConsumer (java.util.function.ObjLongConsumer)3 TestCase (junit.framework.TestCase)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 NoSuchElementException (java.util.NoSuchElementException)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Field (java.lang.reflect.Field)1 URL (java.net.URL)1 Path (java.nio.file.Path)1 Collection (java.util.Collection)1 ConcurrentModificationException (java.util.ConcurrentModificationException)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 OptionalLong (java.util.OptionalLong)1 Set (java.util.Set)1