Rows as Displayed in Screen

Rows from Database

Rows grouping Logic

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
List<RowsBean> outputList = RowsToBeDisplayedList;   
 
HashMap<String, ArrayList>  superGroupPoints    = new HashMap<String, ArrayList>();
HashMap<String, EWMDecimal> subGroupTotalPoints = new HashMap<String, Integer>();
 
String groupName = null;
String prevGroupName = null;
String superGroupName = null;
String prevSuperGroupName = null;
 
List<Map> subGroupPointsList = new ArrayList();
 
 
//Compute grouping totals
Iterator itr = cicCarryPointsList.iterator();
 
 while(itr.hasNext())
 {
  RowsBean rowBean = (RowsBean) itr.next();  
  superGroupName   = rowBean.getSuperGroupName();
  groupName      = rowBean.getGroupName();
   
          //Addition of points summed at Group Level
  if ((prevGroupName != null && !prevGroupName.equals(groupName))
      || (prevSuperGroupName != null &&    !prevSuperGroupName.equals(superGroupName)))
  {
     subGroupPointsList.add(subGroupTotalPoints);
     subGroupTotalPoints = new HashMap<String, Integer>();
  }
   
   
  //Rows at GroupLevel with Sub Groups should be added only when Super Group Changes
  if((prevSuperGroupName != null && !prevSuperGroupName.equals(superGroupName)))
  {       
     superGroupPoints.put(prevSuperGroupName, (ArrayList) subGroupPointsList);
     subGroupPointsList = new ArrayList();
  }
   
  Integer subGroupValPoints = rowBean.getPoints();       
 
  //If InvGrp level Map exists
  if (subGroupTotalPoints.get(groupName) != null) {
    Integer currSummedPointsAtGrpLevel = subGroupTotalPoints.get(groupName);
    currSummedPointsAtGrpLevel = currSummedPointsAtGrpLevel.add(subGroupValPoints);
    subGroupTotalPoints.put(groupName, currSummedPointsAtGrpLevel);      
  } else {
    subGroupTotalPoints.put(groupName, subGroupValPoints);
  }
   
  //Incase of last element the loop exits without adding last summed element
  //To prevent that we add it with out current and prev comparison
  if(!itr.hasNext())
  {
    subGroupPointsList.add(subGroupTotalPoints);       
    superGroupPoints.put(superGroupName, (ArrayList) subGroupPointsList);
  }
   
  prevSuperGroupName = superGroupName;
  prevGroupName = groupName;
}

Retrieval of Rows for Displaying in Screen

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
String currentSuperGrouping = "";
String prevSuperGrouping    = "";
String currGrouping = "";
String prevGrouping = "";
String Value = "";
  
for (RowsBean rowBean : outputList)
{
  currentSuperGrouping = rowBean.getSuperGroupName();
  currGrouping = rowBean.getGroupName();
 
    //Level 1 - New Super Group Creation
  //New Super Group should be created when ever prevSuperGrouping and  currentSuperGrouping are different
    if (!currentSuperGrouping.equals(prevSuperGrouping))
    {
      .
      
      Super Group Row Creation HTML Code Goes Here
      .
      .
      .
    }
      
    //Level 2 - Group addition under Super Group
  //New Group should be created when ever SuperGroup or Group Changes
    if(!currGrouping.equals(prevGrouping) || !currentSuperGrouping.equals(prevSuperGrouping))
    {
      //Taking Group Level Maps List
      ArrayList GroupLevelMapList = superGroup.get(rowBean.getGroupName());
      Iterator  itr =  GroupLevelMapList.iterator();
        
    //Taking the Summed up value at Group Level from List
      while (itr.hasNext())
      {
         Map ii = (Map) itr.next();
         Points = ii.get(rowBean.getGroupName());     
      
        
      .
      
      Group Row Creation HTML Code Goes Here
      .
      .
      .
    }
      
    //Level 3 - Sub Group Rows Addition
  //Rows will be added
    if(currentSuperGrouping.equals(rowBean.getGroupName) || currentSuperGrouping.equals(rowBean.getSubGroupName))
    {
      .
      
      Sub Group Row Creation HTML Code Goes Here
      .
      .
      .
    }
      
    prevSuperGrouping    = currentSuperGrouping;
    prevGrouping = currGrouping;
}

Comments are closed.