Clover coverage report - baseCode - 0.2.5
Coverage timestamp: Tue Apr 12 2005 11:31:58 EDT
file stats: LOC: 103   Methods: 4
NCLOC: 54   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
MapReader.java 30% 53.8% 50% 47.5%
coverage coverage
 1   
 package baseCode.io.reader;
 2   
 
 3   
 import java.io.BufferedReader;
 4   
 import java.io.File;
 5   
 import java.io.FileInputStream;
 6   
 import java.io.IOException;
 7   
 import java.io.InputStream;
 8   
 import java.io.InputStreamReader;
 9   
 import java.util.HashMap;
 10   
 import java.util.HashSet;
 11   
 import java.util.Map;
 12   
 import java.util.Set;
 13   
 import java.util.StringTokenizer;
 14   
 
 15   
 /**
 16   
  * Reads a tab-delimited file with lines of the format Key Value. If there are multiple values, then a Set is created
 17   
  * for each key containing its values.
 18   
  * </p>
 19   
  * <p>
 20   
  * Copyright (c) 2004
 21   
  * </p>
 22   
  * <p>
 23   
  * Institution: Columbia University
 24   
  * </p>
 25   
  * 
 26   
  * @author Paul Pavlidis
 27   
  * @version $Id: MapReader.java,v 1.2 2004/07/27 03:18:58 pavlidis Exp $
 28   
  */
 29   
 public class MapReader {
 30   
 
 31   
    /**
 32   
     * @param filename String
 33   
     * @throws IOException
 34   
     * @return Map
 35   
     */
 36  0
    public Map read( String filename ) throws IOException {
 37  0
       return this.read( filename, false );
 38   
    }
 39   
 
 40   
    /**
 41   
     * @param stream InputStream
 42   
     * @return @throws IOException
 43   
     * @throws IOException
 44   
     */
 45  1
    public Map read( InputStream stream ) throws IOException {
 46  1
       return this.read( stream, false );
 47   
    }
 48   
 
 49   
    /**
 50   
     * @param filename name of the tab-delimited file
 51   
     * @param hasHeader boolean
 52   
     * @return Map from the file.
 53   
     * @throws IOException
 54   
     */
 55  0
    public Map read( String filename, boolean hasHeader ) throws IOException {
 56  0
       File infile = new File( filename );
 57  0
       if ( !infile.exists() || !infile.canRead() ) {
 58  0
          throw new IllegalArgumentException( "Could not read from " + filename );
 59   
       }
 60  0
       FileInputStream stream = new FileInputStream( infile );
 61  0
       return read( stream, hasHeader );
 62   
 
 63   
    }
 64   
 
 65   
    /**
 66   
     * @param stream InputStream
 67   
     * @param hasHeader boolean
 68   
     * @return @throws IOException
 69   
     * @throws IOException
 70   
     */
 71  2
    public Map read( InputStream stream, boolean hasHeader ) throws IOException {
 72  2
       Map result = new HashMap();
 73   
 
 74  2
       BufferedReader dis = new BufferedReader( new InputStreamReader( stream ) );
 75  2
       if ( hasHeader ) {
 76  1
          dis.readLine();
 77   
       }
 78   
 
 79  2
       String row;
 80  ?
       while ( ( row = dis.readLine() ) != null ) {
 81  201
          StringTokenizer st = new StringTokenizer( row, "\t" );
 82  201
          String key = st.nextToken();
 83   
 
 84  201
          String value = st.nextToken();
 85   
 
 86  201
          if ( st.hasMoreTokens() ) {
 87  0
             Set innerList = new HashSet();
 88  0
             innerList.add( value );
 89  0
             while ( st.hasMoreTokens() ) {
 90  0
                value = st.nextToken();
 91   
             }
 92  0
             innerList.add( value );
 93  0
             result.put( key, innerList );
 94   
          } else {
 95  201
             result.put( key, value );
 96   
          }
 97   
       }
 98  2
       dis.close();
 99   
 
 100  2
       return result;
 101   
    }
 102   
 } // end of class
 103