diff --git a/core/src/main/java/tech/tablesaw/api/Table.java b/core/src/main/java/tech/tablesaw/api/Table.java index 44c8c2578..ef4ec76c0 100644 --- a/core/src/main/java/tech/tablesaw/api/Table.java +++ b/core/src/main/java/tech/tablesaw/api/Table.java @@ -25,8 +25,11 @@ import java.util.List; import java.util.function.Consumer; import java.util.function.Predicate; +import java.util.stream.Stream; import com.google.common.base.Preconditions; +import com.google.common.collect.Iterators; +import com.google.common.collect.Streams; import com.google.common.primitives.Ints; import io.github.classgraph.ClassGraph; @@ -1024,50 +1027,35 @@ public boolean hasNext() { }; } + public Stream stream() { + return Streams.stream(iterator()); + } + /** * Applies the operation in {@code doable} to every row in the table + * @deprecated use {@code stream().forEach} */ public void doWithRows(Consumer doable) { - Row row = new Row(this); - while (row.hasNext()) { - doable.accept(row.next()); - } + stream().forEach(doable); } /** * Applies the predicate to each row, and return true if any row returns true + * @deprecated use {@code stream().anyMatch} */ public boolean detect(Predicate predicate) { - Row row = new Row(this); - while (row.hasNext()) { - if (predicate.test(row.next())) { - return true; - } - } - return false; + return stream().anyMatch(predicate); } /** * Applies the operation in {@code rowConsumer} to every series of n rows in the table + * @deprecated use {@code Streams.stream(Iterators.partition(iterator(), n)).forEach} */ public void stepWithRows(Consumer rowConsumer, int n) { - if (isEmpty()) { - return; - } - Row[] rows = new Row[n]; - for (int i = 0; i < n; i++) { - rows[i] = new Row(this); - } - - int max = rowCount() / n; - - for (int i = 0; i < max; i++) { //0, 1 - for (int r = 1; r <= n; r++) { - int row = i*n + r - 1; - rows[r-1].at(row); - } - rowConsumer.accept(rows); - } + Streams + .stream(Iterators.partition(iterator(), n)) + .map(list -> list.toArray(new Row[list.size()])) + .forEach(rowConsumer); } /**