Loading src/Main.java +11 −4 Original line number Diff line number Diff line Loading @@ -13,6 +13,13 @@ import java.net.Socket; public class Main { static MoleculeDatabase moleculeDb = null; static boolean verbose = false; public static void printVerbose(String s) { if (verbose) { System.out.println(s); } } public static void commandHandler1(String cmd) { switch (cmd) { Loading @@ -20,7 +27,7 @@ public class Main { moleculeDb.printDb(); break; default: System.out.println("unrecognized command: " + cmd); printVerbose("unrecognized command: " + cmd); break; } } Loading @@ -35,11 +42,11 @@ public class Main { if (molecule == null) { System.out.println("NOT FOUND"); } else { System.out.println("FOUND"); printVerbose("FOUND"); } break; default: System.out.println("unrecognized command: " + cmd); printVerbose("unrecognized command: " + cmd); break; } } Loading Loading @@ -110,6 +117,7 @@ public class Main { // save the database before exiting moleculeDb.save(dbName); System.out.println("Database saved successfully."); System.out.println("Goodbye"); } Loading @@ -117,7 +125,6 @@ public class Main { * Main method to start the program */ public static void main(String[] args) throws IOException { // System.out.println("\r"); final int ARG_COUNT = args.length; // Get the port number from the command line arguments Loading src/MoleculeDatabase.java +13 −5 Original line number Diff line number Diff line Loading @@ -16,6 +16,14 @@ public class MoleculeDatabase { public HashMap<Integer, ArrayList<Molecule>> db; // Molecule database static boolean verbose = false; public static void printVerbose(String s) { if (verbose) { System.out.println(s); } } /** * Constructs a database */ Loading @@ -38,6 +46,7 @@ public class MoleculeDatabase { */ public void addMolecule(Molecule molecule) { if (molecule == null) { printVerbose("molecule cannot be null"); return; } int numAtoms = molecule.getNumAtoms(); Loading @@ -57,14 +66,14 @@ public class MoleculeDatabase { // Retrieve the partitioned array list based on the number of atoms int numAtoms = molecule.getNumAtoms(); if (!db.containsKey(numAtoms)) { // System.out.println("no ArrayList with correct # of atoms"); printVerbose("no ArrayList with correct # of atoms"); return null; } ArrayList<Molecule> moleculesWithSameNumAtoms = db.get(numAtoms); // Iterate through the array list of molecules with the same number of atoms for (Molecule dbMolecule : moleculesWithSameNumAtoms) { System.out.println(dbMolecule.moleculeName + " vs " + molecule.moleculeName); printVerbose(dbMolecule.moleculeName + " vs " + molecule.moleculeName); Molecule result = dbMolecule.areMoleculesEqual(molecule); if (result != null) { return result; // Return the isomorphic molecule Loading @@ -82,7 +91,6 @@ public class MoleculeDatabase { objOutStream.writeObject(this.db); objOutStream.close(); fileOutStream.close(); System.out.println("Database saved successfully."); } /** Loading @@ -97,9 +105,9 @@ public class MoleculeDatabase { ObjectInputStream objInStream = new ObjectInputStream(fileInStream); try { this.db = (HashMap<Integer, ArrayList<Molecule>>) objInStream.readObject(); System.out.println("Database loaded successfully."); printVerbose("Database loaded successfully."); } catch (IOException | ClassNotFoundException e) { System.out.println("Error loading database: " + e.getMessage()); printVerbose("Error loading database: " + e.getMessage()); } objInStream.close(); fileInStream.close(); Loading Loading
src/Main.java +11 −4 Original line number Diff line number Diff line Loading @@ -13,6 +13,13 @@ import java.net.Socket; public class Main { static MoleculeDatabase moleculeDb = null; static boolean verbose = false; public static void printVerbose(String s) { if (verbose) { System.out.println(s); } } public static void commandHandler1(String cmd) { switch (cmd) { Loading @@ -20,7 +27,7 @@ public class Main { moleculeDb.printDb(); break; default: System.out.println("unrecognized command: " + cmd); printVerbose("unrecognized command: " + cmd); break; } } Loading @@ -35,11 +42,11 @@ public class Main { if (molecule == null) { System.out.println("NOT FOUND"); } else { System.out.println("FOUND"); printVerbose("FOUND"); } break; default: System.out.println("unrecognized command: " + cmd); printVerbose("unrecognized command: " + cmd); break; } } Loading Loading @@ -110,6 +117,7 @@ public class Main { // save the database before exiting moleculeDb.save(dbName); System.out.println("Database saved successfully."); System.out.println("Goodbye"); } Loading @@ -117,7 +125,6 @@ public class Main { * Main method to start the program */ public static void main(String[] args) throws IOException { // System.out.println("\r"); final int ARG_COUNT = args.length; // Get the port number from the command line arguments Loading
src/MoleculeDatabase.java +13 −5 Original line number Diff line number Diff line Loading @@ -16,6 +16,14 @@ public class MoleculeDatabase { public HashMap<Integer, ArrayList<Molecule>> db; // Molecule database static boolean verbose = false; public static void printVerbose(String s) { if (verbose) { System.out.println(s); } } /** * Constructs a database */ Loading @@ -38,6 +46,7 @@ public class MoleculeDatabase { */ public void addMolecule(Molecule molecule) { if (molecule == null) { printVerbose("molecule cannot be null"); return; } int numAtoms = molecule.getNumAtoms(); Loading @@ -57,14 +66,14 @@ public class MoleculeDatabase { // Retrieve the partitioned array list based on the number of atoms int numAtoms = molecule.getNumAtoms(); if (!db.containsKey(numAtoms)) { // System.out.println("no ArrayList with correct # of atoms"); printVerbose("no ArrayList with correct # of atoms"); return null; } ArrayList<Molecule> moleculesWithSameNumAtoms = db.get(numAtoms); // Iterate through the array list of molecules with the same number of atoms for (Molecule dbMolecule : moleculesWithSameNumAtoms) { System.out.println(dbMolecule.moleculeName + " vs " + molecule.moleculeName); printVerbose(dbMolecule.moleculeName + " vs " + molecule.moleculeName); Molecule result = dbMolecule.areMoleculesEqual(molecule); if (result != null) { return result; // Return the isomorphic molecule Loading @@ -82,7 +91,6 @@ public class MoleculeDatabase { objOutStream.writeObject(this.db); objOutStream.close(); fileOutStream.close(); System.out.println("Database saved successfully."); } /** Loading @@ -97,9 +105,9 @@ public class MoleculeDatabase { ObjectInputStream objInStream = new ObjectInputStream(fileInStream); try { this.db = (HashMap<Integer, ArrayList<Molecule>>) objInStream.readObject(); System.out.println("Database loaded successfully."); printVerbose("Database loaded successfully."); } catch (IOException | ClassNotFoundException e) { System.out.println("Error loading database: " + e.getMessage()); printVerbose("Error loading database: " + e.getMessage()); } objInStream.close(); fileInStream.close(); Loading