@Test public void testFoldIterableByRow() { DataFrame df = DataFrameBuilder .builder("a", "b") .foldIterableByRow(asList("a", 1, "b", 2, "c", 3)); new DataFrameAsserts(df, "a", "b").expectHeight(3) .expectRow(0, "a", 1) .expectRow(1, "b", 2) .expectRow(2, "c", 3); }
public <T> DataFrame foldIterableByRow(Iterable<T> iterable) { int width = columnsIndex.size(); if (width == 0) { throw new IllegalArgumentException("Empty columns"); } int heightEstimate = (iterable instanceof Collection) ? ((Collection) iterable).size() : 10; Accumulator<Object>[] columnBuilders = new Accumulator[width]; for (int i = 0; i < width; i++) { columnBuilders[i] = new ObjectAccumulator<>(heightEstimate); } int p = 0; for (Object o : iterable) { columnBuilders[p % width].add(o); p++; } int pl = p % width; if (pl > 0) { for (; pl < width; pl++) { columnBuilders[pl].add(null); } } Series<?>[] series = new Series[columnBuilders.length]; for (int i = 0; i < columnBuilders.length; i++) { series[i] = columnBuilders[i].toSeries(); } return new ColumnDataFrame(columnsIndex, series); }
DataFrameBuilder { public <T> DataFrame foldIterableByRow(Iterable<T> iterable) { int width = columnsIndex.size(); if (width == 0) { throw new IllegalArgumentException("Empty columns"); } int heightEstimate = (iterable instanceof Collection) ? ((Collection) iterable).size() : 10; Accumulator<Object>[] columnBuilders = new Accumulator[width]; for (int i = 0; i < width; i++) { columnBuilders[i] = new ObjectAccumulator<>(heightEstimate); } int p = 0; for (Object o : iterable) { columnBuilders[p % width].add(o); p++; } int pl = p % width; if (pl > 0) { for (; pl < width; pl++) { columnBuilders[pl].add(null); } } Series<?>[] series = new Series[columnBuilders.length]; for (int i = 0; i < columnBuilders.length; i++) { series[i] = columnBuilders[i].toSeries(); } return new ColumnDataFrame(columnsIndex, series); } }
DataFrameBuilder { public <T> DataFrame foldIterableByRow(Iterable<T> iterable) { int width = columnsIndex.size(); if (width == 0) { throw new IllegalArgumentException("Empty columns"); } int heightEstimate = (iterable instanceof Collection) ? ((Collection) iterable).size() : 10; Accumulator<Object>[] columnBuilders = new Accumulator[width]; for (int i = 0; i < width; i++) { columnBuilders[i] = new ObjectAccumulator<>(heightEstimate); } int p = 0; for (Object o : iterable) { columnBuilders[p % width].add(o); p++; } int pl = p % width; if (pl > 0) { for (; pl < width; pl++) { columnBuilders[pl].add(null); } } Series<?>[] series = new Series[columnBuilders.length]; for (int i = 0; i < columnBuilders.length; i++) { series[i] = columnBuilders[i].toSeries(); } return new ColumnDataFrame(columnsIndex, series); } protected  DataFrameBuilder(Index columnsIndex); }
DataFrameBuilder { public <T> DataFrame foldIterableByRow(Iterable<T> iterable) { int width = columnsIndex.size(); if (width == 0) { throw new IllegalArgumentException("Empty columns"); } int heightEstimate = (iterable instanceof Collection) ? ((Collection) iterable).size() : 10; Accumulator<Object>[] columnBuilders = new Accumulator[width]; for (int i = 0; i < width; i++) { columnBuilders[i] = new ObjectAccumulator<>(heightEstimate); } int p = 0; for (Object o : iterable) { columnBuilders[p % width].add(o); p++; } int pl = p % width; if (pl > 0) { for (; pl < width; pl++) { columnBuilders[pl].add(null); } } Series<?>[] series = new Series[columnBuilders.length]; for (int i = 0; i < columnBuilders.length; i++) { series[i] = columnBuilders[i].toSeries(); } return new ColumnDataFrame(columnsIndex, series); } protected  DataFrameBuilder(Index columnsIndex); static DataFrameBuilder builder(String... columnLabels); static DataFrameBuilder builder(Index columnsIndex); DataFrame empty(); DataFrame columns(Series<?>... columns); DataFrame rows(Object[]... rows); DataFrameByRowBuilder byRow(); DataFrameByRowBuilder addRow(Object... row); DataFrame foldByRow(Object... data); DataFrame foldByColumn(Object... data); DataFrame foldStreamByRow(Stream<T> stream); DataFrame foldStreamByColumn(Stream<T> stream); DataFrame foldIterableByRow(Iterable<T> iterable); DataFrame foldIterableByColumn(Iterable<T> iterable); DataFrame objectsToRows(Iterable<T> objects, Function<T, Object[]> rowMapper); DataFrame foldIntByColumn(int padWith, int... data); DataFrame foldIntStreamByRow(IntStream stream); DataFrame foldIntStreamByRow(int padWith, IntStream stream); DataFrame foldIntStreamByColumn(IntStream stream); DataFrame foldIntStreamByColumn(int padWith, IntStream stream); DataFrame foldLongByColumn(long padWith, long... data); DataFrame foldLongStreamByRow(LongStream stream); DataFrame foldLongStreamByRow(long padWith, LongStream stream); DataFrame foldLongStreamByColumn(LongStream stream); DataFrame foldLongStreamByColumn(long padWith, LongStream stream); DataFrame foldDoubleByColumn(double padWith, double... data); DataFrame foldDoubleStreamByRow(DoubleStream stream); DataFrame foldDoubleStreamByRow(double padWith, DoubleStream stream); DataFrame foldDoubleStreamByColumn(DoubleStream stream); DataFrame foldDoubleStreamByColumn(double padWith, DoubleStream stream); }
DataFrameBuilder { public <T> DataFrame foldIterableByRow(Iterable<T> iterable) { int width = columnsIndex.size(); if (width == 0) { throw new IllegalArgumentException("Empty columns"); } int heightEstimate = (iterable instanceof Collection) ? ((Collection) iterable).size() : 10; Accumulator<Object>[] columnBuilders = new Accumulator[width]; for (int i = 0; i < width; i++) { columnBuilders[i] = new ObjectAccumulator<>(heightEstimate); } int p = 0; for (Object o : iterable) { columnBuilders[p % width].add(o); p++; } int pl = p % width; if (pl > 0) { for (; pl < width; pl++) { columnBuilders[pl].add(null); } } Series<?>[] series = new Series[columnBuilders.length]; for (int i = 0; i < columnBuilders.length; i++) { series[i] = columnBuilders[i].toSeries(); } return new ColumnDataFrame(columnsIndex, series); } protected  DataFrameBuilder(Index columnsIndex); static DataFrameBuilder builder(String... columnLabels); static DataFrameBuilder builder(Index columnsIndex); DataFrame empty(); DataFrame columns(Series<?>... columns); DataFrame rows(Object[]... rows); DataFrameByRowBuilder byRow(); DataFrameByRowBuilder addRow(Object... row); DataFrame foldByRow(Object... data); DataFrame foldByColumn(Object... data); DataFrame foldStreamByRow(Stream<T> stream); DataFrame foldStreamByColumn(Stream<T> stream); DataFrame foldIterableByRow(Iterable<T> iterable); DataFrame foldIterableByColumn(Iterable<T> iterable); DataFrame objectsToRows(Iterable<T> objects, Function<T, Object[]> rowMapper); DataFrame foldIntByColumn(int padWith, int... data); DataFrame foldIntStreamByRow(IntStream stream); DataFrame foldIntStreamByRow(int padWith, IntStream stream); DataFrame foldIntStreamByColumn(IntStream stream); DataFrame foldIntStreamByColumn(int padWith, IntStream stream); DataFrame foldLongByColumn(long padWith, long... data); DataFrame foldLongStreamByRow(LongStream stream); DataFrame foldLongStreamByRow(long padWith, LongStream stream); DataFrame foldLongStreamByColumn(LongStream stream); DataFrame foldLongStreamByColumn(long padWith, LongStream stream); DataFrame foldDoubleByColumn(double padWith, double... data); DataFrame foldDoubleStreamByRow(DoubleStream stream); DataFrame foldDoubleStreamByRow(double padWith, DoubleStream stream); DataFrame foldDoubleStreamByColumn(DoubleStream stream); DataFrame foldDoubleStreamByColumn(double padWith, DoubleStream stream);  }