Loading src/GUI.java +20 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ public class GUI extends JFrame { private JButton displayMoleculeButton; private JButton findSubgraphButton; private JButton downloadPubChemButton; private JButton deleteMoleculeButton; private JTextField filePathField; private static MDB moleculeDb; private Socket clientSocket; Loading @@ -42,6 +43,7 @@ public class GUI extends JFrame { JScrollPane scrollPane = new JScrollPane(outputTextArea); chooseFileButton = new JButton("Choose File"); downloadPubChemButton = new JButton("Download PubChem"); deleteMoleculeButton = new JButton("Delete Molecule"); addMoleculeButton = new JButton("Add Molecule"); findMoleculeButton = new JButton("Find Molecule"); findSubgraphButton = new JButton("Find Subgraph"); Loading @@ -58,6 +60,7 @@ public class GUI extends JFrame { controlPanel.setBackground(Color.BLACK); controlPanel.add(chooseFileButton); controlPanel.add(downloadPubChemButton); controlPanel.add(deleteMoleculeButton); controlPanel.add(addMoleculeButton); controlPanel.add(findMoleculeButton); controlPanel.add(findSubgraphButton); Loading Loading @@ -109,6 +112,23 @@ public class GUI extends JFrame { } }); //Action Listener for Delete Molecule button deleteMoleculeButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // Get the molecule path from the text field String moleculePath = filePathField.getText(); // Execute the findMolecule command boolean delete= moleculeDb.deleteMolecule(new Molecule(moleculePath)); if(delete) outputTextArea.append("Successfully Deleted" + "\n\n"); else outputTextArea.append("Molecule not in the database" + "\n\n"); } }); // Action listener for Add Molecule button addMoleculeButton.addActionListener(new ActionListener() { @Override Loading src/MDB.java +23 −0 Original line number Diff line number Diff line Loading @@ -145,6 +145,29 @@ public class MDB { return similar; } /** * 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) { this.db.get(numAtoms).remove(dbMolecule); return true; // successfully delete the molecule } } return false; // Return false if molecule not in database } /** * Find subgraph */ 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 System.out.println("Molecule 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) { this.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/GUI.java +20 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ public class GUI extends JFrame { private JButton displayMoleculeButton; private JButton findSubgraphButton; private JButton downloadPubChemButton; private JButton deleteMoleculeButton; private JTextField filePathField; private static MDB moleculeDb; private Socket clientSocket; Loading @@ -42,6 +43,7 @@ public class GUI extends JFrame { JScrollPane scrollPane = new JScrollPane(outputTextArea); chooseFileButton = new JButton("Choose File"); downloadPubChemButton = new JButton("Download PubChem"); deleteMoleculeButton = new JButton("Delete Molecule"); addMoleculeButton = new JButton("Add Molecule"); findMoleculeButton = new JButton("Find Molecule"); findSubgraphButton = new JButton("Find Subgraph"); Loading @@ -58,6 +60,7 @@ public class GUI extends JFrame { controlPanel.setBackground(Color.BLACK); controlPanel.add(chooseFileButton); controlPanel.add(downloadPubChemButton); controlPanel.add(deleteMoleculeButton); controlPanel.add(addMoleculeButton); controlPanel.add(findMoleculeButton); controlPanel.add(findSubgraphButton); Loading Loading @@ -109,6 +112,23 @@ public class GUI extends JFrame { } }); //Action Listener for Delete Molecule button deleteMoleculeButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // Get the molecule path from the text field String moleculePath = filePathField.getText(); // Execute the findMolecule command boolean delete= moleculeDb.deleteMolecule(new Molecule(moleculePath)); if(delete) outputTextArea.append("Successfully Deleted" + "\n\n"); else outputTextArea.append("Molecule not in the database" + "\n\n"); } }); // Action listener for Add Molecule button addMoleculeButton.addActionListener(new ActionListener() { @Override Loading
src/MDB.java +23 −0 Original line number Diff line number Diff line Loading @@ -145,6 +145,29 @@ public class MDB { return similar; } /** * 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) { this.db.get(numAtoms).remove(dbMolecule); return true; // successfully delete the molecule } } return false; // Return false if molecule not in database } /** * Find subgraph */ 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 System.out.println("Molecule 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) { this.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