use of org.hisp.dhis.common.GridHeader in project dhis2-core by dhis2.
the class ListGrid method addCumulativeColumn.
@Override
public Grid addCumulativeColumn(int columnIndex, boolean addHeader) {
verifyGridState();
List<Object> column = getColumn(columnIndex);
List<Object> cumulativeColumn = new ArrayList<>();
double sum = 0d;
for (Object value : column) {
double number = value != null ? Double.parseDouble(String.valueOf(value)) : 0d;
sum += number;
cumulativeColumn.add(sum);
}
addColumn(cumulativeColumn);
if (addHeader && columnIndex < headers.size()) {
GridHeader header = headers.get(columnIndex);
if (header != null) {
GridHeader regressionHeader = new GridHeader(header.getName() + CUMULATIVE_SUFFIX, header.getColumn() + CUMULATIVE_SUFFIX, header.getValueType(), header.isHidden(), header.isMeta());
addHeader(regressionHeader);
}
}
return this;
}
use of org.hisp.dhis.common.GridHeader in project dhis2-core by dhis2.
the class ListGrid method toString.
// -------------------------------------------------------------------------
// toString
// -------------------------------------------------------------------------
@Override
public String toString() {
StringBuilder builder = new StringBuilder("[\n");
if (headers != null && headers.size() > 0) {
List<String> headerNames = new ArrayList<>();
for (GridHeader header : headers) {
headerNames.add(header.getName());
}
builder.append(headerNames).append("\n");
}
for (List<Object> row : grid) {
builder.append(row).append("\n");
}
return builder.append("]").toString();
}
use of org.hisp.dhis.common.GridHeader in project dhis2-core by dhis2.
the class ListGrid method addHeaders.
@Override
public Grid addHeaders(SqlRowSet rs) {
SqlRowSetMetaData rsmd = rs.getMetaData();
int columnNo = rsmd.getColumnCount();
for (int i = 1; i <= columnNo; i++) {
addHeader(new GridHeader(rsmd.getColumnLabel(i), false, false));
}
return this;
}
Aggregations