private void buildTable(TableBuilder.RowGroup rowGroup, TabularResultModel model) { TableBuilder.Row headerRow = rowGroup.newRow(); rowGroup.setColumnSeparator(" | "); rowGroup.newRowSeparator('-', false); Map<String, List<String>> rows = model.getContent(); if (!rows.isEmpty()) { // build table header first rows.keySet().forEach(c -> headerRow.newCenterCol(c)); // each row should have the same number of entries, so just look at the first one int rowCount = rows.values().iterator().next().size(); for (int i = 0; i < rowCount; i++) { TableBuilder.Row oneRow = rowGroup.newRow(); for (String column : rows.keySet()) { oneRow.newLeftCol(rows.get(column).get(i)); } } } }
private void buildData(TableBuilder.Table resultTable, DataResultModel section) { TableBuilder.RowGroup rowGroup = resultTable.newRowGroup(); rowGroup.setColumnSeparator(" : "); addRowInRowGroup(rowGroup, section.getHeader()); // finally process map values for (Map.Entry<String, String> entry : section.getContent().entrySet()) { TableBuilder.Row newRow = rowGroup.newRow(); String key = entry.getKey(); String value = entry.getValue(); String[] values = entry.getValue().split(GfshParser.LINE_SEPARATOR); if (values.length == 1) { newRow.newLeftCol(key).newLeftCol(values[0]); } else { if (values.length != 0) { // possible when object == CliConstants.LINE_SEPARATOR newRow.newLeftCol(key).newLeftCol(values[0]); for (int i = 1; i < values.length; i++) { newRow = rowGroup.newRow(); newRow.setColumnSeparator(" "); newRow.newLeftCol("").newLeftCol(values[i]); } } else { newRow.newLeftCol(key).newLeftCol(""); } } } addRowInRowGroup(rowGroup, section.getFooter()); }
private void buildTable(RowGroup rowGroup, GfJsonObject content) throws GfJsonException { GfJsonArray columnNames = content.names(); int numOfColumns = columnNames.size(); Row headerRow = rowGroup.newRow(); rowGroup.setColumnSeparator(" | "); rowGroup.newRowSeparator('-', false); // build Table Header first for (int i = 0; i < numOfColumns; i++) { Object object = columnNames.get(i); if (ResultData.BYTE_DATA_ACCESSOR.equals(object)) { // skip file data if any continue; } headerRow.newCenterCol(object); } // Build remaining rows by extracting data column-wise from JSON object Row[] dataRows = null; for (int i = 0; i < numOfColumns; i++) { Object object = columnNames.get(i); if (ResultData.BYTE_DATA_ACCESSOR.equals(object)) { // skip file data if any continue; } GfJsonArray accumulatedData = content.getJSONArray((String) object); dataRows = buildRows(rowGroup, dataRows, accumulatedData); } }