/** * Returns the child at the specified index. If the index is out of bounds, returns null. * * @param index The index of the child sought. * @return Child at the specified index or null if the index is out of bounds. */ public BaseComponent getChildAt(int index) { return index < 0 || index >= getChildCount() ? null : children.get(index); }
/** * Returns the last child of this component. * * @return The last child, or null if no children. */ public BaseComponent getLastChild() { return getChildAt(getChildCount() - 1); }
/** * Validates that the specified component may be added as a child. * * @param child The component to check. * @exception ComponentException Thrown if the component fails validation. */ protected void validateChild(BaseComponent child) { componentDefinition.validateChild(child.componentDefinition, () -> getChildCount(child.getClass())); }
/** * Returns the sibling of this component at the specified offset. * * @param offset Offset from this component. For example, 2 would mean the second sibling * following this component. * @return The requested sibling, or null if none exists at the requested offset. */ private BaseComponent getRelativeSibling(int offset) { int i = getIndex(); i = i == -1 ? -1 : i + offset; return i < 0 || i >= getParent().getChildCount() ? null : getParent().getChildAt(i); }