Clover coverage report - baseCode - 0.2.5 Coverage timestamp: Tue Apr 12 2005 11:31:58 EDT FRAMES NO FRAMES |
file stats: | LOC: | 87 |  | Methods: | 1
| NCLOC: | 53 |  | Classes: | 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
Source file | Conditionals | Statements | Methods | TOTAL
AbstractNamedMatrixReader.java | 72.2% | 85.2% | 100% | 80.4% |

1 |  |
     package baseCode.io.reader;
2 |  |
3 |  |
     import java.io.BufferedReader;
4 |  |
     import java.io.IOException;
5 |  |
     import java.io.InputStream;
6 |  |
     import java.util.StringTokenizer;
7 |  |
     import java.util.Vector;
8 |  |
9 |  |
     import org.apache.commons.logging.Log;
10 |  |
     import org.apache.commons.logging.LogFactory;
11 |  |
12 |  |
     import baseCode.dataStructure.matrix.NamedMatrix;
13 |  |
14 |  |
     /**
15 |  |
      * Abstract class representing an object that can read in a {@link NamedMatrix}from a file.
16 |  |
      * <p>
17 |  |
      * Copyright (c) 2004
18 |  |
      * </p>
19 |  |
      * <p>
20 |  |
      * Institution:: Columbia University
21 |  |
      * </p>
22 |  |
      *
23 |  |
      * @author Paul Pavlidis
24 |  |
      * @version $Id: AbstractNamedMatrixReader.java,v 1.3 2004/08/11 22:53:43 pavlidis Exp $
25 |  |
      */
26 |  |
     public abstract class AbstractNamedMatrixReader {
27 |  |
28 |  |
        public abstract NamedMatrix read( String filename ) throws IOException;
29 |  |
30 |  |
        public abstract NamedMatrix read( InputStream stream ) throws IOException;
31 |  |
32 |  |
        public abstract NamedMatrix readOneRow(BufferedReader dis ) throws IOException;
33 |  |
34 |  |
35 |  |
        protected static final Log log = LogFactory
36 |  |
              .getLog( AbstractNamedMatrixReader.class );
37 |  |
38 | 229 |
        protected Vector readHeader( BufferedReader dis ) throws IOException {
39 | 229 |
           Vector headerVec = new Vector();
40 | 229 |
           String header = dis.readLine();
41 | 229 |
           StringTokenizer st = new StringTokenizer( header, "\t", true ); // return
42 |  |
           // delims.
43 |  |
44 | 229 |
           String previousToken = "";
45 | 229 |
           int columnNumber = 0;
46 | 229 |
           while ( st.hasMoreTokens() ) {
47 | 5762 |
              String s = st.nextToken();
48 | 5762 |
              boolean missing = false;
49 |  |
50 | 5762 |
              if ( s.compareTo( "\t" ) == 0 ) {
51 |  |
                 /* two tabs in a row */
52 | 2767 |
                 if ( previousToken.compareTo( "\t" ) == 0 ) {
53 | 0 |
                    missing = true;
54 | 2767 |
                 } else if ( !st.hasMoreTokens() ) { // at end of line.
55 | 1 |
                    missing = true;
56 |  |
                 } else {
57 | 2766 |
                    previousToken = s;
58 | 2766 |
                    continue;
59 |  |
                 }
60 | 2995 |
              } else if ( s.compareTo( " " ) == 0 ) {
61 | 0 |
                 if ( previousToken.compareTo( "\t" ) == 0 ) {
62 | 0 |
                    missing = true;
63 |  |
                 }
64 |  |
              }
65 |  |
66 | 2996 |
              if ( missing ) {
67 | 1 |
                 throw new IOException(
68 |  |
                       "Warning: Missing values not allowed in the header (column "
69 |  |
                             + columnNumber + ")" );
70 | 2995 |
              } else if ( columnNumber > 0 ) {
71 | 2766 |
                 headerVec.add( s );
72 |  |
              }
73 |  |
              // otherwise, just the corner string.
74 | 2995 |
              columnNumber++;
75 | 2995 |
              previousToken = s;
76 |  |
           }
77 |  |
78 |  |
           //return columnNumber - 1;
79 | 228 |
           if ( headerVec.size() == 0 ) {
80 | 0 |
              log.warn( "No headings found" );
81 |  |
           }
82 |  |
83 | 228 |
           return headerVec;
84 |  |
85 |  |
        }
86 |  |
87 |  |
     }