Wesley Acheson
12/18/2019, 12:23 PMGROUP BY day, status which would give me a list with the same day more than once and the same status more than once which returned a list of
data class DayStatusCount(val day:LocalDate, val status:Status, val count:Long)
If I wanted to convert to a Map<LocalDate, Map<Status, Long>> or anythings similar to that. I've been creating mutable maps.
val rawData: MutableMap<LocalDate, Map<Status, Long> = HashMap()
data.forEach {
rawData
.getOrPut(it.day) { HashMap() }
.getOrPut(it.status) { HashMap() }
// More as per step
}
Sorry thats not the real code. but anyway convert from a list with duplicates to nested sets.Ubi
12/18/2019, 2:43 PMimport java.time.LocalDate
data class DayStatusCount(val day: LocalDate, val status: String, val count: Long)
val rawData: MutableMap<LocalDate, Map<String, Long>> = HashMap()
val data = listOf(
DayStatusCount(day = LocalDate.of(2001, 1, 1), status = "TODO", count = 1L),
DayStatusCount(day = LocalDate.of(2001, 1, 1), status = "IN_PROGRESS", count = 2L),
DayStatusCount(day = LocalDate.of(2001, 1, 2), status = "TODO", count = 1L),
DayStatusCount(day = LocalDate.of(2001, 1, 3), status = "TODO", count = 1L),
DayStatusCount(day = LocalDate.of(2001, 1, 4), status = "TODO", count = 1L)
)
val groupdData: Map<LocalDate, List<DayStatusCount>> = data.groupBy { it -> it.day }Ubi
12/18/2019, 2:43 PMdata? Like the above example?Wesley Acheson
12/18/2019, 3:02 PMWesley Acheson
12/18/2019, 3:04 PMmutableMapOf() rather than HashMap() Also I like the array syntax you use. which I'm still getting my head around. Not array exactly more like associative array.Wesley Acheson
12/18/2019, 3:08 PMWesley Acheson
12/18/2019, 3:08 PMWesley Acheson
12/18/2019, 3:09 PMWesley Acheson
12/18/2019, 3:11 PMUbi
12/18/2019, 4:31 PMval mapped: Map<LocalDate, Map<String, Long>> = data.groupBy { it.day }
.mapValues { (_, value) -> value.map { it.status to it.count } }
.mapValues { (_, values) -> values.toMap() }Wesley Acheson
12/18/2019, 4:32 PMUbi
12/18/2019, 4:32 PM