Interface ComponentTree<E extends Component>
- Type Parameters:
E
- Type of components contained by this tree
- All Known Subinterfaces:
MessageComponentTree
,ModalComponentTree
- All Known Implementing Classes:
AbstractComponentTree
,ComponentTreeImpl
,MessageComponentTreeImpl
,ModalComponentTreeImpl
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 enum
Represents 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 MessageComponentTree
forMessage
(Collection<? extends MessageTopLevelComponent> components) Creates aMessageComponentTree
from the given top-level message components.static ModalComponentTree
forModal
(Collection<? extends ModalTopLevelComponent> components) Creates aModalComponentTree
from 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 aComponentTree
from the given components, and checks their compatibility.static ComponentTree
<IComponentUnion> of
(Collection<? extends Component> components) Creates aComponentTree
from 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 aComponentTree
from 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
ComponentTree
containing the given components - Throws:
IllegalArgumentException
- Ifnull
is 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 aComponentTree
from the given components.- Parameters:
components
- List of components to construct the tree from- Returns:
- A
ComponentTree
containing the given components - Throws:
IllegalArgumentException
- Ifnull
is provided
-
forMessage
@Nonnull static MessageComponentTree forMessage(@Nonnull Collection<? extends MessageTopLevelComponent> components) Creates aMessageComponentTree
from 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
MessageComponentTree
containing the given components - Throws:
IllegalArgumentException
- Ifnull
is provided
-
forModal
@Nonnull static ModalComponentTree forModal(@Nonnull Collection<? extends ModalTopLevelComponent> components) Creates aModalComponentTree
from 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
ModalComponentTree
containing the given components - Throws:
IllegalArgumentException
- Ifnull
is 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
- Ifnull
is 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
- Ifnull
is 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
Optional
possibly containing a component satisfying the type and filter - Throws:
IllegalArgumentException
- Ifnull
is provided
-
replace
Replaces and/or removes components using the providedComponentReplacer
, and construct a new tree from the result.- Parameters:
replacer
- TheComponentReplacer
to apply- Returns:
- A new tree with the new components
- Throws:
IllegalArgumentException
- Ifnull
is 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.
-