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.

  • Method Details

    • of

      @Nonnull static <E extends Component, T extends IComponentUnion> ComponentTree<T> of(@Nonnull Class<T> unionType, @Nonnull Collection<E> components)
      Creates a ComponentTree from the given components, and checks their compatibility.
      Parameters:
      unionType - The union type expected from the components
      components - List of components to construct the tree from
      Returns:
      A ComponentTree containing the given components
      Throws:
      IllegalArgumentException - If null 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 a ComponentTree from the given components.
      Parameters:
      components - List of components to construct the tree from
      Returns:
      A ComponentTree containing the given components
      Throws:
      IllegalArgumentException - If null is provided
    • forMessage

      @Nonnull static MessageComponentTree forMessage(@Nonnull Collection<? extends MessageTopLevelComponent> components)
      Creates a MessageComponentTree from the given top-level message components.
      This is a shortcut for MessageComponentTree.of(components).
      Parameters:
      components - List of components to construct the tree from
      Returns:
      A MessageComponentTree containing the given components
      Throws:
      IllegalArgumentException - If null is provided
    • forModal

      @Nonnull static ModalComponentTree forModal(@Nonnull Collection<? extends ModalTopLevelComponent> components)
      Creates a ModalComponentTree from the given top-level message components.
      This is a shortcut for ModalComponentTree.of(components).
      Parameters:
      components - List of components to construct the tree from
      Returns:
      A ModalComponentTree containing the given components
      Throws:
      IllegalArgumentException - If null is provided
    • getType

      @Nonnull ComponentTree.Type getType()
      Returns the type of this component tree.
      Returns:
      The type of this component tree
    • getComponents

      @Nonnull @Unmodifiable List<E> getComponents()
      Unmodifiable list of components contained by this tree.
      Returns:
      An unmodifiable list of components in this tree
    • findAll

      @Nonnull default <T extends Component> List<T> findAll(@Nonnull Class<T> type)
      Finds all components with the given type, recursively.
      This is a shortcut for findAll(type, _ -> true)
      Parameters:
      type - The type of components to search for
      Returns:
      A modifiable list of components with the specified type
      Throws:
      IllegalArgumentException - If null 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 for
      filter - The component filter to apply
      Returns:
      A modifiable list of components satisfying the type and filter
      Throws:
      IllegalArgumentException - If null 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 for
      filter - The component filter to apply
      Returns:
      An Optional possibly containing a component satisfying the type and filter
      Throws:
      IllegalArgumentException - If null is provided
    • replace

      @Nonnull @CheckReturnValue ComponentTree<E> replace(@Nonnull ComponentReplacer replacer)
      Replaces and/or removes components using the provided ComponentReplacer, and construct a new tree from the result.
      Parameters:
      replacer - The ComponentReplacer to apply
      Returns:
      A new tree with the new components
      Throws:
      IllegalArgumentException - If null is provided
      See Also:
    • withDisabled

      @Nonnull @CheckReturnValue ComponentTree<E> withDisabled(boolean disabled)
      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

      @Nonnull @CheckReturnValue default ComponentTree<E> 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

      @Nonnull @CheckReturnValue default ComponentTree<E> asEnabled()
      Enables all components which can be enabled, and constructs a new tree from the result.
      Returns:
      A new tree with all components enabled.