Example usage for org.apache.poi.hssf.usermodel HSSFCell setCellValue

List of usage examples for org.apache.poi.hssf.usermodel HSSFCell setCellValue

Introduction

In this page you can find the example usage for org.apache.poi.hssf.usermodel HSSFCell setCellValue.

Prototype

@SuppressWarnings("fallthrough")
public void setCellValue(boolean value) 

Source Link

Document

set a boolean value for the cell

Usage

From source file:com.nokia.s60tools.swmtanalyser.model.ExcelCreator.java

License:Open Source License

private void createFreeSlackTab() {
    HSSFSheet sheet = wb.createSheet();/*from   www .ja  v  a  2 s . co m*/
    // declare a row object reference
    HSSFRow row = null;
    HSSFRow description = null;
    // declare a cell object reference
    HSSFCell cell = null;

    //set the sheet name in Unicode
    wb.setSheetName(9, "Free Slack");

    row = sheet.createRow(0);
    //r.setHeight((short)500);

    cell = row.createCell(0);
    cell.setCellStyle(styles.get("header"));
    cell.setCellValue(new HSSFRichTextString("Free slack"));

    description = sheet.createRow(1);

    //creates an empty row.
    row = sheet.createRow(2);

    row = sheet.createRow(3);
    cell = row.createCell(0);
    cell.setCellStyle(styles.get("header1"));
    cell.setCellValue(new HSSFRichTextString("Threads"));
    addCycleIntervals(row);

    cell = row.createCell((int) row.getLastCellNum());
    cell.setCellStyle(styles.get("header2"));
    cell.setCellValue(new HSSFRichTextString("Delta"));

    int rowNo = 4;

    for (String heap : heapThreads) {
        row = sheet.createRow(rowNo);
        cell = row.createCell(0);
        cell.setCellStyle(styles.get("cell_normal"));
        cell.setCellValue(new HSSFRichTextString(heap));

        ArrayList<ThreadData> heapValues = heapData.get(heap.toLowerCase());

        if (heapValues != null) {
            int j = 1;
            for (int i = 0; i < heapValues.size(); i++) {
                if (constants.contains(i + 1))
                    continue;

                cell = row.createCell(j++);
                cell.setCellStyle(styles.get("cell_number"));
                ThreadData thData = heapValues.get(i);

                if (thData.getStatus() == 0) {
                    //cell.getCellStyle().setAlignment(HSSFCellStyle.ALIGN_CENTER);
                    cell.setCellValue(new HSSFRichTextString(NOT_AVAILABLE));
                } else
                    cell.setCellValue(thData.getFreeSlackSize());
            }
        }
        cell = row.createCell(logData.getNumberOfCycles() + 1 - constants.size());
        cell.setCellStyle(styles.get("cell_number"));

        if (deltaData.get(heap.toLowerCase()) != null) {
            long heapSlackDelta = deltaData.get(heap.toLowerCase()).getFreeSlackSize();
            cell.setCellValue(heapSlackDelta);
        } else
            cell.setCellValue(0);

        rowNo++;
    }
    for (int i = 0; i <= logData.getNumberOfCycles(); i++) {
        sheet.autoSizeColumn((short) i);
    }

    cell = description.createCell(0);
    cell.setCellValue(new HSSFRichTextString(
            "Specifies the free slack size for each thread in bytes, for each cycle in seconds"));
}

From source file:com.nokia.s60tools.swmtanalyser.model.ExcelCreator.java

License:Open Source License

private void createLargestAllocSizeTab() {
    HSSFSheet sheet = wb.createSheet();/*from ww  w  .j av a 2s.  c  o m*/
    // declare a row object reference
    HSSFRow row = null;
    HSSFRow description = null;
    // declare a cell object reference
    HSSFCell cell = null;

    //set the sheet name in Unicode
    wb.setSheetName(10, "Largest allocated cell size in heap");

    row = sheet.createRow(0);
    //r.setHeight((short)500);

    cell = row.createCell(0);
    cell.setCellStyle(styles.get("header"));
    cell.setCellValue(new HSSFRichTextString("Largest allocated cell size in heap"));

    sheet.autoSizeColumn((short) 0);

    description = sheet.createRow(1);

    //creates an empty row.
    row = sheet.createRow(2);

    row = sheet.createRow(3);
    cell = row.createCell(0);
    cell.setCellStyle(styles.get("header1"));
    cell.setCellValue(new HSSFRichTextString("Threads"));
    addCycleIntervals(row);

    cell = row.createCell((int) row.getLastCellNum());
    cell.setCellStyle(styles.get("header2"));
    cell.setCellValue(new HSSFRichTextString("Delta"));

    int rowNo = 4;

    for (String heap : heapThreads) {
        row = sheet.createRow(rowNo);
        cell = row.createCell(0);
        cell.setCellStyle(styles.get("cell_normal"));
        cell.setCellValue(new HSSFRichTextString(heap));

        ArrayList<ThreadData> heapValues = heapData.get(heap.toLowerCase());

        if (heapValues != null) {
            int j = 1;
            for (int i = 0; i < heapValues.size(); i++) {
                if (constants.contains(i + 1))
                    continue;

                cell = row.createCell(j++);
                cell.setCellStyle(styles.get("cell_number"));
                ThreadData thData = heapValues.get(i);

                if (thData.getStatus() == 0) {
                    //cell.getCellStyle().setAlignment(HSSFCellStyle.ALIGN_CENTER);
                    cell.setCellValue(new HSSFRichTextString(NOT_AVAILABLE));
                } else
                    cell.setCellValue(thData.getLargestAllocCellSize());
            }
        }
        cell = row.createCell(logData.getNumberOfCycles() + 1 - constants.size());
        cell.setCellStyle(styles.get("cell_number"));

        if (deltaData.get(heap.toLowerCase()) != null) {
            long largetAllocCellDelta = deltaData.get(heap.toLowerCase()).getLargestAllocCellSize();
            cell.setCellValue(largetAllocCellDelta);
        } else
            cell.setCellValue(0);

        rowNo++;
    }
    for (int i = 0; i <= logData.getNumberOfCycles(); i++) {
        sheet.autoSizeColumn((short) i);
    }

    cell = description.createCell(0);
    cell.setCellValue(new HSSFRichTextString(
            "Specifies the largest allocated cell size in heap for each thread in bytes, for each cycle in seconds"));
}

From source file:com.nokia.s60tools.swmtanalyser.model.ExcelCreator.java

License:Open Source License

private void createLargestFreeSizeTab() {
    HSSFSheet sheet = wb.createSheet();//from www.  j ava 2 s  . c  o  m
    // declare a row object reference
    HSSFRow row = null;
    HSSFRow description = null;
    // declare a cell object reference
    HSSFCell cell = null;

    //set the sheet name in Unicode
    wb.setSheetName(11, "Largest free cell size in heap");

    row = sheet.createRow(0);
    //r.setHeight((short)500);

    cell = row.createCell(0);
    cell.setCellStyle(styles.get("header"));
    cell.setCellValue(new HSSFRichTextString("Largest free cell size in heap"));

    description = sheet.createRow(1);

    //creates an empty row.
    row = sheet.createRow(2);

    row = sheet.createRow(3);
    cell = row.createCell(0);
    cell.setCellStyle(styles.get("header1"));
    cell.setCellValue(new HSSFRichTextString("Threads"));
    addCycleIntervals(row);

    cell = row.createCell((int) row.getLastCellNum());
    cell.setCellStyle(styles.get("header2"));
    cell.setCellValue(new HSSFRichTextString("Delta"));

    int rowNo = 4;

    for (String heap : heapThreads) {
        row = sheet.createRow(rowNo);
        cell = row.createCell(0);
        cell.setCellStyle(styles.get("cell_normal"));
        cell.setCellValue(new HSSFRichTextString(heap));

        ArrayList<ThreadData> heapValues = heapData.get(heap.toLowerCase());

        if (heapValues != null) {
            int j = 1;
            for (int i = 0; i < heapValues.size(); i++) {
                if (constants.contains(i + 1))
                    continue;

                cell = row.createCell(j++);
                cell.setCellStyle(styles.get("cell_number"));
                ThreadData thData = heapValues.get(i);

                if (thData.getStatus() == 0) {
                    //cell.getCellStyle().setAlignment(HSSFCellStyle.ALIGN_CENTER);
                    cell.setCellValue(new HSSFRichTextString(NOT_AVAILABLE));
                } else
                    cell.setCellValue(thData.getLargestFreeCellSize());
            }
        }

        cell = row.createCell(logData.getNumberOfCycles() + 1 - constants.size());
        cell.setCellStyle(styles.get("cell_number"));

        if (deltaData.get(heap.toLowerCase()) != null) {
            long largestFreeCellDelta = deltaData.get(heap.toLowerCase()).getLargestFreeCellSize();
            cell.setCellValue(largestFreeCellDelta);
        } else
            cell.setCellValue(0);

        rowNo++;
    }
    for (int i = 0; i <= logData.getNumberOfCycles(); i++) {
        sheet.autoSizeColumn((short) i);
    }

    cell = description.createCell(0);
    cell.setCellValue(new HSSFRichTextString(
            "Specifies the largest free cell size in heap for each thread in bytes, for each cycle in seconds"));
}

From source file:com.nokia.s60tools.swmtanalyser.model.ExcelCreator.java

License:Open Source License

/**
 * This method creates the sheet for Global Data.
 * //from w ww .  jav a 2 s.c  o m
 *
 */
private void createGlobalChunksSheet() {
    HSSFSheet sheet = wb.createSheet();
    // declare a row object reference
    HSSFRow row = null;
    HSSFRow description = null;
    // declare a cell object reference
    HSSFCell cell = null;

    //set the sheet name in Unicode
    wb.setSheetName(2, "Global Data");

    row = sheet.createRow(0);
    //r.setHeight((short)500);

    cell = row.createCell(0);
    cell.setCellStyle(styles.get("header"));
    cell.setCellValue(new HSSFRichTextString("Global Data"));

    description = sheet.createRow(1);

    //creates an empty row.
    row = sheet.createRow(2);

    row = sheet.createRow(3);
    cell = row.createCell(0);
    cell.setCellStyle(styles.get("header1"));
    cell.setCellValue(new HSSFRichTextString("Chunk Names"));
    addCycleIntervals(row);

    cell = row.createCell((int) row.getLastCellNum());
    cell.setCellStyle(styles.get("header2"));
    cell.setCellValue(new HSSFRichTextString("Delta"));

    int rowNo = 4;

    for (String heap : glodChunks) {
        row = sheet.createRow(rowNo);
        cell = row.createCell(0);
        cell.setCellStyle(styles.get("cell_normal"));
        cell.setCellValue(new HSSFRichTextString(heap));

        ArrayList<GlobalDataChunks> heapValues = glodData.get(heap);

        int j = 1;
        for (int i = 0; i < heapValues.size(); i++) {
            if (constants.contains(i + 1))
                continue;

            cell = row.createCell(j++);
            cell.setCellStyle(styles.get("cell_number"));
            GlobalDataChunks thData = heapValues.get(i);

            if (thData.getAttrib() == 0) {
                //cell.getCellStyle().setAlignment(HSSFCellStyle.ALIGN_CENTER);
                cell.setCellValue(new HSSFRichTextString(NOT_AVAILABLE));
            } else
                cell.setCellValue(thData.getSize());
        }

        cell = row.createCell(logData.getNumberOfCycles() + 1 - constants.size());
        cell.setCellStyle(styles.get("cell_number"));

        if (glodDeltaData.get(heap) != null) {
            long largestFreeCellDelta = Long.parseLong(glodDeltaData.get(heap));
            cell.setCellValue(largestFreeCellDelta);
        }
        rowNo++;
    }
    for (int i = 0; i <= logData.getNumberOfCycles(); i++) {
        sheet.autoSizeColumn((short) i);
    }

    cell = description.createCell(0);
    cell.setCellValue(new HSSFRichTextString(
            "Specifies the chunk sizes in bytes that caontains global data, for each cycle in seconds"));

}

From source file:com.nokia.s60tools.swmtanalyser.model.ExcelCreator.java

License:Open Source License

private void createNonHeapChunkSheet() {
    //create a new sheet
    HSSFSheet sheet = wb.createSheet();// ww w .  j  a  va  2s .  c  o m
    // declare a row object reference
    HSSFRow row = null;
    HSSFRow description = null;
    // declare a cell object reference
    HSSFCell cell = null;

    //set the sheet name in Unicode
    wb.setSheetName(3, "Non-heap chunks");

    row = sheet.createRow(0);
    //r.setHeight((short)500);

    cell = row.createCell(0);
    cell.setCellStyle(styles.get("header"));
    cell.setCellValue(new HSSFRichTextString("Non-Heap Chunk Size"));

    description = sheet.createRow(1);

    //creates an empty row
    row = sheet.createRow(2);

    row = sheet.createRow(3);
    cell = row.createCell(0);
    cell.setCellStyle(styles.get("header2"));
    cell.setCellValue(new HSSFRichTextString("Chunk Names"));
    addCycleIntervals(row);

    cell = row.createCell((int) row.getLastCellNum());
    cell.setCellStyle(styles.get("header2"));
    cell.setCellValue(new HSSFRichTextString("Delta"));

    int rowNo = 4;

    for (String heap : nonHeapChunks) {
        row = sheet.createRow(rowNo);
        cell = row.createCell(0);
        cell.setCellStyle(styles.get("cell_normal"));
        cell.setCellValue(new HSSFRichTextString(heap));

        ArrayList<ChunksData> chunkValues = chunkData.get(heap);

        int j = 1;
        for (int i = 0; i < chunkValues.size(); i++) {
            if (constants.contains(i + 1))
                continue;

            cell = row.createCell(j++);
            cell.setCellStyle(styles.get("cell_number"));
            ChunksData chData = chunkValues.get(i);

            if (chData.getAttrib() == 0) {
                //cell.getCellStyle().setAlignment(HSSFCellStyle.ALIGN_CENTER);
                cell.setCellValue(new HSSFRichTextString(NOT_AVAILABLE));
            } else
                cell.setCellValue(chData.getSize());
        }

        cell = row.createCell(logData.getNumberOfCycles() + 1 - constants.size());
        cell.setCellStyle(styles.get("cell_number"));

        if (chunkDeltaData.get(heap) != null) {
            long largestFreeCellDelta = Long.parseLong(chunkDeltaData.get(heap));
            cell.setCellValue(largestFreeCellDelta);
        }
        rowNo++;
    }

    for (int i = 0; i <= logData.getNumberOfCycles(); i++) {
        sheet.autoSizeColumn((short) i);
    }

    cell = description.createCell(0);
    cell.setCellValue(
            new HSSFRichTextString("Specifies the non heap chunk sizes in bytes, for each cycle in seconds"));
}

From source file:com.nokia.s60tools.swmtanalyser.model.ExcelCreator.java

License:Open Source License

/**
 * This method creates sheet with Window Group events.
 *
 *//* w  w w .j av  a 2 s . c  o m*/
private void createWindowGroupSheet() {
    //create a new sheet
    HSSFSheet sheet = wb.createSheet();
    // declare a row object reference
    HSSFRow row = null;
    HSSFRow description = null;
    // declare a cell object reference
    HSSFCell cell = null;

    //set the sheet name in Unicode
    wb.setSheetName(12, "Window Groups");

    row = sheet.createRow(0);
    //r.setHeight((short)500);

    cell = row.createCell(0);
    cell.setCellStyle(styles.get("header"));
    cell.setCellValue(new HSSFRichTextString("Window Group Events"));

    description = sheet.createRow(1);

    //creates an empty row
    row = sheet.createRow(2);

    row = sheet.createRow(3);
    cell = row.createCell(0);
    cell.setCellStyle(styles.get("header2"));
    cell.setCellValue(new HSSFRichTextString("Window Group Names"));
    addCycleIntervals(row);

    SWMTLogReaderUtils utils = new SWMTLogReaderUtils();
    ArrayList<String> wndg_names = utils.getWindowGroupNames(logData);

    int rowNo = 4;

    if (wndg_names == null)
        return;
    else {
        for (String name : wndg_names) {
            row = sheet.createRow(rowNo++);
            cell = row.createCell(0);
            cell.setCellStyle(styles.get("cell_normal"));
            cell.setCellValue(new HSSFRichTextString(name));

            ArrayList<WindowGroupEventData> events_list = utils.getAllWindowGroupEvents(name, logData);

            int j = 1;

            for (int i = 0; i < events_list.size(); i++) {
                if (constants.contains(i + 1))
                    continue;

                cell = row.createCell(j++);
                cell.setCellStyle(styles.get("cell_normal"));

                WindowGroupEventData eventSet = events_list.get(i);

                if (eventSet == null) {
                    cell.setCellValue(new HSSFRichTextString(NOT_AVAILABLE));
                } else {
                    StringBuffer tmp = new StringBuffer();

                    if (eventSet.getEvent_0_count() > 0)
                        tmp.append(" NoEvent(" + eventSet.getEvent_0_count() + ")");
                    if (eventSet.getEvent_1_count() > 0)
                        tmp.append(" NameChanged(" + eventSet.getEvent_1_count() + ")");
                    if (eventSet.getEvent_2_count() > 0)
                        tmp.append(" FocusGained(" + eventSet.getEvent_2_count() + ")");
                    if (eventSet.getEvent_3_count() > 0)
                        tmp.append(" FocusLost(" + eventSet.getEvent_3_count() + ")");

                    cell.setCellValue(new HSSFRichTextString(tmp.toString()));
                }

            }
        }

        for (int i = 0; i <= logData.getNumberOfCycles(); i++)
            sheet.autoSizeColumn((short) i);

        cell = description.createCell(0);
        cell.setCellValue(new HSSFRichTextString(
                "Specifies the type and number of events for each window group, in each cycle."));
    }
}

From source file:com.nokia.s60tools.swmtanalyser.model.ExcelCreator.java

License:Open Source License

/**
 * This method adds cells with values of time intervals between 
 * consecutive cycles to given row.//from   w  w w.j  a  v a 2 s.  co m
 * @param row 
 */
private void addCycleIntervals(HSSFRow row) {
    HSSFCell cell = null;

    SWMTLogReaderUtils utils = new SWMTLogReaderUtils();

    cell = row.createCell(1);
    cell.setCellStyle(styles.get("header2"));
    cell.setCellValue(0);

    if (logData == null)
        return;

    long prevDuration = 0;

    int i;
    String currentTime = "";
    String prevTime = "";
    int j = 1;
    int filesSkipped = 1;

    CycleData[] cycles = logData.getLogData();

    for (i = 1; i < logData.getNumberOfCycles(); i++) {
        if (constants.contains(i + 1)) {
            filesSkipped++;
            continue;
        }
        j++;
        currentTime = cycles[i].getTime();
        //if(constants.contains(i-1))
        //   prevTime = logData.get(i-2).getTime();
        //else
        //   prevTime = logData.get(i-1).getTime();
        prevTime = cycles[i - filesSkipped].getTime();

        long timeDiff = utils.getDurationInSeconds(prevTime, currentTime);
        cell = row.createCell(j);
        cell.setCellStyle(styles.get("header2"));
        cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC);

        if (timeDiff < 0) {
            cell.setCellValue(new HSSFRichTextString("Cycle " + (i + 1)));
            return;
        } else {
            timeDiff += prevDuration;
            prevDuration = timeDiff;

            cell.setCellValue(timeDiff);
        }
        filesSkipped = 1;
    }

}

From source file:com.nokia.s60tools.swmtanalyser.model.ExcelCreator.java

License:Open Source License

private void createOverviewFields(HSSFRow row) {
    HSSFCell cell = row.createCell(0);
    cell.setCellStyle(styles.get("header1"));
    cell.getCellStyle().setAlignment(HSSFCellStyle.ALIGN_LEFT);
    cell.setCellValue(new HSSFRichTextString("Threads"));

    cell = row.createCell(1);//www .j  a va  2 s  .  co  m
    cell.setCellStyle(styles.get("header1"));
    cell.getCellStyle().setAlignment(HSSFCellStyle.ALIGN_LEFT);
    cell.setCellValue(new HSSFRichTextString("Status"));

    cell = row.createCell(2);
    cell.setCellStyle(styles.get("header1"));
    cell.getCellStyle().setAlignment(HSSFCellStyle.ALIGN_LEFT);
    cell.setCellValue(new HSSFRichTextString("Max Heap Size"));

    cell = row.createCell(3);
    cell.setCellStyle(styles.get("header1"));
    cell.getCellStyle().setAlignment(HSSFCellStyle.ALIGN_LEFT);
    cell.setCellValue(new HSSFRichTextString("Change in Heap \n size (in Bytes)"));

    cell = row.createCell(4);
    cell.setCellStyle(styles.get("header1"));
    cell.setCellValue(new HSSFRichTextString("Change in  Heap Allocated  \n space (in Bytes) "));

    cell = row.createCell(5);
    cell.setCellStyle(styles.get("header1"));
    cell.getCellStyle().setAlignment(HSSFCellStyle.ALIGN_LEFT);
    cell.setCellValue(new HSSFRichTextString("Change in Heap \n Free space (in Bytes)"));

    cell = row.createCell(6);
    cell.setCellStyle(styles.get("header1"));
    cell.getCellStyle().setAlignment(HSSFCellStyle.ALIGN_LEFT);
    cell.setCellValue(new HSSFRichTextString("Change in Allocated \n Cell Count"));

    cell = row.createCell(7);
    cell.setCellStyle(styles.get("header1"));
    cell.getCellStyle().setAlignment(HSSFCellStyle.ALIGN_LEFT);
    cell.setCellValue(new HSSFRichTextString("Change in Free \n Cell Count"));

    cell = row.createCell(8);
    cell.setCellStyle(styles.get("header1"));
    cell.getCellStyle().setAlignment(HSSFCellStyle.ALIGN_LEFT);
    cell.setCellValue(new HSSFRichTextString("Change in Slack \n space size (in Bytes) "));

    cell = row.createCell(9);
    cell.setCellStyle(styles.get("header1"));
    cell.getCellStyle().setAlignment(HSSFCellStyle.ALIGN_LEFT);
    cell.setCellValue(new HSSFRichTextString("Stack size"));

    cell = row.createCell(10);
    cell.setCellStyle(styles.get("header1"));
    cell.getCellStyle().setAlignment(HSSFCellStyle.ALIGN_LEFT);
    cell.setCellValue(new HSSFRichTextString("No. of Files \n opened"));

    cell = row.createCell(11);
    cell.setCellStyle(styles.get("header1"));
    cell.getCellStyle().setAlignment(HSSFCellStyle.ALIGN_LEFT);
    cell.setCellValue(new HSSFRichTextString("No. of \n P&S Handles"));

}

From source file:com.nokia.s60tools.swmtanalyser.model.ExcelCreator.java

License:Open Source License

private void createDataInOverView(HSSFSheet sheet, int rowNo) {
    SWMTLogReaderUtils utils = new SWMTLogReaderUtils();

    ArrayList<String> allThreads = utils.getAllThreadNames(logData);
    Collections.sort(allThreads);

    long[] maxHeapSizes = new long[allThreads.size()];
    long[] heapSizes = new long[allThreads.size()];
    long[] freeCells = new long[allThreads.size()];
    long[] allocCells = new long[allThreads.size()];
    long[] freeSpace = new long[allThreads.size()];
    long[] allocSpace = new long[allThreads.size()];
    long[] slackSpace = new long[allThreads.size()];
    long[] totalFiles = new long[allThreads.size()];
    long[] totalHandles = new long[allThreads.size()];
    long[] totalStacks = new long[allThreads.size()];

    int i = 0;/*from ww w .j a v a  2 s . c o m*/

    for (String thName : allThreads) {
        if (thName.startsWith("MemSpy") && thName.endsWith("::MemSpy"))
            continue;

        HSSFRow row = sheet.createRow(rowNo);
        HSSFCell cell = row.createCell(0);

        cell.setCellStyle(styles.get("cell_normal"));
        cell.setCellValue(new HSSFRichTextString(thName));

        cell = row.createCell(1);
        cell.setCellStyle(styles.get("cell_normal"));

        if (logData.getNumberOfCycles() == 1) {
            cell.setCellValue(new HSSFRichTextString("Alive"));
        } else {
            int status = utils.getThreadStatusFromAllCycles(thName, logData);

            if (status == 0)
                cell.setCellValue(new HSSFRichTextString("Dead"));
            else if (status == 1 || status == 2)
                cell.setCellValue(new HSSFRichTextString("Alive"));
            else
                cell.setCellValue(new HSSFRichTextString(NOT_AVAILABLE));
        }

        ThreadData threadDelta = deltaData.get(thName.toLowerCase());

        cell = row.createCell(2);
        cell.setCellStyle(styles.get("cell_number"));
        cell.setCellValue(threadDelta.getMaxHeapSize());

        maxHeapSizes[i] = threadDelta.getMaxHeapSize();
        /*ArrayList<String> heapThreads = utils.getAllHeapThreads(logData);
        long delta = 0;
        long lastValue = 0;
                
        ArrayList<ThreadData> heapData = utils.getHeapDataFromAllCycles(thName, logData);
                
        if(utils.getHeapStatusFromAllCycles(thName, logData) == 0)
        {
           //Display zeros for all heap fields
           maxHeapSize = 0;
           delta = 0;
        }
        else{
           lastValue = heapData.get(logData.size()-1).getHeapChunkSize();
            maxHeapSize = heapData.get(logData.size()-1).getMaxHeapSize();
                       
            long firstValue = 0;
                  
            for(int i=heapData.size()-2; i>=0; i--)
            {
         ThreadData data = heapData.get(i);
         if(data.getStatus() != CycleData.Deleted){
            firstValue = data.getHeapChunkSize();
         }
         else
            break;
            }
                   
            if(firstValue != -1)
         delta = lastValue - firstValue;
        } */

        //cell.setCellValue(maxHeapSize);

        cell = row.createCell(3);
        cell.setCellStyle(styles.get("cell_number"));
        cell.setCellValue(threadDelta.getHeapChunkSize());
        heapSizes[i] = threadDelta.getHeapChunkSize();

        cell = row.createCell(4);
        cell.setCellStyle(styles.get("cell_number"));
        cell.setCellValue(threadDelta.getHeapAllocatedSpace());
        allocSpace[i] = threadDelta.getHeapAllocatedSpace();

        cell = row.createCell(5);
        cell.setCellStyle(styles.get("cell_number"));
        cell.setCellValue(threadDelta.getHeapFreeSpace());
        freeSpace[i] = threadDelta.getHeapFreeSpace();

        cell = row.createCell(6);
        cell.setCellStyle(styles.get("cell_number"));
        cell.setCellValue(threadDelta.getAllocatedCells());
        allocCells[i] = threadDelta.getAllocatedCells();

        cell = row.createCell(7);
        cell.setCellStyle(styles.get("cell_number"));
        cell.setCellValue(threadDelta.getFreeCells());
        freeCells[i] = threadDelta.getFreeCells();

        cell = row.createCell(8);
        cell.setCellStyle(styles.get("cell_number"));
        cell.setCellValue(threadDelta.getFreeSlackSize());
        slackSpace[i] = threadDelta.getFreeSlackSize();

        cell = row.createCell(9);
        cell.setCellStyle(styles.get("cell_number"));
        cell.setCellValue(threadDelta.getStackSize());
        totalStacks[i] = threadDelta.getStackSize();

        cell = row.createCell(10);
        cell.setCellStyle(styles.get("cell_number"));
        cell.setCellValue(threadDelta.getOpenFiles());
        totalFiles[i] = threadDelta.getOpenFiles();

        cell = row.createCell(11);
        cell.setCellStyle(styles.get("cell_number"));
        cell.setCellValue(threadDelta.getPsHandles());
        totalHandles[i] = threadDelta.getPsHandles();

        i++;

        rowNo++;
    }

    if (allThreads.size() > 0) {

        HSSFRow totalRow = sheet.createRow(rowNo);

        long totalMaxHeapSize = utils.calculateAndGetTotal(maxHeapSizes);
        long totalStackSize = utils.calculateAndGetTotal(totalStacks);
        totalHeapSizeChange = utils.calculateAndGetTotal(heapSizes);
        totalFreeCellChange = utils.calculateAndGetTotal(freeCells);
        totalAllocCellChange = utils.calculateAndGetTotal(allocCells);
        totalFreeSpaceChange = utils.calculateAndGetTotal(freeSpace);
        totalAllocSpaceChange = utils.calculateAndGetTotal(allocSpace);
        totalSlackSpaceChange = utils.calculateAndGetTotal(slackSpace);
        totalFilesChange = utils.calculateAndGetTotal(totalFiles);
        totalHandlesChange = utils.calculateAndGetTotal(totalHandles);

        HSSFCell cell = totalRow.createCell(2);
        cell.setCellStyle(styles.get("cell_blue_font_white"));
        cell.setCellValue(totalMaxHeapSize);

        cell = totalRow.createCell(3);
        cell.setCellStyle(styles.get("cell_blue_font_white"));
        cell.setCellValue(totalHeapSizeChange);

        cell = totalRow.createCell(4);
        cell.setCellStyle(styles.get("cell_blue_font_white"));
        cell.setCellValue(totalAllocSpaceChange);

        cell = totalRow.createCell(5);
        cell.setCellStyle(styles.get("cell_blue_font_white"));
        cell.setCellValue(totalFreeSpaceChange);

        cell = totalRow.createCell(6);
        cell.setCellStyle(styles.get("cell_blue_font_white"));
        cell.setCellValue(totalAllocCellChange);

        cell = totalRow.createCell(7);
        cell.setCellStyle(styles.get("cell_blue_font_white"));
        cell.setCellValue(totalFreeCellChange);

        cell = totalRow.createCell(8);
        cell.setCellStyle(styles.get("cell_blue_font_white"));
        cell.setCellValue(totalSlackSpaceChange);

        cell = totalRow.createCell(9);
        cell.setCellStyle(styles.get("cell_blue_font_white"));
        cell.setCellValue(totalStackSize);

        cell = totalRow.createCell(10);
        cell.setCellStyle(styles.get("cell_blue_font_white"));
        cell.setCellValue(totalFilesChange);

        cell = totalRow.createCell(11);
        cell.setCellStyle(styles.get("cell_blue_font_white"));
        cell.setCellValue(totalHandlesChange);
    }

}

From source file:com.objectfrontier.insta.neft.reports.bean.InstaNEFTReportBean.java

License:Open Source License

/**
 * Method used to export the paymentreport in to Excel
 *///from w w  w  .j a v a2s.co  m
public void paymentExportToExcel(ServletOutputStream out) throws Exception {

    try {
        List exportXLS = new ArrayList(1);
        long sno = 0;
        int rowCount = 0;
        //            double totAmt = 0;
        BigDecimal totAmt = BigDecimal.ZERO;
        //Adding the items to a list
        for (Iterator i = getDetailReportDTOs().iterator(); i.hasNext();) {
            NEFTDetailsReportDTO indentList = (NEFTDetailsReportDTO) i.next();
            exportXLS.add(indentList);

        }

        //Only If the list is not empty
        if (exportXLS.size() != 0) {
            // start to export excel
            HSSFWorkbook book = new HSSFWorkbook();
            HSSFSheet sheet = book.createSheet();
            HSSFRow row = null;
            HSSFCell cell = null;
            HSSFFont caption_font = null;
            HSSFCellStyle caption_style = null;

            if (report.equalsIgnoreCase("submitted")) {
                book.setSheetName(0, "Payments Submitted", HSSFWorkbook.ENCODING_COMPRESSED_UNICODE);
            } else {
                book.setSheetName(0, "Payments Received", HSSFWorkbook.ENCODING_COMPRESSED_UNICODE);
            }
            caption_font = book.createFont();
            caption_font.setFontHeightInPoints((short) 10);
            caption_font.setFontName("Verdana");
            caption_style = book.createCellStyle();
            caption_style.setFont(caption_font);
            row = sheet.createRow(rowCount);
            rowCount += 1;
            cell = row.createCell((short) 0);
            if (report.equalsIgnoreCase("submitted")) {
                cell.setCellValue("Payment Submitted Report " + reportDto.getPaymentType() + "  From "
                        + reportDto.getValueDate() + " to " + reportDto.getToDate() + " with status "
                        + reportDto.getStatusValue());
            } else {
                cell.setCellValue("Payment Received Report " + reportDto.getPaymentType() + "  From "
                        + reportDto.getValueDate() + " to " + reportDto.getToDate() + " with status "
                        + reportDto.getStatusValue());
            }
            for (int i = exportXLS.size(), roww = 0; roww <= i; roww++) {

                row = sheet.createRow(rowCount);
                rowCount += 1;
                for (short j = 0; j < 9; j++) {
                    cell = row.createCell(j);

                    // for header
                    if (roww == 0) {
                        if (j == 0) {
                            cell.setCellValue("S.NO");
                        } else if (j == 1) {
                            cell.setCellValue("VALUE DATE");
                        } else if (j == 2) {
                            cell.setCellValue("SENDER ADDRESS");
                        } else if (j == 3) {
                            cell.setCellValue("RECEIVER ADDRESS");
                        } else if (j == 4) {
                            cell.setCellValue("UTR NUMBER");
                        } else if (j == 5) {
                            cell.setCellValue("ACCOUNT NUMBER");
                        } else if (j == 6) {
                            cell.setCellValue("BENIFICIARY DETAILS");
                        } else if (j == 7) {
                            cell.setCellValue("AMOUNT(Rs)");
                        } else if (j == 8) {
                            cell.setCellValue("STATUS");
                        }
                    } else {
                        // Setting values in cell for each and every row
                        if (j == 0) {

                            String no = null;

                            sno += 1;
                            no = String.valueOf(sno);
                            cell.setCellValue(no);
                        } else if (j == 1) {

                            String valueDate = null;
                            if (((NEFTDetailsReportDTO) exportXLS.get(roww - 1)).getValueDate() != null) {
                                valueDate = ((NEFTDetailsReportDTO) exportXLS.get(roww - 1)).getValueDate();
                            }
                            cell.setCellValue(valueDate);
                        } else if (j == 2) {

                            String sendAdd = null;

                            if (((NEFTDetailsReportDTO) exportXLS.get(roww - 1)).getSenderAddress() != null) {
                                sendAdd = ((NEFTDetailsReportDTO) exportXLS.get(roww - 1)).getSenderAddress();
                            }
                            cell.setCellValue(sendAdd);

                        } else if (j == 3) {

                            String recAdd = null;

                            if (((NEFTDetailsReportDTO) exportXLS.get(roww - 1)).getReceiverAddress() != null) {
                                recAdd = ((NEFTDetailsReportDTO) exportXLS.get(roww - 1)).getReceiverAddress();
                            }
                            cell.setCellValue(recAdd);

                        } else if (j == 4) {

                            String utrNo = null;

                            if (((NEFTDetailsReportDTO) exportXLS.get(roww - 1)).getUtrNo() != null) {
                                utrNo = ((NEFTDetailsReportDTO) exportXLS.get(roww - 1)).getUtrNo();
                            }
                            cell.setCellValue(utrNo);

                        } else if (j == 5) {

                            String accNo = null;

                            if (((NEFTDetailsReportDTO) exportXLS.get(roww - 1)).getField6021() != null) {
                                accNo = ((NEFTDetailsReportDTO) exportXLS.get(roww - 1)).getField6021();
                            } else if (((NEFTDetailsReportDTO) exportXLS.get(roww - 1))
                                    .getField6061() != null) {
                                accNo = ((NEFTDetailsReportDTO) exportXLS.get(roww - 1)).getField6061();
                            }
                            cell.setCellValue(accNo);

                        } else if (j == 6) {

                            String beniDetails = null;

                            if (((NEFTDetailsReportDTO) exportXLS.get(roww - 1)).getField5565() != null) {

                                beniDetails = ((NEFTDetailsReportDTO) exportXLS.get(roww - 1)).getField5565();
                                if (((NEFTDetailsReportDTO) exportXLS.get(roww - 1)).getField6081() != null) {

                                    beniDetails = ((NEFTDetailsReportDTO) exportXLS.get(roww - 1))
                                            .getField6081() + "-" + beniDetails;
                                }
                            } else if (((NEFTDetailsReportDTO) exportXLS.get(roww - 1))
                                    .getField6091() != null) {
                                beniDetails = ((NEFTDetailsReportDTO) exportXLS.get(roww - 1)).getField6091();
                            }
                            cell.setCellValue(beniDetails);

                        } else if (j == 7) {

                            String amt = null;

                            if (new BigDecimal(((NEFTDetailsReportDTO) exportXLS.get(roww - 1)).getAmt())
                                    .compareTo(BigDecimal.ZERO) != 0) {

                                //                                    totAmt += ((NEFTDetailsReportDTO)exportXLS
                                //                                    .get(roww - 1)).getAmount();
                                totAmt = totAmt.add(new BigDecimal(
                                        ((NEFTDetailsReportDTO) exportXLS.get(roww - 1)).getAmt()).setScale(2));
                                amt = String.valueOf(((NEFTDetailsReportDTO) exportXLS.get(roww - 1)).getAmt());
                            }
                            cell.setCellValue(new BigDecimal(amt).setScale(2).toString());
                        } else if (j == 8) { //To add status column in the excel sheet.

                            String status = null;
                            if (((NEFTDetailsReportDTO) exportXLS.get(roww - 1)).getStatus() != null) {
                                status = ((NEFTDetailsReportDTO) exportXLS.get(roww - 1)).getStatus();
                            }
                            cell.setCellValue(status);
                        }
                    }
                    cell.setCellStyle(caption_style);
                }
            }
            row = sheet.createRow(rowCount);
            cell = row.createCell((short) 6);
            cell.setCellValue("TOTAL AMOUNT");
            cell.setCellStyle(caption_style);
            cell = row.createCell((short) 7);
            cell.setCellValue(String.valueOf(totAmt));
            cell.setCellStyle(caption_style);
            sheet = book.createSheet();

            book.write(out);
            out.flush();
            out.close();
        }
    } catch (Exception e) {
        logger.error("Exception while creating Excel sheet file" + e.getMessage());
        throw new Exception("Exception while creating Excel sheet file" + e);
    }
}