| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| MatrixToRoundLoader | 
  | 
  | 1.6666666666666667;1,667 | 
| 1 |  /* | |
| 2 |      This file is part of Combean. | |
| 3 | ||
| 4 |      Combean is free software; you can redistribute it and/or modify | |
| 5 |      it under the terms of the GNU General Public License as published by | |
| 6 |      the Free Software Foundation; either version 2 of the License, or | |
| 7 |      (at your option) any later version. | |
| 8 | ||
| 9 |      Combean is distributed in the hope that it will be useful, | |
| 10 |      but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11 |      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | |
| 12 |      GNU General Public License for more details. | |
| 13 | ||
| 14 |      You should have received a copy of the GNU General Public License | |
| 15 |      along with Combean; if not, write to the Free Software | |
| 16 |      Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA | |
| 17 |  */ | |
| 18 |  /* | |
| 19 |   * Created on 04.08.2006 | |
| 20 |   * | |
| 21 |   */ | |
| 22 |  package net.sourceforge.combean.samples.mathprog.lp.matrixrounding; | |
| 23 | ||
| 24 |  import java.util.Locale; | |
| 25 |  import java.util.Scanner; | |
| 26 | ||
| 27 |  import org.apache.commons.logging.Log; | |
| 28 |  import org.apache.commons.logging.LogFactory; | |
| 29 | ||
| 30 |  /** | |
| 31 |   * Load a matrix from a Readable object. | |
| 32 |   *  | |
| 33 |   * @author schickin | |
| 34 |   * | |
| 35 |   */ | |
| 36 | public class MatrixToRoundLoader {  | |
| 37 | ||
| 38 | 3 | private static Log log =  | 
| 39 |          LogFactory.getLog(MatrixToRoundLoader.class);  | |
| 40 | ||
| 41 | 6 | private double[][] M = null;  | 
| 42 | ||
| 43 |      /** | |
| 44 |       * Constructor | |
| 45 |       *  | |
| 46 |       * @param dataSource the Readable from where the matrix shall be read | |
| 47 |       */ | |
| 48 | 6 |      public MatrixToRoundLoader(Readable dataSource) { | 
| 49 | 6 | loadMatrix(dataSource);  | 
| 50 | 6 | }  | 
| 51 | ||
| 52 |      /** | |
| 53 |       * Fill the internal data structures with data from the Readable. | |
| 54 |       *  | |
| 55 |       * @param dataSource the Readable from where the matrix shall be read | |
| 56 |       */ | |
| 57 | private void loadMatrix(Readable dataSource) {  | |
| 58 | 6 |          Scanner scan = new Scanner(dataSource); | 
| 59 | 6 | scan.useLocale(Locale.US);  | 
| 60 | ||
| 61 | 6 |          int numRows = scan.nextInt(); | 
| 62 | 6 |          int numCols = scan.nextInt(); | 
| 63 | ||
| 64 | 6 | log.debug(("#rows: " + numRows + ", #cols: " + numCols));  | 
| 65 | ||
| 66 | 6 | this.M = new double[numRows][numCols];  | 
| 67 | 24 | for (int row = 0; row < numRows; row++) {  | 
| 68 | 72 | for (int col = 0; col < numCols; col++) {  | 
| 69 | 54 |                  this.M[row][col] = scan.nextDouble(); | 
| 70 | }  | |
| 71 | }  | |
| 72 | 6 | }  | 
| 73 | ||
| 74 |      /** | |
| 75 |       * Return the matrix that has been read. | |
| 76 |       *  | |
| 77 |       * @return Returns the matrix. | |
| 78 |       */ | |
| 79 | public final double[][] getM() {  | |
| 80 | 6 | return this.M;  | 
| 81 | }  | |
| 82 | }  |