Skip to content

Commit

Permalink
refactor: Improve code style for ListGrid (#19429)
Browse files Browse the repository at this point in the history
  • Loading branch information
larshelge authored Dec 10, 2024
1 parent 0a5f10c commit 35fcda7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ left join analytics_rs_dateperiodstructure dps on cast(en.enrollmentdate as date
left join analytics_rs_orgunitstructure ous on en.organisationunitid=ous.organisationunitid \
left join analytics_rs_organisationunitgroupsetstructure ougs on en.organisationunitid=ougs.organisationunitid \
${attributeJoinClause}\
where pr.programid=${programId} \
where pr.programid = ${programId} \
and en.organisationunitid is not null \
and (ougs.startdate is null or dps.monthstartdate=ougs.startdate) \
and en.lastupdated <= '${startTime}' \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,11 +503,9 @@ public Grid addColumn(List<Object> columnValues) {

if (grid.size() != columnValues.size()) {
throw new IllegalStateException(
"Number of column values ("
+ columnValues.size()
+ ") is not equal to number of rows ("
+ grid.size()
+ ")");
String.format(
"Number of column values (%d) is not equal to number of rows (%d)",
columnValues.size(), grid.size()));
}

for (int i = 0; i < grid.size(); i++) {
Expand All @@ -526,11 +524,9 @@ public Grid addColumn(int columnIndex, List<Object> columnValues) {

if (grid.size() != columnValues.size()) {
throw new IllegalStateException(
"Number of column values ("
+ columnValues.size()
+ ") is not equal to number of rows ("
+ grid.size()
+ ")");
String.format(
"Number of column values (%d) is not equal to number of rows (%d)",
columnValues.size(), grid.size()));
}

for (int i = 0; i < grid.size(); i++) {
Expand Down Expand Up @@ -657,7 +653,7 @@ public Grid limitGrid(int limit) {
public Grid limitGrid(int startPos, int endPos) {
if (startPos < 0 || endPos < startPos || endPos > getHeight()) {
throw new IllegalStateException(
"Illegal start / end pos: " + startPos + ", " + endPos + ", " + getHeight());
"Illegal start or end pos: " + startPos + ", " + endPos + ", " + getHeight());
}

grid = grid.subList(startPos, endPos);
Expand Down Expand Up @@ -813,8 +809,9 @@ public Grid substituteMetaData(Map<?, ?> metaDataMap) {
header.setName(String.valueOf(headerMetaName));
}

// Column cells

if (header.isMeta()) {
// Column cells

substituteMetaData(colIndex, colIndex, metaDataMap);
}
Expand Down Expand Up @@ -1101,7 +1098,8 @@ public void repositionColumns(List<Integer> columnIndexes) {
row.addAll(orderedValues);
}

// reposition columns in the row context structure
// Reposition columns in the row context structure

Map<Integer, Map<String, Object>> orderedRowContext = new HashMap<>();

for (Map.Entry<Integer, Map<String, Object>> rowContextEntry : rowContext.entrySet()) {
Expand All @@ -1113,7 +1111,8 @@ public void repositionColumns(List<Integer> columnIndexes) {
.forEach(
key -> {
if (numberRegex.matcher(key).matches()) {
// reindexing of columns
// Reindexing of columns

orderedRowContextItems.put(
columnIndexes.get(Integer.parseInt(key)).toString(), ctxItem.get(key));
}
Expand Down Expand Up @@ -1151,12 +1150,9 @@ private void verifyGridState() {
for (List<Object> row : grid) {
if (rowLength != null && rowLength != row.size()) {
throw new IllegalStateException(
"Grid rows do not have the same number of cells, previous: "
+ rowLength
+ ", this: "
+ row.size()
+ ", at row: "
+ rowPos);
String.format(
"Grid rows do not have the same number of cells, previous: %d, this: %d, at row: %d",
rowLength, row.size(), rowPos));
}

rowPos++;
Expand All @@ -1177,7 +1173,7 @@ private void updateColumnIndexMap() {
}

// -------------------------------------------------------------------------
// toString
// ToString
// -------------------------------------------------------------------------

@Override
Expand Down

0 comments on commit 35fcda7

Please sign in to comment.