package todo.sec09; import java.util.*; public class SuperGeneDijkstra { // TODO: add dijkstra method and checkrep private static final boolean DEBUG = false; //private static final String buildingFilename = "campus_buildings.csv"; // AF (this) = {connections, family members} // where connections = Genealogy.Branches // Genealogy.Members = names of people in the family tree; // RI: familyTree != null /** * Holds all of the family members and their connections in a family tree or Genealogy. */ private Genealogy familyTree; public SuperGeneDijkstra() { familyTree = new Genealogy(); Map> temp = parseData(); // initializes the family tree from the data received by temp for (String parent : temp.keySet()) { if (!familyTree.contains(parent)) { familyTree.addMember(parent); } // loops through each child of the parent and adds a branch between // the parent and the child for (String child : temp.get(parent)) { if (!familyTree.contains(child)) { familyTree.addMember(child); } if (!parent.equals(child)) { familyTree.addBranch(parent, child); } } } } /** * Reads the dataset. Each line contains a parent name and a child name, * separated by a comma * * @return a Map of Strings to Sets of Strings. Each of the Map's keys represent a parent in the * family tree and the key's corresponding value represent all of the parent's children. */ public Map> parseData() { List lines = readLines(); // hardcoded a data set, no longer using a file // parents as keys, children as values Map> temp = new HashMap<>(); // Splits each line into its individual parts and collects the data for (String line : lines) { String[] splitLine = line.split(","); String parent = splitLine[0]; String child = splitLine[1]; if (!temp.containsKey(parent)) { temp.put(parent, new HashSet<>()); } temp.get(parent).add(child); } return temp; } /** * Reads all lines contained within the provided data file, which is located * relative to the data/ folder in this parser's classpath. * * @return A new {@link List} containing all lines in the file. */ private List readLines() { List lines = new ArrayList<>(); // Yes, these are presidents. No, I know we're not in monarchy :) lines.add("Washington,Adams"); // branch #1 lines.add("Adams,Jefferson"); // branch #2 lines.add("Jefferson,Madison"); // branch #3 lines.add("Madison,Monroe"); // branch #4 lines.add("Monroe,Quincy-Adams"); // branch #5 lines.add("Quincy-Adams,Jackson"); // branch #6 lines.add("Jackson,Buren"); // branch #7 lines.add("Buren,Harrison"); // branch #8 lines.add("Harrison,Tyler"); // branch #9 lines.add("Tyler,Polk"); // branch #10 return lines; } }