X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.api.acr%2Fsrc%2Forg%2Fargeo%2Fapi%2Facr%2FContent.java;h=4aac92de75b2317f78b83bea56329535c630ff81;hb=c0342975a37c70895c2e8f6b341d790700168d7f;hp=0fdc14fe30e9f0146afbc8f8dde42187086d0200;hpb=5dd5ad8acfa6f78f98b8d8f082f0c1647d02ff2a;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.api.acr/src/org/argeo/api/acr/Content.java b/org.argeo.api.acr/src/org/argeo/api/acr/Content.java index 0fdc14fe3..4aac92de7 100644 --- a/org.argeo.api.acr/src/org/argeo/api/acr/Content.java +++ b/org.argeo.api.acr/src/org/argeo/api/acr/Content.java @@ -2,6 +2,7 @@ package org.argeo.api.acr; import java.io.Closeable; import java.io.IOException; +import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Optional; @@ -129,6 +130,34 @@ public interface Content extends Iterable, Map { throw new UnsupportedOperationException("Cannot write content " + this + " as " + clss.getName()); } + /* + * CHILDREN + */ + + default boolean hasChild(QName name) { + for (Content child : this) { + if (child.getName().equals(name)) + return true; + } + return false; + } + + default Content anyOrAddChild(QName name, QName... classes) { + Content child = anyChild(name); + if (child != null) + return child; + return this.add(name, classes); + } + + /** Any child with this name, or null if there is none */ + default Content anyChild(QName name) { + for (Content child : this) { + if (child.getName().equals(name)) + return child; + } + return null; + } + /* * CONVENIENCE METHODS */