Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Constructor
- public MovieGraph(String filename) throws IOException, SecurityException, FileNotFoundException
- {
- // for debugging
- pdbg(filename);
- BufferedReader findLength = new BufferedReader(new FileReader(filename)); //length of document
- int length = 0;
- while(findLength.readLine() != null)
- length++;
- findLength.close();
- HashMap <String, HashSet<String>> dataMtoA = new HashMap<String, HashSet<String>>();
- HashMap <String, HashSet<String>> dataAtoM = new HashMap<String, HashSet<String>>();
- BufferedReader in = new BufferedReader(new FileReader(filename));
- for(int i = 0; i < length; i++)
- {
- String[] currentLine = in.readLine().split("/");
- int rowLength = currentLine.length;
- HashSet<String> setLine = new HashSet<String>();
- for(int j = 1; j < rowLength ; j++)
- {
- setLine.add(currentLine[j]); //adds actor to current line
- String currentAct = currentLine[j];
- if(dataAtoM.containsKey(currentAct)) // any other add movie to actor
- {
- HashSet<String> temp = dataAtoM.get(currentAct);
- temp.add(currentLine[0]); //add movie
- dataAtoM.put(currentAct, temp);
- }
- else if(!dataAtoM.containsKey(currentAct)) //first time add movie to actor
- {
- HashSet<String> temp = new HashSet<String>();
- temp.add(currentLine[0]); //add movie
- dataAtoM.put(currentAct, temp);
- }
- }
- dataMtoA.put(currentLine[0], setLine); // then set line of movie
- }
- allMovies = dataMtoA;
- allActs = dataAtoM;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement