Coverage details for net.sourceforge.demetrix.rio.Excel2MaximaConverter

LineHitsSource
1 /*******************************************************************************
2  * Demetrix process modelling system
3  *
4  * Copyright (c) 2003, 2004 Dimitri A. Pissarenko
5  *
6  * This file is part of Demetrix.
7  *
8  * Demetrix is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2.1 of the License, or
11  * (at your option) any later version.
12  *
13  * Demetrix is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with Demetrix; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21  *
22  * For further information you may
23  *
24  * - send an e-mail in Russian, German or English to dimitri.pissarenko@gmx.net
25  * - look at http://sourceforge.net/projects/demetrix/
26  * - look at http://demetrix.sourceforge.net/
27  * - look at http://members.inode.at/d.pissarenko/
28  *
29  *****************************************************************************/
30 /*
31  * Created on 24.01.2004
32  */
33 package net.sourceforge.demetrix.rio;
34  
35 import java.util.Iterator;
36  
37 import org.apache.log4j.Logger;
38 import org.apache.poi.hssf.usermodel.HSSFCell;
39 import org.apache.poi.hssf.usermodel.HSSFRow;
40 import org.apache.poi.hssf.usermodel.HSSFSheet;
41  
42 /**
43  * @author Dimitri Pissarenko
44  *
45  */
46 public class Excel2MaximaConverter {
47     private Logger logger = Logger.getLogger(getClass());
48     public final static String EMPTY_ROW = "[]";
495    public Excel2MaximaConverter() {
505    }
51     public String convertToMaxima(HSSFSheet workSheet) {
521        String lineSeparator = null;
531        String returnValue = null;
54  
551        lineSeparator = System.getProperty("line.separator");
561        returnValue = "A:matrix(" + lineSeparator;
571        returnValue =
58             returnValue
59                 + this.getMaximaRepresentation(workSheet)
60                 + lineSeparator;
611        returnValue = returnValue + ");";
62  
631        return returnValue;
64     }
65     public String getMaximaRepresentation(HSSFSheet workSheet) {
662        StringBuffer matrix = null;
672        Iterator rows = null;
682        Iterator cells = null;
692        HSSFRow row = null;
702        HSSFCell cell = null;
712        String lineSeparator = null;
722        StringBuffer rowStringBuffer = null;
73  
742        lineSeparator = System.getProperty("line.separator");
752        matrix = new StringBuffer();
76  
776        for (short i = 0; i <= workSheet.getLastRowNum(); i++) {
784            row = (HSSFRow) workSheet.getRow(i);
794            rowStringBuffer = this.getMatrixRow(row);
804            if (matrix.length() > 0) {
812                matrix.append(',');
822                matrix.append(lineSeparator);
83             }
844            matrix.append(rowStringBuffer);
85         }
86  
872        return matrix.toString();
88     }
89     private StringBuffer getMatrixRow(HSSFRow row) {
907        StringBuffer returnValue = null;
917        StringBuffer cellContent = null;
927        Iterator cellIterator = null;
937        HSSFCell cell = null;
94  
957        returnValue = new StringBuffer();
967        returnValue.append('[');
977        if (row != null) {
986            cellIterator = row.cellIterator();
99  
1006            for (short i = row.getFirstCellNum();
10121                i <= row.getLastCellNum();
10215                i++) {
10315                cell = row.getCell(i);
10415                cellContent = this.getMatrixCell(cell);
10515                if (cellContent.length() > 0)
106                 {
10714                    if (returnValue.length() > 1) {
1088                        returnValue.append(',');
109                     }
110                     
11114                    returnValue.append(cellContent);
112                 }
113                 
114             }
115         }
116  
1177        returnValue.append(']');
1187        return returnValue;
119     }
120     private StringBuffer getMatrixCell(HSSFCell cell) {
12118        StringBuffer returnValue = null;
12218        returnValue = new StringBuffer();
12318        if (cell != null) {
12417            if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
12510                returnValue.append(cell.getNumericCellValue());
1267            } else if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING) {
1276                returnValue.append(cell.getStringCellValue());
128             }
129         }
13018        return returnValue;
131     }
132 }

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.