private static < E > void loadIntoCounter ( String filename , Class < E > c , Counter < E > counter ) throws RuntimeException { try { Constructor < E > m = c . getConstructor ( String . class ) ; BufferedReader in = IOUtils . getBufferedFileReader ( filename ) ; // new // BufferedReader(new // FileReader(filename)); String line = in . readLine ( ) ; while ( line != null && line . length ( ) > 0 ) { int endPos = Math . max ( line . lastIndexOf ( ' ' ) , line . lastIndexOf ( ' ' ) ) ; counter . setCount ( m . newInstance ( line . substring ( 0 , endPos ) . trim ( ) ) , Double . parseDouble ( line . substring ( endPos , line . length ( ) ) . trim ( ) ) ) ; line = in . readLine ( ) ; } in . close ( ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } }
Loads a file into an GenericCounter .