내가 코드 .parseList { DayForecast(HashMap(it)) }
에서 https://github.com/antoniolg/Kotlin-for-Android-DevelopersHashMap (할)은 무엇을 할 것인가?
에서 "안드로이드 개발자를위한 코 틀린"에 대한 샘플 코드를 배우고, 나는 함수의 HashMap이 (가) 무엇을 할 것인지 이해할 수 없습니다. HashMap()이 클래스이고 parmater를 수락합니다 it
?
그리고 더 자세히, 나는 DayForecast(...)..
클래스의 전체 코드가 코드 A라고 생각합니까?
다시 말해서 객체 var myDayForecast=DayForecast(10L,"Desciption",10,5,"http://www.a.com",10L)
을 만들면 myDayForecast.map가 비어있게됩니까?
코드
class DayForecast(var map: MutableMap<String, Any?>) {
var _id: Long by map
var date: Long by map
var description: String by map
var high: Int by map
var low: Int by map
var iconUrl: String by map
var cityId: Long by map
constructor(date: Long, description: String, high: Int, low: Int, iconUrl: String, cityId: Long)
: this(map: MutableMap<String, Any?>=HashMap()) {
this.date = date
this.description = description
this.high = high
this.low = low
this.iconUrl = iconUrl
this.cityId = cityId
}
}
원본 코드
override fun requestForecastByZipCode(zipCode: Long, date: Long) = forecastDbHelper.use {
val dailyRequest = "${DayForecastTable.CITY_ID} = ? AND ${DayForecastTable.DATE} >= ?"
val dailyForecast = select(DayForecastTable.NAME)
.whereSimple(dailyRequest, zipCode.toString(), date.toString())
.parseList { DayForecast(HashMap(it)) }
val city = select(CityForecastTable.NAME)
.whereSimple("${CityForecastTable.ID} = ?", zipCode.toString())
.parseOpt { CityForecast(HashMap(it), dailyForecast) }
city?.let { dataMapper.convertToDomain(it) }
}
class DayForecast(var map: MutableMap<String, Any?>) {
var _id: Long by map
var date: Long by map
var description: String by map
var high: Int by map
var low: Int by map
var iconUrl: String by map
var cityId: Long by map
constructor(date: Long, description: String, high: Int, low: Int, iconUrl: String, cityId: Long)
: this(HashMap()) {
this.date = date
this.description = description
this.high = high
this.low = low
this.iconUrl = iconUrl
this.cityId = cityId
}
}