Skip to content

Commit

Permalink
Add missing methods to get the actual component in HighLevelComponent…
Browse files Browse the repository at this point in the history
… and LowLevelComponent
  • Loading branch information
felldo committed Aug 15, 2021
1 parent 0c43d7e commit 8db0baf
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
@@ -1,4 +1,26 @@
package org.javacord.api.entity.message.component;

public interface HighLevelComponent extends Component {
import org.javacord.api.util.Specializable;
import java.util.Optional;

public interface HighLevelComponent extends Component, Specializable<HighLevelComponent> {

/**
* Whether this component is of this type.
*
* @return True if it's of that type.
*/
default boolean isActionRow() {
return getType() == ComponentType.ACTION_ROW;
}

/**
* Gets the component as an ActionRow if it's of that type.
*
* @return The ActionRow.
*/
default Optional<ActionRow> asActionRow() {
return isActionRow() ? Optional.of((ActionRow) this) : Optional.empty();
}

}
@@ -1,4 +1,44 @@
package org.javacord.api.entity.message.component;

public interface LowLevelComponent extends Component {
import org.javacord.api.util.Specializable;
import java.util.Optional;

public interface LowLevelComponent extends Component, Specializable<LowLevelComponent> {

/**
* Whether this component is of this type.
*
* @return True if it's of that type.
*/
default boolean isButton() {
return getType() == ComponentType.BUTTON;
}

/**
* Gets the component as a Button if it's of that type.
*
* @return The Button.
*/
default Optional<Button> asButton() {
return isButton() ? Optional.of((Button) this) : Optional.empty();
}

/**
* Whether this component is of this type.
*
* @return True if it's of that type.
*/
default boolean isSelectMenu() {
return getType() == ComponentType.SELECT_MENU;
}

/**
* Gets the component as a SelectMenu if it's of that type.
*
* @return The SelectMenu.
*/
default Optional<SelectMenu> asSelectMenu() {
return isSelectMenu() ? Optional.of((SelectMenu) this) : Optional.empty();
}

}

0 comments on commit 8db0baf

Please sign in to comment.