code: private void addFile(int index, String file) {
          if (maxFiles > 0) {
              int numFiles = files.size();
              int maxDateFiles = getMaxDateFiles();
  
              // If there is no max or we have fewer than max, then we're done.
              if (maxDateFiles <= 0 || numFiles < maxDateFiles) {
                  files.add(index, file);
              } else {
                  // The file names we deal with (messages_xx.xx.xx_xx.xx.xx.log)
                  // have dates, and we want to always be using the "most recent",
                  // so delete everything "newer" (index and after), which might be
                  // present if the system clock goes backwards, and then delete
                  // the oldest files until only maxDateFiles-1 remain.
                  while (files.size() > index) {
                      removeFile(files.size() - 1);
                  }
                  while (files.size() >= maxDateFiles) {
                      removeFile(0);
                  }
  
                  files.add(file);
              }
          }
      }
docs: Adds a file name to the files list at the specified index. If adding
  this file would cause the number of files to exceed the maximum, remove
  all files after the specified index, and then remove the oldest files
  until the number is reduced to the maximum.
  
  @param index the index in the files list to insert the file
  @param file the file name