[New] Added IActivityElement.findParent(Predicate<Activity>)

This commit is contained in:
Robert von Burg 2020-02-20 17:59:10 +01:00
parent 2002f91820
commit c6f627be87
1 changed files with 14 additions and 0 deletions

View File

@ -15,6 +15,8 @@
*/
package li.strolch.model.activity;
import java.util.function.Predicate;
import li.strolch.exception.StrolchModelException;
import li.strolch.model.GroupedParameterizedElement;
import li.strolch.model.State;
@ -148,4 +150,16 @@ public interface IActivityElement extends StrolchElement {
* @return the result of the visitor being accepted
*/
<T> T accept(StrolchElementVisitor<T> visitor);
default Activity findParent(Predicate<Activity> predicate) {
Activity parent = getParent();
while (parent != null && !predicate.test(parent))
parent = parent.getParent();
if (parent == null)
throw new StrolchModelException(getLocator() + " has no parent where predicate " + predicate + " is true!");
return parent;
}
}