class ParallelUtil {

    public static <T extends Runnable> void readParallel(
        final int concurrency,
        final int batchSize,
        final BatchNodeIterable idMapping,
        final ExecutorService executor,
        final HugeParallelGraphImporter<T> importer
    ) {

        Collection<PrimitiveLongIterable> iterators =
            idMapping.batchIterables(batchSize);

        int threads = iterators.size();

        if (!canRunInParallel(executor) || threads == 1) {
            long nodeOffset = 0L;
            for (PrimitiveLongIterable iterator : iterators) {
                final T task = importer.newImporter(nodeOffset, iterator);
                task.run();
                nodeOffset += batchSize;
            }
        } else {
            AtomicLong nodeOffset = new AtomicLong();
            Collection<T> importers = LazyMappingCollection.of(
                iterators,
                it -> importer.newImporter(nodeOffset.getAndAdd(batchSize), it)
            );
            runWithConcurrency(concurrency, importers, executor);
        }
    }

    private  ParallelUtil();

}