/** * @return {@code true} if this element has no children. It may have attributes. */ public boolean isEmpty() { return getContentType() == ElementContentType.EMPTY; }
/** * @return {@code true} if this element has only non-text (comments and elements) children. */ public boolean hasOnlyNonText() { return getContentType() == ElementContentType.NON_TEXT; }
/** * @return {@code true} if this element has text and non-text children. */ public boolean isMixed() { return getContentType() == ElementContentType.MIXED; }
/** * @return {@code true} if this element has only text children. */ public boolean hasOnlyText() { return getContentType() == ElementContentType.TEXT; }
Function<String, String> modifier) { for (final Element child : getElementsNamed(name)) { switch (child.getContentType()) { case EMPTY: case TEXT:
@Test public void testContentType() { final Element e = new Element(NAME); assertEquals(ElementContentType.EMPTY, e.getContentType()); e.addComment("Hello"); assertEquals(ElementContentType.NON_TEXT, e.getContentType()); e.removeChildren(); assertEquals(ElementContentType.EMPTY, e.getContentType()); e.addText("Hello"); assertEquals(ElementContentType.TEXT, e.getContentType()); e.addText("World"); assertEquals(ElementContentType.TEXT, e.getContentType()); e.addComment("Hello"); assertEquals(ElementContentType.MIXED, e.getContentType()); e.removeChildren(); assertEquals(ElementContentType.EMPTY, e.getContentType()); e.addElement("child"); assertEquals(ElementContentType.NON_TEXT, e.getContentType()); e.addComment("Hello"); assertEquals(ElementContentType.NON_TEXT, e.getContentType()); e.addText("World"); assertEquals(ElementContentType.MIXED, e.getContentType()); }
@Test public void testConstructors() { final Element e = new Element(NAME); assertEquals(null, e.getParent()); assertEquals(ElementContentType.EMPTY, e.getContentType()); e.addComment("comment", true); assertEquals(ElementContentType.NON_TEXT, e.getContentType()); }