List<TemplateImpl> (@NotNull List<? extends TemplateGroup> groups) { List<TemplateImpl> result = new ArrayList<>(); for (TemplateGroup group : groups) { result.addAll(group.getElements()); } result.sort((o1, o2) -> { final int groupsEqual = o1.getGroupName().compareToIgnoreCase(o2.getGroupName()); if (groupsEqual != 0) { return groupsEqual; } return o1.getKey().compareToIgnoreCase(o2.getKey()); }); return result; }