#include "ButtonDifference.h"
#include "OneButton.h"
#include "SampleDifference.h"

ButtonDifference::ButtonDifference(OneButton * one_button)
 : max_diff_time(0), log_max_diff_time(0.0) {

   unsigned int len = one_button->NumSamples();
   for (unsigned int i = 0; i < len; ++i) {
      SampleDifference * sd = new SampleDifference((*one_button)[i]);
      for (unsigned int j = 0; j < len; ++j) {
         if (j != i) {
            sd->CompareSample((*one_button)[j]);
         }
      }
      sd->FinishDiffs();
      unsigned long tt = sd->TotalTime();
      if (tt > max_diff_time) {
         max_diff_time = tt;
      }
      double dtt = sd->LogTotalTime();
      if (dtt > log_max_diff_time) {
         log_max_diff_time = dtt;
      }
      diff.push_back(sd);
   }
}

ButtonDifference::~ButtonDifference() {
   return;
}

unsigned int
ButtonDifference::NumDiffs() const {
   return diff.size();
}

SampleDifference *
ButtonDifference::operator[](unsigned int ndx) const {
   if (ndx >= diff.size()) {
      return NULL;
   }
   return diff[ndx];
}
