T (@NotNull FileNameMatcher matcher, @NotNull T type) { if (matcher instanceof ExtensionFileNameMatcher) { String extension = ((ExtensionFileNameMatcher)matcher).getExtension(); return myExtensionMappings.put(extension, type); } if (matcher instanceof ExactFileNameMatcher) { ExactFileNameMatcher exactFileNameMatcher = (ExactFileNameMatcher)matcher; Map<CharSequence, T> mapToUse = exactFileNameMatcher.isIgnoreCase() ? myExactFileNameAnyCaseMappings : myExactFileNameMappings; return mapToUse.put(exactFileNameMatcher.getFileName(), type); } int i = ContainerUtil.indexOf(myMatchingMappings, p -> p.first.equals(matcher)); if (i == -1) { myMatchingMappings.add(Pair.create(matcher, type)); return null; } Pair<FileNameMatcher, T> old = myMatchingMappings.get(i); myMatchingMappings.set(i, Pair.create(matcher, type)); return Pair.getSecond(old); }