日期:2014-05-20 浏览次数:20712 次
private void format(String fileName, Set<Integer> set, HashMap< Integer, LinkedList<Integer> > inlinkMap, HashMap<Integer,LinkedList<Integer> > outlinkMap) { System.out.println("Loading..."); FileReader fr = null; BufferedReader br = null; LinkedList<Integer> inlinkList = null; LinkedList<Integer> outlinkList = null; String strLine = null; int seperatorIndex, followerId, followeeId; try { fr = new FileReader(fileName); br = new BufferedReader(fr); } catch (FileNotFoundException e) { e.printStackTrace(); } while(true) { try { strLine = br.readLine(); seperatorIndex = strLine.indexOf(','); followerId = Integer.parseInt(strLine.substring(0, seperatorIndex)); followeeId = Integer.parseInt(strLine.substring(seperatorIndex+1,strLine.length())); if(!set.contains(followerId)) { set.add(followerId); } if(!set.contains(followeeId)) { set.add(followeeId); } if(!inlinkMap.keySet().contains(followeeId)) { inlinkList = new LinkedList<Integer>(); inlinkList.add(followerId); inlinkMap.put(followeeId, inlinkList); } else { inlinkList = inlinkMap.get(followeeId); inlinkList.add(followerId); } if(!outlinkMap.keySet().contains(followerId)) { outlinkList = new LinkedList<Integer>(); outlinkList.add(followeeId); outlinkMap.put(followerId, outlinkList); } else { outlinkList = outlinkMap.get(followerId); outlinkList.add(followeeId); } } catch(Exception e) { System.out.println("EOF"); try { br.close(); fr.close(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } break; } } try { br.close(); fr.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("Loading completed!"); }