Advertisement
Guest User

Untitled

a guest
May 19th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. // Constructor
  2. public MovieGraph(String filename) throws IOException, SecurityException, FileNotFoundException
  3. {
  4. // for debugging
  5. pdbg(filename);
  6.  
  7. BufferedReader findLength = new BufferedReader(new FileReader(filename)); //length of document
  8. int length = 0;
  9. while(findLength.readLine() != null)
  10. length++;
  11. findLength.close();
  12.  
  13. HashMap <String, HashSet<String>> dataMtoA = new HashMap<String, HashSet<String>>();
  14. HashMap <String, HashSet<String>> dataAtoM = new HashMap<String, HashSet<String>>();
  15.  
  16. BufferedReader in = new BufferedReader(new FileReader(filename));
  17. for(int i = 0; i < length; i++)
  18. {
  19. String[] currentLine = in.readLine().split("/");
  20. int rowLength = currentLine.length;
  21.  
  22. HashSet<String> setLine = new HashSet<String>();
  23. for(int j = 1; j < rowLength ; j++)
  24. {
  25. setLine.add(currentLine[j]); //adds actor to current line
  26.  
  27. String currentAct = currentLine[j];
  28. if(dataAtoM.containsKey(currentAct)) // any other add movie to actor
  29. {
  30. HashSet<String> temp = dataAtoM.get(currentAct);
  31. temp.add(currentLine[0]); //add movie
  32. dataAtoM.put(currentAct, temp);
  33. }
  34. else if(!dataAtoM.containsKey(currentAct)) //first time add movie to actor
  35. {
  36. HashSet<String> temp = new HashSet<String>();
  37. temp.add(currentLine[0]); //add movie
  38. dataAtoM.put(currentAct, temp);
  39. }
  40. }
  41. dataMtoA.put(currentLine[0], setLine); // then set line of movie
  42. }
  43.  
  44. allMovies = dataMtoA;
  45. allActs = dataAtoM;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement