Skip to content

Commit

Permalink
Add getCurrentState() and getCurrentStateIndex()
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmigloz committed Mar 15, 2022
1 parent 9d19499 commit 9093ead
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,17 @@ class MultiStateSwitch @JvmOverloads constructor(
*/
fun getNumberStates(): Int = states.size

/**
* Returns current state.
* Note: the states should be populated already, otherwise an exception will be thrown.
*/
fun getCurrentState(): State = states.getOrNull(currentStateIndex) ?: error("No current state")

/**
* Returns the index of the current state.
*/
fun getCurrentStateIndex(): Int = currentStateIndex

/**
* Sets the max number of states. If you try to add a new state but the number of states is
* already maxNumberStates the state will be ignored. By default is -1 which means that there
Expand Down

0 comments on commit 9093ead

Please sign in to comment.