I have an enum class which maps language locale to a list.
How can I fix the function getReservationFrequencies inside the companion object to return the value of the map based on the locale (key)?
enum class ReservationFrequencies(val frequencies: Map<Language, List<ReservationFrequency>>) {
APPLICATION(mapOf(
Language.en to listOf(
ReservationFrequency(0,"once",0),
ReservationFrequency(1,"Monthly",2),
ReservationFrequency(2,"Quarterly",5),
ReservationFrequency(3,"Semi-annually",5),
ReservationFrequency(4,"Annually",5)
),
Language.ar to listOf(
ReservationFrequency(0,"مرة واحده",0),
ReservationFrequency(1,"شهرياً",2),
ReservationFrequency(2,"ربع سنوياً",5),
ReservationFrequency(3,"نصف سنوياً",5),
ReservationFrequency(4," سنوياً",5)
)
));
}
I tried creating a companion object that includes a function that returns the list
companion object {
fun getReservationFrequencies(locale: String?) : List<ReservationFrequency> {
val reservationFrequencyDtos = mutableListOf<ReservationFrequency>()
reservationFrequencies.values()
.filter { locale!!.contains(it.name)}
.forEach() {
ReservationFrequency.add(ReservationFrequency(code = it.frequencies))
}
}
}
I'm expecting a List<ReservationFrequency>
based on the locale