/** * 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); }
/** * 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); }