Search in sources :

Example 11 with LongConsumer

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

the class EntityCollectionPageSourceTest method secondPage.

@Test
void secondPage() {
    final List<Integer> allResults = FUNCTION.apply(null);
    final List<Integer> subpage = allResults.subList(PAGE_SIZE, 2 * PAGE_SIZE);
    final PaginatedApi<Integer, Object> api = mock(PaginatedApi.class);
    when(api.execute(eq(FUNCTION), eq(SELECT), eq(ORDERING), eq(1), 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(PAGE_SIZE, 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)

Example 12 with LongConsumer

use of java.util.function.LongConsumer in project jgnash by ccavanaugh.

the class BootLoader method downloadFiles.

public static boolean downloadFiles(final Consumer<String> fileNameConsumer, final IntConsumer percentCompleteConsumer) {
    percentCompleteConsumer.accept(0);
    boolean result = true;
    final Path lib = Paths.get(BootLoader.getLibPath());
    try {
        final long completeDownloadSize = getTotalDownloadSize();
        // create the directory if needed
        Files.createDirectories(lib);
        final String spec = MAVEN_REPO + "javafx-{0}/{1}/" + FILE_PATTERN;
        final String pathSpec = lib + SEPARATOR + FILE_PATTERN;
        final LongConsumer countConsumer = new LongConsumer() {

            long totalCounts;

            @Override
            public void accept(final long value) {
                totalCounts += value;
                percentCompleteConsumer.accept((int) (((double) totalCounts / (double) completeDownloadSize) * 100));
            }
        };
        for (final String fxJar : JARS) {
            URL url = new URL(MessageFormat.format(spec, fxJar, JFX_VERSION, OS));
            Path path = Paths.get(MessageFormat.format(pathSpec, fxJar, JFX_VERSION, OS));
            if (!Files.exists(path)) {
                fileNameConsumer.accept(url.toExternalForm());
                try {
                    boolean downloadResult = downloadFile(url, path, countConsumer);
                    if (!downloadResult) {
                        result = false;
                        break;
                    }
                } catch (final IOException e) {
                    e.printStackTrace();
                    showException(e);
                }
            }
        }
    } catch (final IOException e) {
        e.printStackTrace();
        result = false;
    }
    return result;
}
Also used : Path(java.nio.file.Path) LongConsumer(java.util.function.LongConsumer) IOException(java.io.IOException) URL(java.net.URL)

Example 13 with LongConsumer

use of java.util.function.LongConsumer in project j2objc by google.

the class SpliteratorsTest method testEmptyLongSpliterator.

public void testEmptyLongSpliterator() {
    Spliterator.OfLong empty = Spliterators.emptyLongSpliterator();
    assertNull(empty.trySplit());
    assertEquals(0, empty.estimateSize());
    assertEquals(0, empty.getExactSizeIfKnown());
    LongConsumer alwaysFails = (long value) -> fail();
    Consumer<Long> alwaysFailsBoxed = (Long value) -> fail();
    empty.tryAdvance(alwaysFails);
    empty.tryAdvance(alwaysFailsBoxed);
    empty.forEachRemaining(alwaysFails);
    empty.forEachRemaining(alwaysFailsBoxed);
    assertEquals(Spliterator.SIZED | Spliterator.SUBSIZED, empty.characteristics());
}
Also used : LongConsumer(java.util.function.LongConsumer) Spliterator(java.util.Spliterator)

Example 14 with LongConsumer

use of java.util.function.LongConsumer in project j2objc by google.

the class LongPipeline method forEachWithCancel.

@Override
public 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)

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