public Optional<Path> mostRecentFile() throws IOException {
    if (!Files.exists(directory) || !Files.isDirectory(directory)) {
      return Optional.empty();
    }
    // find files matching fileNameFormat, extract dates of creation, and remove the oldest files
    final Comparator<Pair<Path, Date>> byDateOfCreation = comparing(pair -> pair.second);
    try (final Stream<Path> children = Files.list(directory)) {
      return children.map(this::tryParsePath)
        .filter(pair -> pair.second != null)
        .max(byDateOfCreation)
        .map(pair -> pair.first);
    }
  }
public Optional<Path> mostRecentFile()