Element (Element element) { Comparator<BaseInjection> comparator = (o1, o2) -> { int rc = Comparing.compare(o1.getDisplayName(), o2.getDisplayName()); if (rc != 0) return rc; return ContainerUtil.compareLexicographically( Arrays.asList(o1.getInjectionPlaces()), Arrays.asList(o2.getInjectionPlaces()), (o11, o22) -> { if (o11.isEnabled() && !o22.isEnabled()) return -1; if (!o11.isEnabled() && o22.isEnabled()) return 1; return Comparing.compare(o11.getElementPattern().toString(), o22.getElementPattern().toString()); }); }; for (String key : new TreeSet<>(myInjections.keySet())) { Set<BaseInjection> injections = new HashSet<>(myInjections.get(key)); injections.removeAll(getDefaultInjections()); for (BaseInjection injection : ContainerUtil.sorted(injections, comparator)) { element.addContent(injection.getState()); } } return element; }