Loading src/Main.java +7 −0 Original line number Diff line number Diff line Loading @@ -122,6 +122,13 @@ public class Main { printVerbose("invalid Input"); } break; case "--delete": boolean delete= moleculeDb.deleteMolecule(new Molecule(moleculePath)); if(delete) printVerbose("Successfully Deleted"); else printVerbose("Molecule not deleted or already not in the database"); break; default: printVerbose("unrecognized command: " + cmd); break; Loading src/MoleculeDatabase.java +24 −0 Original line number Diff line number Diff line Loading @@ -176,6 +176,30 @@ public class MoleculeDatabase { return returnList; } /** * Delete a given molecule if it is in the database */ public boolean deleteMolecule(Molecule molecule){ // Retrieve the partitioned array list based on the number of atoms int numAtoms = molecule.getNumAtoms(); if (!db.containsKey(numAtoms)) { return false; } ArrayList<Molecule> moleculesWithSameNumAtoms = db.get(numAtoms); // Iterate through the array list of molecules with the same number of atoms for (Molecule dbMolecule : moleculesWithSameNumAtoms) { Molecule result = dbMolecule.areMoleculesEqual(molecule); if (result != null) { db.get(numAtoms).remove(dbMolecule); return true; // successfully delete the molecule } } return false; // Return false if molecule not in database } /** * Save database to file system */ Loading Loading
src/Main.java +7 −0 Original line number Diff line number Diff line Loading @@ -122,6 +122,13 @@ public class Main { printVerbose("invalid Input"); } break; case "--delete": boolean delete= moleculeDb.deleteMolecule(new Molecule(moleculePath)); if(delete) printVerbose("Successfully Deleted"); else printVerbose("Molecule not deleted or already not in the database"); break; default: printVerbose("unrecognized command: " + cmd); break; Loading
src/MoleculeDatabase.java +24 −0 Original line number Diff line number Diff line Loading @@ -176,6 +176,30 @@ public class MoleculeDatabase { return returnList; } /** * Delete a given molecule if it is in the database */ public boolean deleteMolecule(Molecule molecule){ // Retrieve the partitioned array list based on the number of atoms int numAtoms = molecule.getNumAtoms(); if (!db.containsKey(numAtoms)) { return false; } ArrayList<Molecule> moleculesWithSameNumAtoms = db.get(numAtoms); // Iterate through the array list of molecules with the same number of atoms for (Molecule dbMolecule : moleculesWithSameNumAtoms) { Molecule result = dbMolecule.areMoleculesEqual(molecule); if (result != null) { db.get(numAtoms).remove(dbMolecule); return true; // successfully delete the molecule } } return false; // Return false if molecule not in database } /** * Save database to file system */ Loading