Search code examples
javafor-loopserver-side

GWT Java - Server Side "for loop" not working


I am reading in a file in which each row has a column no, row number, detail. The file is sorted on column then row. I want to place the detail in a csv file in the correct row and column. So I am testing for change in row number and then add in line breaks ("\n").

The issue is that the System.out.println on each side of the for loop is being displayed in the log; however, the loop its self is not triggered (i.e., the line break is not added and the System.out.println is not appearing in the log.

The code is:

System.out.println("New row - " + Integer.parseInt(report.getReportDetailRow())+ " greater than current row - " + currentRow);
            currentCol = 0;
            //Add line breaks
            int j = Integer.parseInt(report.getReportDetailRow());
            for(int i = currentRow; i > j; i++){
                System.out.println("Append line break");
                fileContent.append("\n");
            }
            System.out.println("After append");
            currentRow = Integer.parseInt(report.getReportDetailRow());
            if (currentCol == Integer.parseInt(report.getReportDetailColumn())){
                fileContent.append(report.getReportDetailDetails() + ",");
                currentCol++;
            }else{
                //Add columns
                for(int i = currentCol; i == Integer.parseInt(report.getReportDetailColumn()); i++){
                    fileContent.append(",");
                }
                fileContent.append(report.getReportDetailDetails() + ",");
                currentCol = Integer.parseInt(report.getReportDetailColumn());
            }

Please note that I have use "i > j" instead of "i == j" to try to force a result.


Solution

  • In your statement for iterating through the rows, you have

    for(int i = currentRow; i > j; i++)
    

    If j is the number of current rows, then you need to change your condition to i < j to go through them all.