class DensityAwareFileComparator implements Comparator<File> {

  @Override
  public int compare(@NotNull File file1, @NotNull File file2) {
    int c = -Boolean.compare(myDirectories.contains(file1), myDirectories.contains(file2));
    if (c != 0) {
      return c;
    }
    String path1 = file1.getAbsolutePath();
    String path2 = file2.getAbsolutePath();
    Density density1 = pathToDensity(path1 + File.separator);
    Density density2 = pathToDensity(path2 + File.separator);
    c = Boolean.compare(density1 != null, density2 != null); // Files and directories with a density suffix are sorted first.
    if (c != 0) {
      return c;
    }

    if (density1 != null && density2 != null && density1 != density2) {
      return Integer.compare(density2.getDpiValue(), density1.getDpiValue()); // Sort least dense to most dense.
    }

    return path1.compareTo(path2);
  }

  public  DensityAwareFileComparator(@NotNull Set<File> directories);

}