Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add missing methods to get the actual component in HighLevelComponent…
… and LowLevelComponent
- Loading branch information
Showing
2 changed files
with
64 additions
and
2 deletions.
There are no files selected for viewing
24 changes: 23 additions & 1 deletion
24
javacord-api/src/main/java/org/javacord/api/entity/message/component/HighLevelComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
|
||
} |
42 changes: 41 additions & 1 deletion
42
javacord-api/src/main/java/org/javacord/api/entity/message/component/LowLevelComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
|
||
} |