Ich lerne verstehen den Beispielcode über "Kotlin für Android-Entwickler" bei https://github.com/antoniolg/Kotlin-for-Android-DevelopersWas wird HashMap (it) tun?
Im Code .parseList { DayForecast(HashMap(it)) }
, kann ich nicht, was die Funktion HashMap (es) tun. Ist HashMap() eine Klasse und akzeptieren Sie einen Parameter it
?
Und mehr, ich denke, dass der vollständige Code der Klasse DayForecast(...)..
Code A ist, richtig?
Noch einmal, wenn ich ein Objekt var myDayForecast=DayForecast(10L,"Desciption",10,5,"http://www.a.com",10L)
erstellen, wird myDayForecast.map leer sein, oder?
Code A
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
}
}
Originalcode
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
}
}