#include "LineStat.h"
#include "BlankStat.h"


LineStat::LineStat() {
  list.reserve( 10 );
}


LineStat::~LineStat() {
}


void LineStat::beginJob() {
  // create 3 mean calculators for 3 length ranges,
  // if any range does change, it must be changed in "process" function, too
  list.push_back( new BlankStat(  1, 20 ) );
  list.push_back( new BlankStat( 21, 40 ) );
  list.push_back( new BlankStat( 41, 80 ) );
  return;
}


void LineStat::process( const std::string& line ) {
  // pass the input line to the relevant mean calculator,
  // if any range does change, it must be changed in "beginJob" function, too
  int length = line.length();
  if ( ( length >=  1 ) &&
       ( length <= 20 ) ) list[0]->process( line );
  if ( ( length >= 21 ) &&
       ( length <= 40 ) ) list[1]->process( line );
  if ( ( length >= 41 ) &&
       ( length <= 80 ) ) list[2]->process( line );
  return;
}


void LineStat::endJob() {
  // print results for all mean calculators
  int i;
  int n = list.size();
  for ( i = 0; i < n; ++i ) list[i]->print();
  return;
}

