Interface ComponentTree<E extends Component>
- Type Parameters:
E- Type of components contained by this tree
- All Known Subinterfaces:
MessageComponentTree,ModalComponentTree
public interface ComponentTree<E extends Component>
Represents a tree of components, in which you can find, replace or remove components recursively.
As with every component, component trees are immutable and will return a new instance on every mutating call.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumRepresents the type of component tree. -
Method Summary
Modifier and TypeMethodDescriptiondefault ComponentTree<E> Disables all components which can be disabled, and constructs a new tree from the result.default ComponentTree<E> Enables all components which can be enabled, and constructs a new tree from the result.Finds the first component with the given type and satisfying the filter, recursively.Finds all components with the given type, recursively.Finds all components with the given type and satisfying the filter, recursively.static MessageComponentTreeforMessage(Collection<? extends MessageTopLevelComponent> components) Creates aMessageComponentTreefrom the given top-level message components.static ModalComponentTreeforModal(Collection<? extends ModalTopLevelComponent> components) Creates aModalComponentTreefrom the given top-level message components.Unmodifiable list of components contained by this tree.getType()Returns the type of this component tree.static <E extends Component,T extends IComponentUnion>
ComponentTree<T> of(Class<T> unionType, Collection<E> components) Creates aComponentTreefrom the given components, and checks their compatibility.static ComponentTree<IComponentUnion> of(Collection<? extends Component> components) Creates aComponentTreefrom the given components.replace(ComponentReplacer replacer) Replaces and/or removes components using the providedComponentReplacer, and construct a new tree from the result.withDisabled(boolean disabled) Enables or disables all components which can be enabled/disabled, and constructs a new tree from the result.
-
Method Details
-
of
@Nonnull static <E extends Component,T extends IComponentUnion> ComponentTree<T> of(@Nonnull Class<T> unionType, @Nonnull Collection<E> components) Creates aComponentTreefrom the given components, and checks their compatibility.- Parameters:
unionType- The union type expected from the componentscomponents- List of components to construct the tree from- Returns:
- A
ComponentTreecontaining the given components - Throws:
IllegalArgumentException- Ifnullis provided, or if one of the component is not of the provided union type
-
of
@Nonnull static ComponentTree<IComponentUnion> of(@Nonnull Collection<? extends Component> components) Creates aComponentTreefrom the given components.- Parameters:
components- List of components to construct the tree from- Returns:
- A
ComponentTreecontaining the given components - Throws:
IllegalArgumentException- Ifnullis provided
-
forMessage
@Nonnull static MessageComponentTree forMessage(@Nonnull Collection<? extends MessageTopLevelComponent> components) Creates aMessageComponentTreefrom the given top-level message components.
This is a shortcut forMessageComponentTree.of(components).- Parameters:
components- List of components to construct the tree from- Returns:
- A
MessageComponentTreecontaining the given components - Throws:
IllegalArgumentException- Ifnullis provided
-
forModal
@Nonnull static ModalComponentTree forModal(@Nonnull Collection<? extends ModalTopLevelComponent> components) Creates aModalComponentTreefrom the given top-level message components.
This is a shortcut forModalComponentTree.of(components).- Parameters:
components- List of components to construct the tree from- Returns:
- A
ModalComponentTreecontaining the given components - Throws:
IllegalArgumentException- Ifnullis provided
-
getType
Returns the type of this component tree.- Returns:
- The type of this component tree
-
getComponents
Unmodifiable list of components contained by this tree.- Returns:
- An unmodifiable list of components in this tree
-
findAll
Finds all components with the given type, recursively.
This is a shortcut forfindAll(type, _ -> true)- Parameters:
type- The type of components to search for- Returns:
- A modifiable list of components with the specified type
- Throws:
IllegalArgumentException- Ifnullis provided
-
findAll
@Nonnull default <T extends Component> List<T> findAll(@Nonnull Class<T> type, @Nonnull Predicate<? super T> filter) Finds all components with the given type and satisfying the filter, recursively.- Parameters:
type- The type of components to search forfilter- The component filter to apply- Returns:
- A modifiable list of components satisfying the type and filter
- Throws:
IllegalArgumentException- Ifnullis provided
-
find
@Nonnull default <T extends Component> Optional<T> find(@Nonnull Class<T> type, @Nonnull Predicate<? super T> filter) Finds the first component with the given type and satisfying the filter, recursively.- Parameters:
type- The type of components to search forfilter- The component filter to apply- Returns:
- An
Optionalpossibly containing a component satisfying the type and filter - Throws:
IllegalArgumentException- Ifnullis provided
-
replace
Replaces and/or removes components using the providedComponentReplacer, and construct a new tree from the result.- Parameters:
replacer- TheComponentReplacerto apply- Returns:
- A new tree with the new components
- Throws:
IllegalArgumentException- Ifnullis provided- See Also:
-
withDisabled
Enables or disables all components which can be enabled/disabled, and constructs a new tree from the result.- Returns:
- A new tree with all components enabled/disabled.
-
asDisabled
Disables all components which can be disabled, and constructs a new tree from the result.- Returns:
- A new tree with all components disabled.
-
asEnabled
Enables all components which can be enabled, and constructs a new tree from the result.- Returns:
- A new tree with all components enabled.
-