kotlin lints

This commit is contained in:
Milos Kozak 2023-08-27 01:27:36 +02:00
parent c77fbcd473
commit f2e86ae63c
13 changed files with 53 additions and 83 deletions

View file

@ -13,7 +13,7 @@ class TokenizationTest {
// Trying to match it at those coordinates is expected to succeed, // Trying to match it at those coordinates is expected to succeed,
// while trying to match it slightly to the right should fail. // while trying to match it slightly to the right should fail.
val largeBasalGlyphPattern = glyphPatterns[Glyph.LargeSymbol(LargeSymbol.BASAL)]!! val largeBasalGlyphPattern = glyphPatterns.getValue(Glyph.LargeSymbol(LargeSymbol.BASAL))
val result1 = checkIfPatternMatchesAt( val result1 = checkIfPatternMatchesAt(
testFrameMainScreenWithTimeSeparator, testFrameMainScreenWithTimeSeparator,

View file

@ -614,21 +614,21 @@ class BigLogInquireResponsePacket(
var recordMap: MutableMap<String, Double> = mutableMapOf("dummy" to 0.0) var recordMap: MutableMap<String, Double> = mutableMapOf("dummy" to 0.0)
if (dailyMaxValInfo.containsKey(recordDateStr)) { if (dailyMaxValInfo.containsKey(recordDateStr)) {
recordMap = dailyMaxValInfo[recordDateStr]!! recordMap = dailyMaxValInfo.getValue(recordDateStr)
} else { } else {
recordMap["bolus"] = 0.0 recordMap["bolus"] = 0.0
recordMap["basal"] = 0.0 recordMap["basal"] = 0.0
dailyMaxValInfo[recordDateStr] = recordMap dailyMaxValInfo[recordDateStr] = recordMap
} }
if (diaconnG8HistoryRecord.dailyBolus > recordMap["bolus"]!!) { if (diaconnG8HistoryRecord.dailyBolus > recordMap.getValue("bolus")) {
recordMap["bolus"] = diaconnG8HistoryRecord.dailyBolus recordMap["bolus"] = diaconnG8HistoryRecord.dailyBolus
} else { } else {
diaconnG8HistoryRecord.dailyBolus = recordMap["bolus"]!! diaconnG8HistoryRecord.dailyBolus = recordMap.getValue("bolus")
} }
if (recordMap["basal"]!! > 0.0) { if (recordMap.getValue("basal") > 0.0) {
diaconnG8HistoryRecord.dailyBasal = recordMap["basal"]!! diaconnG8HistoryRecord.dailyBasal = recordMap.getValue("basal")
} }
diaconnG8HistoryRecord.lognum = logNum diaconnG8HistoryRecord.lognum = logNum
diaconnG8HistoryRecord.wrappingCount = wrappingCount diaconnG8HistoryRecord.wrappingCount = wrappingCount
@ -663,21 +663,21 @@ class BigLogInquireResponsePacket(
var recordMap: MutableMap<String, Double> = mutableMapOf("dummy" to 0.0) var recordMap: MutableMap<String, Double> = mutableMapOf("dummy" to 0.0)
if (dailyMaxValInfo.containsKey(recordDateStr)) { if (dailyMaxValInfo.containsKey(recordDateStr)) {
recordMap = dailyMaxValInfo[recordDateStr]!! recordMap = dailyMaxValInfo.getValue(recordDateStr)
} else { } else {
recordMap["bolus"] = 0.0 recordMap["bolus"] = 0.0
recordMap["basal"] = 0.0 recordMap["basal"] = 0.0
dailyMaxValInfo[recordDateStr] = recordMap dailyMaxValInfo[recordDateStr] = recordMap
} }
if (diaconnG8HistoryRecord.dailyBasal > recordMap["basal"]!!) { if (diaconnG8HistoryRecord.dailyBasal > recordMap.getValue("basal")) {
recordMap["basal"] = diaconnG8HistoryRecord.dailyBasal recordMap["basal"] = diaconnG8HistoryRecord.dailyBasal
} else { } else {
diaconnG8HistoryRecord.dailyBasal = recordMap["basal"]!! diaconnG8HistoryRecord.dailyBasal = recordMap.getValue("basal")
} }
if (recordMap["bolus"]!! > 0.0) { if (recordMap.getValue("bolus") > 0.0) {
diaconnG8HistoryRecord.dailyBolus = recordMap["bolus"]!! diaconnG8HistoryRecord.dailyBolus = recordMap.getValue("bolus")
} }
diaconnG8HistoryRecord.lognum = logNum diaconnG8HistoryRecord.lognum = logNum
diaconnG8HistoryRecord.wrappingCount = wrappingCount diaconnG8HistoryRecord.wrappingCount = wrappingCount

View file

@ -25,13 +25,13 @@ abstract class MedtronicHistoryEntry : MedtronicHistoryEntryInterface {
var id: Long = 0 var id: Long = 0
@Expose @Expose
var DT: String? = null var dt: String? = null
@Expose @Expose
var atechDateTime: Long = 0L var atechDateTime: Long = 0L
set(value) { set(value) {
field = value field = value
DT = DateTimeUtil.toString(value) dt = DateTimeUtil.toString(value)
if (isEntryTypeSet() && value != 0L) pumpId = generatePumpId() if (isEntryTypeSet() && value != 0L) pumpId = generatePumpId()
} }
@ -49,22 +49,6 @@ abstract class MedtronicHistoryEntry : MedtronicHistoryEntryInterface {
return field return field
} }
/**
* if history object is already linked to AAPS object (either Treatment, TempBasal or TDD (tdd's
* are not actually
* linked))
*/
var linked = false
/**
* Linked object, see linked
*/
var linkedObject: Any? = null
set(value) {
linked = true
field = value
}
abstract fun generatePumpId(): Long abstract fun generatePumpId(): Long
abstract fun isEntryTypeSet(): Boolean abstract fun isEntryTypeSet(): Boolean
@ -107,16 +91,16 @@ abstract class MedtronicHistoryEntry : MedtronicHistoryEntryInterface {
} }
val dateTimeString: String val dateTimeString: String
get() = if (DT == null) "Unknown" else DT!! get() = dt ?: "Unknown"
val decodedDataAsString: String val decodedDataAsString: String
get() = if (decodedData.size == 0) if (isNoDataEntry) "No data" else "" else decodedData.toString() get() = if (decodedData.isEmpty()) if (isNoDataEntry) "No data" else "" else decodedData.toString()
fun hasData(): Boolean { private fun hasData(): Boolean {
return decodedData.size == 0 || isNoDataEntry || entryTypeName == "UnabsorbedInsulin" return decodedData.isEmpty() || isNoDataEntry || entryTypeName == "UnabsorbedInsulin"
} }
val isNoDataEntry: Boolean private val isNoDataEntry: Boolean
get() = sizes[0] == 2 && sizes[1] == 5 && sizes[2] == 0 get() = sizes[0] == 2 && sizes[1] == 5 && sizes[2] == 0
fun getDecodedDataEntry(key: String?): Any? { fun getDecodedDataEntry(key: String?): Any? {
@ -127,17 +111,16 @@ abstract class MedtronicHistoryEntry : MedtronicHistoryEntryInterface {
return decodedData.containsKey(key) return decodedData.containsKey(key)
} }
fun showRaw(): Boolean { private fun showRaw(): Boolean =
return entryTypeName == "EndResultTotals" entryTypeName == "EndResultTotals"
}
val headLength: Int private val headLength: Int
get() = sizes[0] get() = sizes[0]
val dateTimeLength: Int val dateTimeLength: Int
get() = sizes[1] get() = sizes[1]
val bodyLength: Int private val bodyLength: Int
get() = sizes[2] get() = sizes[2]
abstract fun toEntryString(): String abstract fun toEntryString(): String
@ -148,7 +131,7 @@ abstract class MedtronicHistoryEntry : MedtronicHistoryEntryInterface {
// Log.e("", "DT is null. RawData=" + ByteUtil.getHex(rawData)) // Log.e("", "DT is null. RawData=" + ByteUtil.getHex(rawData))
// } // }
sb.append(toStringStart) sb.append(toStringStart)
sb.append(", DT: " + if (DT == null) "null" else StringUtil.getStringInLength(DT, 19)) sb.append(", DT: " + if (dt == null) "null" else StringUtil.getStringInLength(dt, 19))
sb.append(", length=") sb.append(", length=")
sb.append(headLength) sb.append(headLength)
sb.append(",") sb.append(",")
@ -171,11 +154,11 @@ abstract class MedtronicHistoryEntry : MedtronicHistoryEntryInterface {
sb.append(", head=") sb.append(", head=")
sb.append(ByteUtil.shortHexString(head)) sb.append(ByteUtil.shortHexString(head))
} }
if (datetime.size != 0) { if (datetime.isNotEmpty()) {
sb.append(", datetime=") sb.append(", datetime=")
sb.append(ByteUtil.shortHexString(datetime)) sb.append(ByteUtil.shortHexString(datetime))
} }
if (body.size != 0) { if (body.isNotEmpty()) {
sb.append(", body=") sb.append(", body=")
sb.append(ByteUtil.shortHexString(body)) sb.append(ByteUtil.shortHexString(body))
} }
@ -206,15 +189,7 @@ abstract class MedtronicHistoryEntry : MedtronicHistoryEntryInterface {
} }
fun addDecodedData(key: String, value: Any) { fun addDecodedData(key: String, value: Any) {
decodedData.put(key, value) decodedData[key] = value
}
fun toShortString(): String {
return if (head.size != 0) {
"Unidentified record. "
} else {
"HistoryRecord: head=[" + ByteUtil.shortHexString(head) + "]"
}
} }
fun containsDecodedData(key: String?): Boolean { fun containsDecodedData(key: String?): Boolean {

View file

@ -90,7 +90,7 @@ class PumpHistoryEntry : MedtronicHistoryEntry() {
// Log.e("", "DT is null. RawData=" + ByteUtil.getHex(rawData)) // Log.e("", "DT is null. RawData=" + ByteUtil.getHex(rawData))
// } // }
sb.append("PumpHistoryEntry [type=" + StringUtil.getStringInLength(entryType.name, 20)) sb.append("PumpHistoryEntry [type=" + StringUtil.getStringInLength(entryType.name, 20))
sb.append(" " + if (DT == null) "null" else StringUtil.getStringInLength(DT, 19)) sb.append(" " + if (dt == null) "null" else StringUtil.getStringInLength(dt, 19))
val hasData = (decodedData.size > 0) val hasData = (decodedData.size > 0)
if (hasData) { if (hasData) {

View file

@ -178,7 +178,7 @@ class MedtronicHistoryData @Inject constructor(
for (bolusEstimate in bolusEstimates) { for (bolusEstimate in bolusEstimates) {
for (bolus in boluses) { for (bolus in boluses) {
if (bolusEstimate.atechDateTime == bolus.atechDateTime) { if (bolusEstimate.atechDateTime == bolus.atechDateTime) {
bolus.addDecodedData("Estimate", bolusEstimate.decodedData["Object"]!!) bolus.addDecodedData("Estimate", bolusEstimate.decodedData.getValue("Object"))
} }
} }
} }
@ -1292,15 +1292,15 @@ class MedtronicHistoryData @Inject constructor(
private fun preProcessTBRs(tbrsInput: MutableList<PumpHistoryEntry>): MutableList<PumpHistoryEntry> { private fun preProcessTBRs(tbrsInput: MutableList<PumpHistoryEntry>): MutableList<PumpHistoryEntry> {
val tbrs: MutableList<PumpHistoryEntry> = mutableListOf() val tbrs: MutableList<PumpHistoryEntry> = mutableListOf()
val map: MutableMap<String?, PumpHistoryEntry?> = HashMap() val map: MutableMap<String, PumpHistoryEntry> = HashMap()
for (pumpHistoryEntry in tbrsInput) { for (pumpHistoryEntry in tbrsInput) {
if (map.containsKey(pumpHistoryEntry.DT)) { if (map.containsKey(pumpHistoryEntry.dt)) {
medtronicPumpHistoryDecoder.decodeTempBasal(map[pumpHistoryEntry.DT]!!, pumpHistoryEntry) medtronicPumpHistoryDecoder.decodeTempBasal(map.getValue(pumpHistoryEntry.dateTimeString), pumpHistoryEntry)
pumpHistoryEntry.setEntryType(medtronicUtil.medtronicPumpModel, PumpHistoryEntryType.TempBasalCombined) pumpHistoryEntry.setEntryType(medtronicUtil.medtronicPumpModel, PumpHistoryEntryType.TempBasalCombined)
tbrs.add(pumpHistoryEntry) tbrs.add(pumpHistoryEntry)
map.remove(pumpHistoryEntry.DT) map.remove(pumpHistoryEntry.dt)
} else { } else {
map[pumpHistoryEntry.DT] = pumpHistoryEntry map[pumpHistoryEntry.dateTimeString] = pumpHistoryEntry
} }
} }
return tbrs return tbrs

View file

@ -73,11 +73,11 @@ class TempBasalProcessDTO constructor(var itemOne: PumpHistoryEntry,
fun toTreatmentString(): String { fun toTreatmentString(): String {
val stringBuilder = StringBuilder() val stringBuilder = StringBuilder()
stringBuilder.append(itemOne.DT) stringBuilder.append(itemOne.dt)
if (itemTwo!=null) { if (itemTwo!=null) {
stringBuilder.append(" - ") stringBuilder.append(" - ")
stringBuilder.append(itemTwo?.DT) stringBuilder.append(itemTwo?.dt)
} }
stringBuilder.append(" " + durationAsSeconds + " s (" + durationAsSeconds/60 + ")") stringBuilder.append(" " + durationAsSeconds + " s (" + durationAsSeconds/60 + ")")

View file

@ -1,7 +1,5 @@
package info.nightscout.androidaps.plugins.pump.medtronic.defs package info.nightscout.androidaps.plugins.pump.medtronic.defs
import java.util.*
/** /**
* Taken from GNU Gluco Control diabetes management software (ggc.sourceforge.net) * Taken from GNU Gluco Control diabetes management software (ggc.sourceforge.net)
* *
@ -37,6 +35,7 @@ enum class MedtronicDeviceType {
All; All;
companion object { companion object {
var mapByDescription: MutableMap<String, MedtronicDeviceType> = mutableMapOf() var mapByDescription: MutableMap<String, MedtronicDeviceType> = mutableMapOf()
fun isSameDevice(deviceWeCheck: MedtronicDeviceType, deviceSources: MedtronicDeviceType): Boolean { fun isSameDevice(deviceWeCheck: MedtronicDeviceType, deviceSources: MedtronicDeviceType): Boolean {
@ -50,17 +49,12 @@ enum class MedtronicDeviceType {
return false return false
} }
fun getByDescription(desc: String): MedtronicDeviceType { fun getByDescription(desc: String): MedtronicDeviceType =
return if (mapByDescription.containsKey(desc)) { mapByDescription[desc] ?: Unknown_Device
mapByDescription[desc]!!
} else {
Unknown_Device
}
}
init { init {
for (minimedDeviceType in values()) { for (minimedDeviceType in values()) {
if (!minimedDeviceType.isFamily && minimedDeviceType.pumpModel!=null) { if (!minimedDeviceType.isFamily && minimedDeviceType.pumpModel != null) {
mapByDescription[minimedDeviceType.pumpModel!!] = minimedDeviceType mapByDescription[minimedDeviceType.pumpModel!!] = minimedDeviceType
} }
} }

View file

@ -93,13 +93,13 @@ open class TestBase {
val tbrs: MutableList<PumpHistoryEntry> = mutableListOf() val tbrs: MutableList<PumpHistoryEntry> = mutableListOf()
val map: MutableMap<String?, PumpHistoryEntry?> = HashMap() val map: MutableMap<String?, PumpHistoryEntry?> = HashMap()
for (pumpHistoryEntry in TBRs_Input) { for (pumpHistoryEntry in TBRs_Input) {
if (map.containsKey(pumpHistoryEntry.DT)) { if (map.containsKey(pumpHistoryEntry.dt)) {
decoder.decodeTempBasal(map[pumpHistoryEntry.DT]!!, pumpHistoryEntry) decoder.decodeTempBasal(map[pumpHistoryEntry.dt]!!, pumpHistoryEntry)
pumpHistoryEntry.setEntryType(medtronicUtil.medtronicPumpModel, PumpHistoryEntryType.TempBasalCombined) pumpHistoryEntry.setEntryType(medtronicUtil.medtronicPumpModel, PumpHistoryEntryType.TempBasalCombined)
tbrs.add(pumpHistoryEntry) tbrs.add(pumpHistoryEntry)
map.remove(pumpHistoryEntry.DT) map.remove(pumpHistoryEntry.dt)
} else { } else {
map[pumpHistoryEntry.DT] = pumpHistoryEntry map[pumpHistoryEntry.dt] = pumpHistoryEntry
} }
} }
return tbrs return tbrs

View file

@ -5,7 +5,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.message.
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.message.MessageType import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.message.MessageType
import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.message.StringLengthPrefixEncoding import info.nightscout.androidaps.plugins.pump.omnipod.dash.driver.comm.message.StringLengthPrefixEncoding
data class PairMessage( class PairMessage(
val sequenceNumber: Byte, val sequenceNumber: Byte,
val source: Id, val source: Id,
val destination: Id, val destination: Id,

View file

@ -101,7 +101,7 @@ class Connection(
val discovered = discoverer.discoverServices(connectionWaitCond) val discovered = discoverer.discoverServices(connectionWaitCond)
val cmdBleIO = CmdBleIO( val cmdBleIO = CmdBleIO(
aapsLogger, aapsLogger,
discovered[CharacteristicType.CMD]!!, discovered.getValue(CharacteristicType.CMD),
incomingPackets incomingPackets
.cmdQueue, .cmdQueue,
gatt, gatt,
@ -109,7 +109,7 @@ class Connection(
) )
val dataBleIO = DataBleIO( val dataBleIO = DataBleIO(
aapsLogger, aapsLogger,
discovered[CharacteristicType.DATA]!!, discovered.getValue(CharacteristicType.DATA),
incomingPackets incomingPackets
.dataQueue, .dataQueue,
gatt, gatt,

View file

@ -41,7 +41,7 @@ class Inevitable @Inject internal constructor() {
if (debug) { if (debug) {
aapsLogger.debug( aapsLogger.debug(
LTag.WEAR, LTag.WEAR,
"Creating task: " + id + " due: " + dateUtil.dateAndTimeAndSecondsString(tasks[id]!!.`when`) "Creating task: " + id + " due: " + dateUtil.dateAndTimeAndSecondsString(tasks.getValue(id).`when`)
) )
} }

View file

@ -44,7 +44,7 @@ open class WearUtil @Inject constructor(
// return true if below rate limit // return true if below rate limit
@Synchronized fun isBelowRateLimit(named: String, onceForSeconds: Int): Boolean { @Synchronized fun isBelowRateLimit(named: String, onceForSeconds: Int): Boolean {
// check if over limit // check if over limit
if (rateLimits.containsKey(named) && timestamp() - rateLimits[named]!! < onceForSeconds * 1000) { if (rateLimits.containsKey(named) && timestamp() - rateLimits.getValue(named) < onceForSeconds * 1000) {
aapsLogger.debug(LTag.WEAR, "$named rate limited to one for $onceForSeconds seconds") aapsLogger.debug(LTag.WEAR, "$named rate limited to one for $onceForSeconds seconds")
return false return false
} }

View file

@ -2,17 +2,18 @@ package info.nightscout.androidaps.watchfaces.utils
import android.graphics.DashPathEffect import android.graphics.DashPathEffect
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.shared.utils.DateUtil
import info.nightscout.shared.sharedPreferences.SP
import info.nightscout.rx.weardata.EventData import info.nightscout.rx.weardata.EventData
import info.nightscout.rx.weardata.EventData.SingleBg import info.nightscout.rx.weardata.EventData.SingleBg
import info.nightscout.rx.weardata.EventData.TreatmentData.Basal import info.nightscout.rx.weardata.EventData.TreatmentData.Basal
import info.nightscout.shared.sharedPreferences.SP
import info.nightscout.shared.utils.DateUtil
import lecho.lib.hellocharts.model.Axis import lecho.lib.hellocharts.model.Axis
import lecho.lib.hellocharts.model.AxisValue import lecho.lib.hellocharts.model.AxisValue
import lecho.lib.hellocharts.model.Line import lecho.lib.hellocharts.model.Line
import lecho.lib.hellocharts.model.LineChartData import lecho.lib.hellocharts.model.LineChartData
import lecho.lib.hellocharts.model.PointValue import lecho.lib.hellocharts.model.PointValue
import java.util.* import java.util.Calendar
import java.util.GregorianCalendar
import kotlin.math.abs import kotlin.math.abs
import kotlin.math.max import kotlin.math.max
import kotlin.math.min import kotlin.math.min
@ -203,7 +204,7 @@ class BgGraphBuilder(
if (!values.containsKey(color)) { if (!values.containsKey(color)) {
values[color] = ArrayList() values[color] = ArrayList()
} }
values[color]!!.add(PointValue(fuzz(timeStamp), value.toFloat())) values.getValue(color).add(PointValue(fuzz(timeStamp), value.toFloat()))
} }
} }
for ((key, value) in values) { for ((key, value) in values) {