private Pair<Double, Integer> max(double[] x, int startIndex, int endIndex) {
    double maxValue = -Double.MAX_VALUE;
    int maxIndex = -1;
    for (int i = startIndex; i < endIndex; i++) {
      if (x[i] > maxValue) {
        maxValue = x[i];
        maxIndex = i;
      }
    }
    return Pair.create(x[maxIndex], maxIndex);
  }
The function is used to compute the period of a numeric time series.
library-udf/src/main/java/org/apache/iotdb/library/dprofile/UDAFPeriod.java