List<VcsDirectoryMapping> (@NotNull List<? extends VcsDirectoryMapping> existingMappings, @NotNull VcsDirectoryMapping newMapping) { List<VcsDirectoryMapping> mappings = new ArrayList<>(existingMappings); for (Iterator<VcsDirectoryMapping> iterator = mappings.iterator(); iterator.hasNext(); ) { VcsDirectoryMapping mapping = iterator.next(); if (mapping.isDefaultMapping() && mapping.isNoneMapping()) { LOG.debug("Removing <Project> -> <None> mapping"); iterator.remove(); } else if (FileUtil.pathsEqual(mapping.getDirectory(), newMapping.getDirectory())) { if (!StringUtil.isEmptyOrSpaces(mapping.getVcs())) { if (mapping.getVcs().equals(newMapping.getVcs())) { LOG.debug(String.format("Substituting existing mapping with identical [%s] -> [%s]", mapping.getDirectory(), mapping.getVcs())); } else { LOG.warn(String.format("Substituting existing mapping [%s] -> [%s] with [%s]", mapping.getDirectory(), mapping.getVcs(), newMapping.getVcs())); } } else { LOG.debug(String.format("Removing [%s] -> <None> mapping", mapping.getDirectory())); } iterator.remove(); } } mappings.add(newMapping); return mappings; }