/** * 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); }
if (batch == null || batch.isEmpty() || batch.rowCount() == 0 || filter == null || batch.width() < 1) return batch; return new Batch() { private boolean atNext = false;
if (batch == null || batch.isEmpty() || batch.rowCount() == 0 || filter == null || batch.width() < 1) return batch; return new Batch() { private boolean atNext = false;
/** * Create a copy of a batch that always has a {@link Batch#rowCount()}. * * @param batch the original batch; may be null * @return the batch that has a true {@link Batch#rowCount()}, or the original batch if null or empty or if the original has a * non-negative row count */ public static Batch copy( Batch batch ) { if (batch == null) return batch; if (batch.isEmpty() || batch.width() < 1) return emptyBatch(batch.getWorkspaceName(), 1); // Otherwise, create a copy ... return batch.width() == 1 ? new SingleWidthBatch(batch) : new MultiWidthBatch(batch); }
/** * Create a batch that always has a {@link Batch#rowCount()}, even if that means returning a new Batch that buffers the * original's rows it into memory. * * @param batch the original batch; may be null * @return the batch that has a true {@link Batch#rowCount()}, or the original batch if null or empty or if the original has a * non-negative row count */ public static Batch batchWithCount( Batch batch ) { if (batch == null || batch.isEmpty() || batch.rowCount() >= 0 || batch.width() < 1) return batch; // Otherwise, the batch doesn't know it's row count, so we have to copy it ... return batch.width() == 1 ? new SingleWidthBatch(batch) : new MultiWidthBatch(batch); }
@Override public int width() { return batch.width(); }
@Override public int width() { return original.width(); }
@Override public int width() { return sequence.width(); }
/** * Create a copy of a batch that always has a {@link Batch#rowCount()}. * * @param batch the original batch; may be null * @return the batch that has a true {@link Batch#rowCount()}, or the original batch if null or empty or if the original has a * non-negative row count */ public static Batch copy( Batch batch ) { if (batch == null) return batch; if (batch.isEmpty() || batch.width() < 1) return emptyBatch(batch.getWorkspaceName(), 1); // Otherwise, create a copy ... return batch.width() == 1 ? new SingleWidthBatch(batch) : new MultiWidthBatch(batch); }
@Override public int width() { return original.width(); }
@Override public int width() { return original.width(); }
@Override public int width() { return batch.width(); }
@Override public int width() { return sequence.width(); }
@Override public int width() { return original.width(); }
/** * Create a batch that always has a {@link Batch#rowCount()}, even if that means returning a new Batch that buffers the * original's rows it into memory. * * @param batch the original batch; may be null * @return the batch that has a true {@link Batch#rowCount()}, or the original batch if null or empty or if the original has a * non-negative row count */ public static Batch batchWithCount( Batch batch ) { if (batch == null || batch.isEmpty() || batch.rowCount() >= 0 || batch.width() < 1) return batch; // Otherwise, the batch doesn't know it's row count, so we have to copy it ... return batch.width() == 1 ? new SingleWidthBatch(batch) : new MultiWidthBatch(batch); }
@Override public int width() { return original.width(); }
@Override public int width() { return original.width(); }