Coverage Report - eu.simuline.octave.io.impl.AbstractLogicalFloatingPointWriter
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractLogicalFloatingPointWriter
100%
23/23
85%
12/14
4.5
 
 1  
 package eu.simuline.octave.io.impl;
 2  
 
 3  
 import eu.simuline.octave.type.matrix.AbstractGenericMatrix;
 4  
 
 5  
 import java.io.IOException;
 6  
 import java.io.Writer;
 7  
 
 8  
 /**
 9  
  * Common Writer class for logical and floating point types: 
 10  
  * Boolean, Double, ...
 11  
  *
 12  
  * @param <T>
 13  
  *    the type to be written out 
 14  
  *    which has to extend {@link AbstractGenericMatrix}. 
 15  
  */
 16  482
 abstract class AbstractLogicalFloatingPointWriter 
 17  
     <T extends AbstractGenericMatrix<?,?>> 
 18  
     extends AbstractPrimitiveMatrixWriter<T> {
 19  
 
 20  
 
 21  
     @Override
 22  
     public void write(final Writer writer, 
 23  
                       final T octaveMatrix) throws IOException {
 24  478
         if (octaveMatrix.getSizeLength() > 2) {
 25  212
             writer.write("# type: " + octaveMatrixType() + "\n");
 26  212
             saveDataVectorized(writer, octaveMatrix);
 27  
         } else {
 28  266
             if (octaveMatrix.getSizeLength() == 2 && 
 29  266
                 octaveMatrix.getSize(1) == 1 && 
 30  110
                 octaveMatrix.getSize(2) == 1) {
 31  
 
 32  96
                 writer.write("# type: " + octaveScalarType() + "\n");
 33  96
                 writer.write(octaveMatrix.getPlainString(0) + "\n");
 34  
             } else {
 35  170
                 writer.write("# type: " + octaveMatrixType() + "\n");
 36  170
                 saveData2d(writer, octaveMatrix);
 37  
             }
 38  
         }
 39  478
     }
 40  
 
 41  
     private void saveData2d(final Writer writer, 
 42  
                             final T octaveMatrix) 
 43  
         throws IOException {
 44  
 
 45  170
         final int nrows = octaveMatrix.getSize(1);
 46  170
         final int ncols = octaveMatrix.getSizeLength() > 1 
 47  170
             ? octaveMatrix.getSize(2) : 1;
 48  170
         writer.write(NROWS + nrows + "\n");
 49  170
         writer.write(NCOLUMNS + ncols + "\n");
 50  386
         for (int row = 0; row < nrows; row++) {
 51  740
             for (int col = 0; col < ncols; col++) {
 52  1048
                writer.write(" " + 
 53  524
                             octaveMatrix.getPlainString(row + col * nrows));
 54  
             }
 55  216
             writer.write('\n');
 56  
         }
 57  170
     }
 58  
 
 59  
 }