Untitled
Anonymous
plain_text
03/01/2026 5:53 AM
3.2 KB
18
Indexable
// -------------------------------------------------------------------------
/**
* Accumulates results from a DNA tree search operation.
* Tracks matched sequences and the number of nodes visited.
*
* @author Ishita Punna
* @author Leguejou Awunganyi
* @version Spring 2026
*/
public class SearchResult {
/** The sequences found during this search. */
private String[] same;
/** The number of matches found. */
private int sameCount;
/** The number of nodes visited during the search. */
private int nodesVisited;
/** Initial capacity for matches array. */
private static final int INIT_CAP = 16;
// ----------------------------------------------------------
/**
* Construct a new empty SearchResult.
*/
public SearchResult() {
same = new String[INIT_CAP];
sameCount = 0;
nodesVisited = 0;
}
// ----------------------------------------------------------
/**
* Add a matched sequence to results.
*
* @param sequence
* The matched sequence
*/
public void addMatch(String sequence) {
if (sameCount == same.length) {
String[] bigger = new String[same.length * 2];
for (int i = 0; i < same.length; i++) {
bigger[i] = same[i];
}
same = bigger;
}
same[sameCount] = sequence;
sameCount++;
}
// ----------------------------------------------------------
/**
* Increment the visited node counter.
*/
public void visit() {
nodesVisited++;
}
// ----------------------------------------------------------
/**
* Get the number of nodes visited.
*
* @return node visit count
*/
public int getNodesVisited() {
return nodesVisited;
}
// ----------------------------------------------------------
/**
* Get the number of matches found.
*
* @return match count
*/
public int getSameCount() {
return sameCount;
}
// ----------------------------------------------------------
/**
* Get a matched sequence by index.
*
* @param index
* The index to retrieve
* @return The sequence at that index
*/
public String getSame(int index) {
return same[index];
}
}Editor is loading...
Leave a Comment