File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
src/main/java/org/javawebstack/abstractdata/xml Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change 44import java .util .LinkedHashMap ;
55import java .util .List ;
66import java .util .Map ;
7+ import java .util .function .Consumer ;
78import java .util .stream .Collectors ;
89
910public class XMLElement implements XMLNode {
@@ -13,11 +14,15 @@ public class XMLElement implements XMLNode {
1314 private final List <XMLNode > childNodes = new ArrayList <>();
1415
1516 public XMLElement (String tagName ) {
17+ if (tagName == null )
18+ throw new IllegalArgumentException ("tagName can not be null" );
1619 this .tagName = tagName ;
1720 }
1821
1922 public XMLElement (String tagName , String text ) {
20- this (text );
23+ this (tagName );
24+ if (text == null )
25+ throw new IllegalArgumentException ("text can not be null" );
2126 text (text );
2227 }
2328
@@ -68,6 +73,12 @@ public XMLElement child(XMLNode childNode) {
6873 return this ;
6974 }
7075
76+ public XMLElement onlyIf (boolean condition , Consumer <XMLElement > fn ) {
77+ if (condition )
78+ fn .accept (this );
79+ return this ;
80+ }
81+
7182 public Map <String , String > getAttributes () {
7283 return attributes ;
7384 }
You can’t perform that action at this time.
0 commit comments