public static <K,V>void readKV(Map<Id<K>,Id<V>> yFromX,String key,Class<K> keyType,String value,Class<V> valueType,String filename){
  try {
    log.info("Starting to read some key-value pairs from " + filename);
    BufferedReader reader=IOUtils.getBufferedReader(filename);
    String header=reader.readLine();
    Map<String,Integer> idxFromKey=Utils.createIdxFromKey(header,null);
    String line=reader.readLine();
    while (line != null) {
      String[] parts=line.split("[\t\n]+");
      int idx=idxFromKey.get(value);
      Id<V> valueId=Id.create(parts[idx],valueType);
      idx=idxFromKey.get(key);
      Id<K> keyId=Id.create(parts[idx],keyType);
      yFromX.put(keyId,valueId);
      line=reader.readLine();
    }
  }
 catch (  FileNotFoundException e) {
    e.printStackTrace();
  }
catch (  IOException e) {
    e.printStackTrace();
  }
  log.info("DONE with reading some key-value pairs.");
}

public static < K , V > void readKV ( Map < Id < K > , Id < V > > yFromX , String key , Class < K > keyType , String value , Class < V > valueType , String filename ) { try { log . info ( "Starting to read some key-value pairs from " + filename ) ; BufferedReader reader = IOUtils . getBufferedReader ( filename ) ; String header = reader . readLine ( ) ; Map < String , Integer > idxFromKey = Utils . createIdxFromKey ( header , null ) ; String line = reader . readLine ( ) ; while ( line != null ) { String [ ] parts = line . split ( "[\t\n]+" ) ; int idx = idxFromKey . get ( value ) ; Id < V > valueId = Id . create ( parts [ idx ] , valueType ) ; idx = idxFromKey . get ( key ) ; Id < K > keyId = Id . create ( parts [ idx ] , keyType ) ; yFromX . put ( keyId , valueId ) ; line = reader . readLine ( ) ; } } catch ( FileNotFoundException e ) { e . printStackTrace ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } log . info ( "DONE with reading some key-value pairs." ) ; }
this reads a key - value mapping from a column - oriented file . the " string key " and the " string value " parameters give the column headers . the idfactories are there so that there is at least some runtime safety net : if you pull an id that you did not expect , it will complain . " map < id , id > yfromx " contains the result .
