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()));
}
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;
}
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());
}
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));
}
Aggregations