class MovingAverageTimeSeriesOrderIdentifier {

  public int getOrder(final DoubleTimeSeries<?> ts) {
    Validate.notNull(ts);
    if (ts.isEmpty()) {
      throw new IllegalArgumentException("Time series was empty");
    }
    if (ts.size() < _maxOrder) {
      throw new IllegalArgumentException("Number of data points lower than the maximum order to calculate");
    }
    final double[] acf = _calculator.evaluate(ts);
    final int n = ts.size();
    final double bound = _criticalValue / Math.sqrt(n);
    for (int i = _maxOrder; i > 0; i--) {
      if (Math.abs(acf[i]) > bound) {
        return i;
      }
    }
    throw new IllegalArgumentException("Could not find order of series; no significant autocorrelations");
  }

  public  MovingAverageTimeSeriesOrderIdentifier(final int maxOrder, final double level);

}