private File findMostLikelyHomeDir( List<File> possibleHomeDirList, List<String> homeContentPathList) { int numFoundMax = 0; File mostLikelyHomeDir = null; for (File possibleHomeDir : possibleHomeDirList) { trace(String.format("Is [%s] my home directory?", possibleHomeDir)); int numFound = 0; for (String homeContentPath : homeContentPathList) { File homeContentFile = new File(possibleHomeDir, homeContentPath); if (homeContentFile.exists()) { trace(String.format(" [%s] contained? Yes.", homeContentPath)); numFound++; } else { trace(String.format(" [%s] contained? No.", homeContentPath)); } } if (numFound == 0) { trace("No."); } else { trace(String.format("Maybe. %d related file(s) found.", numFound)); } if (numFound > numFoundMax) { try { mostLikelyHomeDir = possibleHomeDir.getCanonicalFile(); numFoundMax = numFound; } catch (IOException e) { // ??? } } } return mostLikelyHomeDir; }