/** * Create a sequence of nodes that iterates over the supplied batches of nodes. Note that the supplied iterator is accessed * lazily as the resulting sequence instance is {@link #nextBatch() used}. * * @param batches the iterable container containing the node batches to be returned; if null, an {@link #emptySequence empty * instance} is returned * @param width the width of the batch; must be positive * @return the sequence of nodes; never null */ public static NodeSequence withBatches( final Collection<Batch> batches, final int width ) { if (batches == null || batches.isEmpty()) return emptySequence(width); if (batches.size() == 1) { Batch batch = batches.iterator().next(); assert width == batch.width(); return withBatch(batch); } // Tally the size of each batch ... long rowCount = 0L; for (Batch batch : batches) { long count = batch.rowCount(); rowCount = count < 0L ? -1L : rowCount + count; } return withBatches(batches.iterator(), width, rowCount); }
/** * Create a sequence of nodes that iterates over the supplied batches of nodes. Note that the supplied iterator is accessed * lazily as the resulting sequence instance is {@link #nextBatch() used}. * * @param batches the iterable container containing the node batches to be returned; if null, an {@link #emptySequence empty * instance} is returned * @param width the width of the batch; must be positive * @return the sequence of nodes; never null */ public static NodeSequence withBatches( final Collection<Batch> batches, final int width ) { if (batches == null || batches.isEmpty()) return emptySequence(width); if (batches.size() == 1) { Batch batch = batches.iterator().next(); assert width == batch.width(); return withBatch(batch); } // Tally the size of each batch ... long rowCount = 0L; for (Batch batch : batches) { long count = batch.rowCount(); rowCount = count < 0L ? -1L : rowCount + count; } return withBatches(batches.iterator(), width, rowCount); }
protected NodeSequence multipleBatchesOf( Iterator<NodeKey> keys, float score, int sizeOfBatches ) { List<NodeKey> listOfKeys = new ArrayList<>(); List<Batch> batches = new ArrayList<>(); while (keys.hasNext()) { for (int i = 0; i != sizeOfBatches; ++i) { if (!keys.hasNext()) break; listOfKeys.add(keys.next()); } batches.add(NodeSequence.batchOfKeys(listOfKeys.iterator(), listOfKeys.size(), score, workspaceName(), cache)); listOfKeys = new ArrayList<>(); } return NodeSequence.withBatches(batches, 1); }