Builder () { return new Builder() { private final Map<File, String> myMap = new HashMap<>(); private final Collection<File> myPath = new ArrayList<>(); @Override public Builder add(String moduleName, File pathElement) { myPath.add(pathElement); if (moduleName != null) { myMap.put(pathElement, moduleName); } return this; } @Override public ModulePath create() { if (myPath.isEmpty()) { return EMPTY; } final Collection<File> files = Collections.unmodifiableCollection(myPath); return new ModulePath() { @Override public Collection<? extends File> getPath() { return files; } @Override public String getModuleName(File pathElement) { return myMap.get(pathElement); } }; } }; }