Untitled
Anonymous
plain_text
02/22/2026 11:29 PM
4.2 KB
20
Indexable
//-------------------------------------------------------------------------
/**
* The database implementation for this project.
* This manages the commands for the DNA tree.
*
* @author CS3114/5040 Staff
* @version Spring 2026
*
*/
public class DNADB implements DNA {
/**
* Create a new DNADB object.
*/
public DNADB() {
// Tree will be added later
}
// ----------------------------------------------------------
/**
* Insert a DNA string into the database
* @param sequence The sequence to insert
* @return The outcomes message string
*/
public String insert(String sequence) {
String bad = validate(sequence);
if (bad != null) {
return bad;
}
// Milestone 1 minimal behavior
return "Sequence |" + sequence + "| inserted";
}
// ----------------------------------------------------------
/**
* Remove a DNA string into the database
* @param sequence The sequence to remove
* @return The outcomes message string
*/
public String remove(String sequence) {
String bad = validate(sequence);
if (bad != null) {
return bad;
}
return "Sequence |" + sequence + "| does not exist";
}
// ----------------------------------------------------------
/**
* Print the tree
* @return the print string
*/
public String print() {
return "tree dump:\r\nE";
}
// ----------------------------------------------------------
/**
* Print the lengths
* @return the print string
*/
public String printLengths() {
return "tree dump with lengths:\r\nE";
}
// ----------------------------------------------------------
/**
* Print the stats
* @return the print string
*/
public String printStats() {
return "tree dump with stats:\r\nE";
}
// ----------------------------------------------------------
/**
* Search for a given string
* @param sequence The sequence to search for
* @return the print string
*/
public String search(String sequence) {
String bad = validate(sequence);
if (bad != null) {
return bad;
}
return "No sequence found\r\n# of nodes visited: 1";
}
/**
* Validates input for Milestone 1
*/
private String validate(String sequence) {
if (sequence == null) {
return "Bad input: Sequence may not be null\r\n";
}
if (sequence.isEmpty()) {
return "Bad input: Sequence may not be empty\r\n";
}
for (int i = 0; i < sequence.length(); i++) {
char c = sequence.charAt(i);
// if (c != 'A' && c != 'C' && c != 'G' && c != 'T' && c != '$')
// this top if might be a problem later just to note
if (c != 'A' && c != 'C' && c != 'G' && c != 'T') {
return "Bad Input Sequence |" + sequence + "|\r\n";
}
}
return null;
}
}Editor is loading...
Leave a Comment