Add helper methods

This commit is contained in:
SiboVG 2022-03-04 18:10:44 +01:00
parent ff00ace5e4
commit e82a7a89b2

View File

@ -1623,6 +1623,23 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
checkState();
return parent;
}
/**
* Get all the parent and super-parent components of this component.
* @return parent and super-parents of this component
*/
public final List<RocketComponent> getParents() {
checkState();
List<RocketComponent> result = new LinkedList<>();
RocketComponent currComp = this;
while (currComp.parent != null) {
currComp = currComp.parent;
result.add(currComp);
}
return result;
}
/**
* Get the root component of the component tree.
@ -1710,6 +1727,26 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
}
return result;
}
/**
* Return all the component assemblies that are a parent or super-parent of this component
* @return list of ComponentAssembly components that are a parent or super-parent of this component
*/
public final List<RocketComponent> getParentAssemblies() {
checkState();
List<RocketComponent> result = new LinkedList<>();
RocketComponent currComp = this;
while (currComp.parent != null) {
currComp = currComp.parent;
if (currComp instanceof ComponentAssembly) {
result.add(currComp);
}
}
return result;
}
/**