Element (@NotNull ArrangementSectionRule section) { final Element sectionElement = new Element(SECTION_ELEMENT_NAME); if (StringUtil.isNotEmpty(section.getStartComment())) { // or only != null ? sectionElement.setAttribute(SECTION_START_ATTRIBUTE, section.getStartComment()); } if (StringUtil.isNotEmpty(section.getEndComment())) { sectionElement.setAttribute(SECTION_END_ATTRIBUTE, section.getEndComment()); } //TODO: serialize start & end comment as rule? final List<StdArrangementMatchRule> rules = section.getMatchRules(); for (int i = 0; i < rules.size(); i++) { StdArrangementMatchRule rule = rules.get(i); if ((i != 0 || StringUtil.isEmpty(section.getStartComment())) && (i != rules.size() - 1 || StringUtil.isEmpty(section.getEndComment()))) { sectionElement.addContent(serialize(rule)); } } return sectionElement; }