class InterestRateCurveSensitivityUtils {

  static final List<DoublesPair> clean(final List<DoublesPair> old, final double relTol, final double absTol) {

    ArgumentChecker.notNull(old, "null list");
    ArgumentChecker.isTrue(relTol >= 0.0 && absTol >= 0.0, "Tolerances must be greater than zero");
    if (old.size() == 0) {
      return new ArrayList<>();
    }
    final List<DoublesPair> res = new ArrayList<>();
    final DoublesPair[] sort = old.toArray(new DoublesPair[old.size()]);
    Arrays.sort(sort, FirstThenSecondDoublesPairComparator.INSTANCE);
    final DoublesPair pairOld = sort[0];
    double tOld = pairOld.first;
    double sum = pairOld.getSecond();
    double scale = Math.abs(sum);
    double t = tOld;
    for (int i = 1; i < sort.length; i++) {
      final DoublesPair pair = sort[i];
      t = pair.first;
      if (t > tOld) {
        if (Math.abs(sum) > absTol && Math.abs(sum) / scale > relTol) {
          res.add(DoublesPair.of(tOld, sum));
        }
        tOld = t;
        sum = pair.getSecondDouble();
        scale = Math.abs(sum);
      } else {
        sum += pair.getSecondDouble();
        scale += Math.abs(pair.getSecondDouble());
      }
    }

    if (Math.abs(sum) > absTol && Math.abs(sum) / scale > relTol) {
      res.add(DoublesPair.of(t, sum));
    }

    return res;
  }

  protected  InterestRateCurveSensitivityUtils();

}