sortFileByIndex method

  1. @visibleForTesting
List<File> sortFileByIndex(
  1. List<File> logFiles
)

Sort the list of log files by their log indexes.

The files are ordered in such way that the higher log index is the latest.

Implementation

@visibleForTesting
List<File> sortFileByIndex(final List<File> logFiles) {
  logFiles.sort((File leftFile, File rightFile) {
    final int leftFileIndex = getLogFileIndex(
      path.basenameWithoutExtension(leftFile.path),
    );

    final int rightFileIndex = getLogFileIndex(
      path.basenameWithoutExtension(rightFile.path),
    );

    // If the result is 0 then they are equal
    // If the result is lower to 0 then left is lower than right
    // If the result is greater to 0 then left is greater than right.
    return rightFileIndex - leftFileIndex;
  });

  return logFiles;
}