public RowGroup newRowGroup() { RowGroup rowGroup = new RowGroup(this); this.rowGroups.add(rowGroup); return rowGroup; }
public List<String> buildTableList() { List<String> list = new ArrayList<>(); for (RowGroup rowGroup : this.rowGroups) { list.add(rowGroup.buildRowGroup(isTabularResult)); } return list; }
public String buildRowGroup(boolean isTabularResult) { this.colSizes = computeColSizes(isTabularResult); StringBuilder stringBuffer = new StringBuilder(); for (Row row : rows) { String builtRow = row.buildRow(isTabularResult); stringBuffer.append(builtRow); if (StringUtils.isNotBlank(builtRow) || row.isBlank) { stringBuffer.append(GfshParser.LINE_SEPARATOR); } } return stringBuffer.toString(); }
} else if (key.equals(CompositeResultData.SEPARATOR)) { String separatorString = section.getString(key); rowGroup.newRowSeparator(separatorString.charAt(0), true); } else if (key.equals(ResultData.RESULT_HEADER) || key.equals(ResultData.RESULT_FOOTER)) { Row newRow = rowGroup.newRow(); String prefix = ""; for (int i = 0; i < depth; i++) { newRow.newLeftCol(prefix + key).newLeftCol(value[0]); for (int i = 1; i < value.length; i++) { newRow = rowGroup.newRow(); newRow.setColumnSeparator(" "); newRow.newLeftCol("").newLeftCol(value[i]);
stringBuffer.append(this.rowGroup.getColumnSeparator());
private void buildComposite() { try { GfJsonObject content = getContent(); if (content != null) { Table resultTable = TableBuilder.newTable(); resultTable.setColumnSeparator(" : "); addHeaderInTable(resultTable, getGfJsonObject()); for (Iterator<String> it = content.keys(); it.hasNext();) { String key = it.next(); if (key.startsWith(ResultData.SECTION_DATA_ACCESSOR)) { GfJsonObject subSection = content.getJSONObject(key); buildSection(resultTable, null, subSection, 0); } else if (key.equals(CompositeResultData.SEPARATOR)) { String separatorString = content.getString(key); resultTable.newRowGroup().newRowSeparator(separatorString.charAt(0), true); } } addFooterInTable(resultTable, getGfJsonObject()); resultLines.addAll(resultTable.buildTableList()); } } catch (GfJsonException e) { resultLines .add("Error occurred while processing Command Result. Internal Error - Invalid Result."); logger.info( "Error occurred while processing Command Result. Internal Error - Invalid Result.", e); } finally { isDataBuilt = true; } }
/** * Computes total Max Row Length across table - for all row groups. */ private int getMaxLength() { int rowGroupMaxTotalLength = 0; for (RowGroup rowGroup : this.rowGroups) { List<Row> rows = rowGroup.rows; int rowGroupTotalLength = 0; int rowMaxTotalLength = 0; for (Row row : rows) { int rowTotalLength = 0; for (int i = 0; i < row.getNumCols(); i++) { rowTotalLength += row.getMaxColLength(i); } if (rowGroup.getColumnSeparator() != null) { rowTotalLength += row.getNumCols() * rowGroup.getColumnSeparator().length(); } if (rowMaxTotalLength < rowTotalLength) { rowMaxTotalLength = rowTotalLength; } } rowGroupTotalLength += rowMaxTotalLength; if (rowGroupMaxTotalLength < rowGroupTotalLength) { rowGroupMaxTotalLength = rowGroupTotalLength; } } return (int) (rowGroupMaxTotalLength * 1.1); }
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); } }
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(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 Row[] buildRows(RowGroup rowGroup, Row[] dataRows, GfJsonArray accumulatedData) throws GfJsonException { int size = accumulatedData.size(); // Initialize rows' array as required if (dataRows == null) { dataRows = new Row[size]; for (int j = 0; j < dataRows.length; j++) { dataRows[j] = rowGroup.newRow(); } } // Add data column-wise for (int j = 0; j < size; j++) { dataRows[j].newLeftCol(accumulatedData.get(j)); } return dataRows; }
public String getColumnSeparator() { return this.columnSeparator != null ? this.columnSeparator : rowGroup.getColumnSeparator(); }
public void newBlankRow() { RowGroup rowGroup = newRowGroup(); rowGroup.newBlankRow(); }
private void addRowInRowGroup(TableBuilder.RowGroup rowGroup, String row) { if (row != null && !row.isEmpty()) { rowGroup.newRow().newLeftCol(row); } }
private void addHeaderInRowGroup(RowGroup rowGroup, GfJsonObject fromJsonObject) { String header = getHeader(fromJsonObject); if (header != null && !header.isEmpty()) { rowGroup.newRow().newLeftCol(header); } }
private void addFooterInRowGroup(RowGroup rowGroup, GfJsonObject fromJsonObject) { String footer = getFooter(fromJsonObject); if (footer != null && !footer.isEmpty()) { rowGroup.newRow().newLeftCol(footer); } }
private void buildInfoOrErrorCommandOutput(TableBuilder.Table resultTable, InfoResultModel model) { TableBuilder.RowGroup rowGroup = resultTable.newRowGroup(); addRowInRowGroup(rowGroup, model.getHeader()); model.getContent().forEach(c -> rowGroup.newRow().newLeftCol(c)); addRowInRowGroup(rowGroup, model.getFooter()); } }
public void newBlankRow() { Row row = newRow(); row.newCenterCol(""); row.isBlank = true; }
private int[] computeColSizes(boolean isTabularResult) { int[] localColSizes = new int[getNumCols()]; for (int i = 0; i < localColSizes.length; i++) { localColSizes[i] = getMaxColLength(i); } if (isTabularResult) { localColSizes = TableBuilderHelper.recalculateColSizesForScreen( TableBuilderHelper.getScreenWidth(), localColSizes, getColumnSeparator()); } return localColSizes; }
private int getMaxColLength(final int colNum) { int maxLength = 0; for (Row row : rows) { int colLength = row.getMaxColLength(colNum); if (colLength > maxLength) { maxLength = colLength; } } return maxLength; }