Rows as Displayed in Screen

Rows from Database

Rows grouping Logic

	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

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.