public void setDefaultTemplate(String name) { Set<String> fullNames = ContainerUtil.newHashSet(toEqualsName(name), toHashCodeName(name)); for (TemplateResource resource : getAllTemplates()) { if (fullNames.contains(resource.getFileName())) { setDefaultTemplate(resource); break; } } }
private TemplateResource getDefaultTemplate( String selfSuffix, String oppositeSuffix, TemplateResource defaultTemplate) { final String fileName = defaultTemplate.getFileName(); if (fileName.endsWith(selfSuffix)) { return defaultTemplate; } final String equalsTemplateName = StringUtil.trimEnd(fileName, oppositeSuffix) + selfSuffix; for (TemplateResource resource : getAllTemplates()) { if (equalsTemplateName.equals(resource.getFileName())) { return resource; } } assert false : selfSuffix + " template for " + fileName + " not found"; return null; }
public Collection<Couple<TemplateResource>> getTemplateCouples() { final LinkedHashMap<String, Couple<TemplateResource>> resources = new LinkedHashMap<String, Couple<TemplateResource>>(); for (TemplateResource resource : getAllTemplates()) { final String baseName = getTemplateBaseName(resource); TemplateResource eq = toEqualsName(baseName).equals(resource.getFileName()) ? resource : null; TemplateResource hc = toHashCodeName(baseName).equals(resource.getFileName()) ? resource : null; final Couple<TemplateResource> couple = resources.get(baseName); if (couple != null) { resources.put( baseName, Couple.of( couple.first != null ? couple.first : eq, couple.second != null ? couple.second : hc)); } else { resources.put(baseName, Couple.of(eq, hc)); } } return resources.values(); }
@NotNull public static String getTemplateBaseName(TemplateResource resource) { return StringUtil.trimEnd( StringUtil.trimEnd(resource.getFileName(), EQUALS_SUFFIX), HASH_CODE_SUFFIX) .trim(); }