https://kotlinlang.org logo
Title
o

oday

08/11/2022, 2:56 PM
how can I express,
if the values in this list are valid values in my enum
? I am doing this
if (queryParams.containsAll(GiveConsent.ConsentType.values())){
but i get this error that it expects a collection and I gave it an Array
j

Joffrey

08/11/2022, 3:00 PM
Even if the code you wrote compiled, it doesn't express what you seem to be wanting in your description. Do you want to check if all values in the list are valid values from this enum, or do you want to check if all values of the enum appear in the list?
I would say you probably want:
val validEnumValues = GiveConsent.ConsentType.values().map { it.name }.toSet()
if (queryParams.all { it in validEnumValues }) {
    ...
}
(If your
queryParams
values are strings)
You could also ignore the case depending on your needs (for instance by lowercasing the values in the set, and then lowercasing the params in the
all
)
o

oday

08/11/2022, 3:22 PM
that’s nice actually
make them a set, and then check for whether all items in the list are in the set
thanks Joffrey!