class KiltReformatter {

  public void reorderByTemplate(final File template, final FileMatcher fileMatcher, final AttachCommentsTo attachCommentsTo, final Charset charset) {
    Require.nonNull(fileMatcher);
    Require.nonNull(attachCommentsTo);
    Require.nonNull(charset);

    final Set<File> propertyFiles= fileMatcher.findMatchingFiles();
    LOGGER.log(Level.INFO, "Reordering entries by template {} in the following files: {}", template, propertyFiles);

    // create a PropertyFile instance for each file
    final PropertyFile reference= PropertyFile.from(template, charset);
    final Set<RememberingPropertyFile> pfs= propertyFiles.stream()
      .filter(_f -> {
        if (_f.getAbsolutePath().equals(template.getAbsolutePath())) {
          LOGGER.log(Level.DEBUG, "Ignoring property file "+_f.getAbsolutePath()+" because it is the same as the reference template.");
          return false;
        } else {
          return true;
        }
      })
      .map(_f -> {
        return RememberingPropertyFile.from(_f, charset);
      })
      .collect(Collectors.toSet());

//    // and reorder in the given order
//    for (int i= 1; i < pfs.size(); i++) {
//      final RememberingPropertyFile rpf= pfs.get(i);
//      new Reformatter().reorderByTemplate(pfs.get(i - 1).propertyFile, rpf.propertyFile, attachCommentsTo);
//      rpf.propertyFile.overwrite(rpf.actualFile);
//    }

    // and reorder them
    final Reformatter reformatter= new Reformatter(
    ReformatOptions.create()
      .with(charset)
      .with(attachCommentsTo));

    for (final RememberingPropertyFile rpf : pfs) {
      reformatter.reorderByTemplate(reference, rpf.propertyFile);
      rpf.propertyFile.overwrite(rpf.actualFile, APRON_OPTIONS.with(charset));
    }
  }

}