DataFrameInlinePrintWorker extends BasePrintWorker { public StringBuilder print(DataFrame df) { if (df == null) { out.append("null"); return out; } DataFrameTruncator truncator = DataFrameTruncator.create(df, maxDisplayRows); Index columns = df.getColumnsIndex(); int width = columns.size(); int h = truncator.height(); String[] labels = columns.getLabels(); if (h == 0) { for (int j = 0; j < width; j++) { if (j > 0) { out.append(","); } appendTruncate(labels[j]); out.append(":"); } return out; } boolean comma = false; for (RowProxy p : truncator.head()) { if (comma) { out.append(","); } comma = true; out.append("{"); for (int j = 0; j < width; j++) { if (j > 0) { out.append(","); } appendTruncate(labels[j]); out.append(":"); appendTruncate(String.valueOf(p.get(j))); } out.append("}"); } if (truncator.isTruncated()) { if (comma) { out.append(","); } out.append("..."); for (RowProxy p : truncator.tail()) { out.append(",{"); for (int j = 0; j < width; j++) { if (j > 0) { out.append(","); } appendTruncate(labels[j]); out.append(":"); appendTruncate(String.valueOf(p.get(j))); } out.append("}"); } } return out; } DataFrameInlinePrintWorker(StringBuilder out, int maxDisplayRows, int maxDisplayColumnWith); StringBuilder print(DataFrame df);  }
@Test public void testToString_NoRows() { DataFrameInlinePrintWorker w = new DataFrameInlinePrintWorker(new StringBuilder(), 5, 10); assertEquals("a:,b:", w.print(DataFrame.newFrame("a", "b").empty()).toString()); }
@Test public void testToString() { DataFrameInlinePrintWorker w = new DataFrameInlinePrintWorker(new StringBuilder(), 5, 10); assertEquals("{col1:one,column2:1},{col1:two,column2:2},{col1:three,column2:3},{col1:four,column2:4}", w.print(df).toString()); }
@Test public void testToString_TruncateRows() { DataFrameInlinePrintWorker w = new DataFrameInlinePrintWorker(new StringBuilder(), 2, 10); assertEquals("{col1:one,column2:1},...,{col1:four,column2:4}", w.print(df).toString()); }
@Test public void testToString_TruncateColumns() { DataFrameInlinePrintWorker w = new DataFrameInlinePrintWorker(new StringBuilder(), 5, 4); assertEquals("{col1:one,c..2:1},{col1:two,c..2:2},{col1:t..e,c..2:3},{col1:four,c..2:4}", w.print(df).toString()); }