/*public String itemWithNthHighestPeak(int n){
     TreeMap peaks = peakResults();
     peakResult next = new peakResult();
     for(int i=0;peaks.size()>0&&i<n;i++){
         next=(peakResult)(peaks.remove(peaks.firstKey()));
     }
     return next.name;
 } */
 public String decisionResult(double thresh) {
   TreeMap decisions = decisionResults(thresh);
   String result;
   if (decisions.size() > 0) result = ((decisResult) decisions.firstKey()).name;
   else result = "(null)";
   return result;
 }
  public String decisionRuleReport(double thresh, String target) {
    /*format of output:
     winning-item, thresh, rt, peak, peak-cycle, (#target-item, thresh, rt, peak, peak-cycle)
       # first-item-to-thresh,second-item-to-thresh,...tenth-item-to-thresh BASTA
     three possible outcomes:
       1. target is recognized first: report its stats only. # #
       2. another item is recognized first: report the winner, # then target stats. #
       3. no item is recognized: # report the target's stats. #
     TODO: right now, the silence segment is always the winner: this could be prevented if we wanted
     TODO: instead of top-ten to thresh, top-ten peaks might be more useful
    */

    if (target.startsWith("-") && target.length() > 1) {
      String[] split = target.split("-");
      if (split == null || split.length == 0 || (split.length == 1 && split[0].equals("")))
        target = "-";
      else {
        target = split[1];
      }
    }
    String result = "target=\t" + target + "\t";
    TreeMap decisions = decisionResults(thresh);
    decisResult next;
    // record winning-item stats
    if (decisions.size() > 0) {
      next = (decisResult) (decisions.remove(decisions.firstKey()));
      result += next.name + "\t" + next.thresh + "\t";
      if (next.recogRt == 12345) result += "\\N\t";
      else result += next.recogRt + "\t";
      result += next.peak + "\t" + next.peakRt + "\t";
    }
    // no decision results!
    else {
      result += "(null)";
      // System.out.println(result);
      return result;
    }
    result += "#\t";
    // is the winning item the target?
    if (next.name.equals(target)) {
      // yes : great! don't report anything else
    } else {
      // if not, find the target and report its stats.
      while (decisions.size() > 0) {
        next = (decisResult) (decisions.remove(decisions.firstKey()));
        if (next.name.equals(target)) {
          result += next.name + "\t" + next.thresh + "\t";
          if (next.recogRt == 12345) result += "-1\t";
          else result += next.recogRt + "\t";
          result += next.peak + "\t" + next.peakRt;
          break;
        }
      }
    }
    decisions = decisionResults(thresh);
    result += "#\t";
    for (int i = 0; decisions.size() > 0 && i < 10; i++) {
      next = (decisResult) (decisions.remove(decisions.firstKey()));
      result += next.name + "\t";
    }
    // System.out.println(result);
    return result;
  }