althaf
08/13/2021, 1:19 PMenum class Role(val letter: Char) {
APPROVER('U'),
ADMIN('D'),
INQUIRER('R'),
OPERATOR('O');
}
we have create this enum for code readability and we don't have direct control over how server is returning constants for the user roles, so they have done it this way 'U' , R etc
apiRespose.role = "U"
Role.valueOf(apiResponse.role) will not work ,as it is expecting 'APPROVER' as input . How can i achieve same benefit of Role.valueOf( ) wrt ot the 'letter' attribute in the enumArslan Armanuly
08/13/2021, 1:29 PMRole.values().first { it.letter == 'U' }
hho
08/13/2021, 1:31 PMArslan Armanuly
08/13/2021, 1:34 PMalthaf
08/13/2021, 1:44 PMephemient
08/13/2021, 2:43 PMval rolesByLetter: Map<Char, Role> = Role.values().associateBy { it.letter }
rolesByLetter['U']
would save you from repeated linear scanBruno Medeiros
08/14/2021, 5:42 AMit.letter
, isn't it?