From f2e86ae63c06f6a92eb55c4ea413c23054653ef0 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Sun, 27 Aug 2023 01:27:36 +0200 Subject: [PATCH] kotlin lints --- .../comboctl/parser/TokenizationTest.kt | 2 +- .../packet/BigLogInquireResponsePacket.kt | 20 +++---- .../comm/history/MedtronicHistoryEntry.kt | 55 +++++-------------- .../comm/history/pump/PumpHistoryEntry.kt | 2 +- .../medtronic/data/MedtronicHistoryData.kt | 12 ++-- .../medtronic/data/dto/TempBasalProcessDTO.kt | 4 +- .../medtronic/defs/MedtronicDeviceType.kt | 14 ++--- .../info/nightscout/androidaps/TestBase.kt | 8 +-- .../dash/driver/comm/pair/PairMessage.kt | 2 +- .../dash/driver/comm/session/Connection.kt | 4 +- .../interaction/utils/Inevitable.kt | 2 +- .../androidaps/interaction/utils/WearUtil.kt | 2 +- .../watchfaces/utils/BgGraphBuilder.kt | 9 +-- 13 files changed, 53 insertions(+), 83 deletions(-) diff --git a/pump/combov2/comboctl/src/jvmTest/kotlin/info/nightscout/comboctl/parser/TokenizationTest.kt b/pump/combov2/comboctl/src/jvmTest/kotlin/info/nightscout/comboctl/parser/TokenizationTest.kt index 964bb2c8f8..1fe386336a 100644 --- a/pump/combov2/comboctl/src/jvmTest/kotlin/info/nightscout/comboctl/parser/TokenizationTest.kt +++ b/pump/combov2/comboctl/src/jvmTest/kotlin/info/nightscout/comboctl/parser/TokenizationTest.kt @@ -13,7 +13,7 @@ class TokenizationTest { // Trying to match it at those coordinates is expected to succeed, // 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( testFrameMainScreenWithTimeSeparator, diff --git a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/packet/BigLogInquireResponsePacket.kt b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/packet/BigLogInquireResponsePacket.kt index 23c00cf689..1b90a78e9d 100644 --- a/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/packet/BigLogInquireResponsePacket.kt +++ b/pump/diaconn/src/main/java/info/nightscout/pump/diaconn/packet/BigLogInquireResponsePacket.kt @@ -614,21 +614,21 @@ class BigLogInquireResponsePacket( var recordMap: MutableMap = mutableMapOf("dummy" to 0.0) if (dailyMaxValInfo.containsKey(recordDateStr)) { - recordMap = dailyMaxValInfo[recordDateStr]!! + recordMap = dailyMaxValInfo.getValue(recordDateStr) } else { recordMap["bolus"] = 0.0 recordMap["basal"] = 0.0 dailyMaxValInfo[recordDateStr] = recordMap } - if (diaconnG8HistoryRecord.dailyBolus > recordMap["bolus"]!!) { + if (diaconnG8HistoryRecord.dailyBolus > recordMap.getValue("bolus")) { recordMap["bolus"] = diaconnG8HistoryRecord.dailyBolus } else { - diaconnG8HistoryRecord.dailyBolus = recordMap["bolus"]!! + diaconnG8HistoryRecord.dailyBolus = recordMap.getValue("bolus") } - if (recordMap["basal"]!! > 0.0) { - diaconnG8HistoryRecord.dailyBasal = recordMap["basal"]!! + if (recordMap.getValue("basal") > 0.0) { + diaconnG8HistoryRecord.dailyBasal = recordMap.getValue("basal") } diaconnG8HistoryRecord.lognum = logNum diaconnG8HistoryRecord.wrappingCount = wrappingCount @@ -663,21 +663,21 @@ class BigLogInquireResponsePacket( var recordMap: MutableMap = mutableMapOf("dummy" to 0.0) if (dailyMaxValInfo.containsKey(recordDateStr)) { - recordMap = dailyMaxValInfo[recordDateStr]!! + recordMap = dailyMaxValInfo.getValue(recordDateStr) } else { recordMap["bolus"] = 0.0 recordMap["basal"] = 0.0 dailyMaxValInfo[recordDateStr] = recordMap } - if (diaconnG8HistoryRecord.dailyBasal > recordMap["basal"]!!) { + if (diaconnG8HistoryRecord.dailyBasal > recordMap.getValue("basal")) { recordMap["basal"] = diaconnG8HistoryRecord.dailyBasal } else { - diaconnG8HistoryRecord.dailyBasal = recordMap["basal"]!! + diaconnG8HistoryRecord.dailyBasal = recordMap.getValue("basal") } - if (recordMap["bolus"]!! > 0.0) { - diaconnG8HistoryRecord.dailyBolus = recordMap["bolus"]!! + if (recordMap.getValue("bolus") > 0.0) { + diaconnG8HistoryRecord.dailyBolus = recordMap.getValue("bolus") } diaconnG8HistoryRecord.lognum = logNum diaconnG8HistoryRecord.wrappingCount = wrappingCount diff --git a/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/MedtronicHistoryEntry.kt b/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/MedtronicHistoryEntry.kt index 2c6fe83dc3..4e126516f0 100644 --- a/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/MedtronicHistoryEntry.kt +++ b/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/MedtronicHistoryEntry.kt @@ -25,13 +25,13 @@ abstract class MedtronicHistoryEntry : MedtronicHistoryEntryInterface { var id: Long = 0 @Expose - var DT: String? = null + var dt: String? = null @Expose var atechDateTime: Long = 0L set(value) { field = value - DT = DateTimeUtil.toString(value) + dt = DateTimeUtil.toString(value) if (isEntryTypeSet() && value != 0L) pumpId = generatePumpId() } @@ -49,22 +49,6 @@ abstract class MedtronicHistoryEntry : MedtronicHistoryEntryInterface { 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 isEntryTypeSet(): Boolean @@ -107,16 +91,16 @@ abstract class MedtronicHistoryEntry : MedtronicHistoryEntryInterface { } val dateTimeString: String - get() = if (DT == null) "Unknown" else DT!! + get() = dt ?: "Unknown" 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 { - return decodedData.size == 0 || isNoDataEntry || entryTypeName == "UnabsorbedInsulin" + private fun hasData(): Boolean { + return decodedData.isEmpty() || isNoDataEntry || entryTypeName == "UnabsorbedInsulin" } - val isNoDataEntry: Boolean + private val isNoDataEntry: Boolean get() = sizes[0] == 2 && sizes[1] == 5 && sizes[2] == 0 fun getDecodedDataEntry(key: String?): Any? { @@ -127,17 +111,16 @@ abstract class MedtronicHistoryEntry : MedtronicHistoryEntryInterface { return decodedData.containsKey(key) } - fun showRaw(): Boolean { - return entryTypeName == "EndResultTotals" - } + private fun showRaw(): Boolean = + entryTypeName == "EndResultTotals" - val headLength: Int + private val headLength: Int get() = sizes[0] val dateTimeLength: Int get() = sizes[1] - val bodyLength: Int + private val bodyLength: Int get() = sizes[2] abstract fun toEntryString(): String @@ -148,7 +131,7 @@ abstract class MedtronicHistoryEntry : MedtronicHistoryEntryInterface { // Log.e("", "DT is null. RawData=" + ByteUtil.getHex(rawData)) // } 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(headLength) sb.append(",") @@ -171,11 +154,11 @@ abstract class MedtronicHistoryEntry : MedtronicHistoryEntryInterface { sb.append(", head=") sb.append(ByteUtil.shortHexString(head)) } - if (datetime.size != 0) { + if (datetime.isNotEmpty()) { sb.append(", datetime=") sb.append(ByteUtil.shortHexString(datetime)) } - if (body.size != 0) { + if (body.isNotEmpty()) { sb.append(", body=") sb.append(ByteUtil.shortHexString(body)) } @@ -206,15 +189,7 @@ abstract class MedtronicHistoryEntry : MedtronicHistoryEntryInterface { } fun addDecodedData(key: String, value: Any) { - decodedData.put(key, value) - } - - fun toShortString(): String { - return if (head.size != 0) { - "Unidentified record. " - } else { - "HistoryRecord: head=[" + ByteUtil.shortHexString(head) + "]" - } + decodedData[key] = value } fun containsDecodedData(key: String?): Boolean { diff --git a/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/PumpHistoryEntry.kt b/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/PumpHistoryEntry.kt index 777745b9d9..6b9dced5e7 100644 --- a/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/PumpHistoryEntry.kt +++ b/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/PumpHistoryEntry.kt @@ -90,7 +90,7 @@ class PumpHistoryEntry : MedtronicHistoryEntry() { // Log.e("", "DT is null. RawData=" + ByteUtil.getHex(rawData)) // } 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) if (hasData) { diff --git a/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.kt b/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.kt index d2bf1a3705..1e6590f97d 100644 --- a/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.kt +++ b/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/MedtronicHistoryData.kt @@ -178,7 +178,7 @@ class MedtronicHistoryData @Inject constructor( for (bolusEstimate in bolusEstimates) { for (bolus in boluses) { 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): MutableList { val tbrs: MutableList = mutableListOf() - val map: MutableMap = HashMap() + val map: MutableMap = HashMap() for (pumpHistoryEntry in tbrsInput) { - if (map.containsKey(pumpHistoryEntry.DT)) { - medtronicPumpHistoryDecoder.decodeTempBasal(map[pumpHistoryEntry.DT]!!, pumpHistoryEntry) + if (map.containsKey(pumpHistoryEntry.dt)) { + medtronicPumpHistoryDecoder.decodeTempBasal(map.getValue(pumpHistoryEntry.dateTimeString), pumpHistoryEntry) pumpHistoryEntry.setEntryType(medtronicUtil.medtronicPumpModel, PumpHistoryEntryType.TempBasalCombined) tbrs.add(pumpHistoryEntry) - map.remove(pumpHistoryEntry.DT) + map.remove(pumpHistoryEntry.dt) } else { - map[pumpHistoryEntry.DT] = pumpHistoryEntry + map[pumpHistoryEntry.dateTimeString] = pumpHistoryEntry } } return tbrs diff --git a/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/TempBasalProcessDTO.kt b/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/TempBasalProcessDTO.kt index 2cc57b4317..7d0d299fbf 100644 --- a/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/TempBasalProcessDTO.kt +++ b/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/data/dto/TempBasalProcessDTO.kt @@ -73,11 +73,11 @@ class TempBasalProcessDTO constructor(var itemOne: PumpHistoryEntry, fun toTreatmentString(): String { val stringBuilder = StringBuilder() - stringBuilder.append(itemOne.DT) + stringBuilder.append(itemOne.dt) if (itemTwo!=null) { stringBuilder.append(" - ") - stringBuilder.append(itemTwo?.DT) + stringBuilder.append(itemTwo?.dt) } stringBuilder.append(" " + durationAsSeconds + " s (" + durationAsSeconds/60 + ")") diff --git a/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/defs/MedtronicDeviceType.kt b/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/defs/MedtronicDeviceType.kt index ebf1c0e7c6..de2fc1d670 100644 --- a/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/defs/MedtronicDeviceType.kt +++ b/pump/medtronic/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/defs/MedtronicDeviceType.kt @@ -1,7 +1,5 @@ package info.nightscout.androidaps.plugins.pump.medtronic.defs -import java.util.* - /** * Taken from GNU Gluco Control diabetes management software (ggc.sourceforge.net) * @@ -37,6 +35,7 @@ enum class MedtronicDeviceType { All; companion object { + var mapByDescription: MutableMap = mutableMapOf() fun isSameDevice(deviceWeCheck: MedtronicDeviceType, deviceSources: MedtronicDeviceType): Boolean { @@ -50,17 +49,12 @@ enum class MedtronicDeviceType { return false } - fun getByDescription(desc: String): MedtronicDeviceType { - return if (mapByDescription.containsKey(desc)) { - mapByDescription[desc]!! - } else { - Unknown_Device - } - } + fun getByDescription(desc: String): MedtronicDeviceType = + mapByDescription[desc] ?: Unknown_Device init { for (minimedDeviceType in values()) { - if (!minimedDeviceType.isFamily && minimedDeviceType.pumpModel!=null) { + if (!minimedDeviceType.isFamily && minimedDeviceType.pumpModel != null) { mapByDescription[minimedDeviceType.pumpModel!!] = minimedDeviceType } } diff --git a/pump/medtronic/src/test/java/info/nightscout/androidaps/TestBase.kt b/pump/medtronic/src/test/java/info/nightscout/androidaps/TestBase.kt index b35c97800c..bb21dda1bf 100644 --- a/pump/medtronic/src/test/java/info/nightscout/androidaps/TestBase.kt +++ b/pump/medtronic/src/test/java/info/nightscout/androidaps/TestBase.kt @@ -93,13 +93,13 @@ open class TestBase { val tbrs: MutableList = mutableListOf() val map: MutableMap = HashMap() for (pumpHistoryEntry in TBRs_Input) { - if (map.containsKey(pumpHistoryEntry.DT)) { - decoder.decodeTempBasal(map[pumpHistoryEntry.DT]!!, pumpHistoryEntry) + if (map.containsKey(pumpHistoryEntry.dt)) { + decoder.decodeTempBasal(map[pumpHistoryEntry.dt]!!, pumpHistoryEntry) pumpHistoryEntry.setEntryType(medtronicUtil.medtronicPumpModel, PumpHistoryEntryType.TempBasalCombined) tbrs.add(pumpHistoryEntry) - map.remove(pumpHistoryEntry.DT) + map.remove(pumpHistoryEntry.dt) } else { - map[pumpHistoryEntry.DT] = pumpHistoryEntry + map[pumpHistoryEntry.dt] = pumpHistoryEntry } } return tbrs diff --git a/pump/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/pair/PairMessage.kt b/pump/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/pair/PairMessage.kt index 864cd2777a..e7f3020fda 100644 --- a/pump/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/pair/PairMessage.kt +++ b/pump/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/pair/PairMessage.kt @@ -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.StringLengthPrefixEncoding -data class PairMessage( +class PairMessage( val sequenceNumber: Byte, val source: Id, val destination: Id, diff --git a/pump/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/Connection.kt b/pump/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/Connection.kt index e56d717041..9116b72c87 100644 --- a/pump/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/Connection.kt +++ b/pump/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/session/Connection.kt @@ -101,7 +101,7 @@ class Connection( val discovered = discoverer.discoverServices(connectionWaitCond) val cmdBleIO = CmdBleIO( aapsLogger, - discovered[CharacteristicType.CMD]!!, + discovered.getValue(CharacteristicType.CMD), incomingPackets .cmdQueue, gatt, @@ -109,7 +109,7 @@ class Connection( ) val dataBleIO = DataBleIO( aapsLogger, - discovered[CharacteristicType.DATA]!!, + discovered.getValue(CharacteristicType.DATA), incomingPackets .dataQueue, gatt, diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/Inevitable.kt b/wear/src/main/java/info/nightscout/androidaps/interaction/utils/Inevitable.kt index 09659036aa..0c4563ae53 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/Inevitable.kt +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/utils/Inevitable.kt @@ -41,7 +41,7 @@ class Inevitable @Inject internal constructor() { if (debug) { aapsLogger.debug( LTag.WEAR, - "Creating task: " + id + " due: " + dateUtil.dateAndTimeAndSecondsString(tasks[id]!!.`when`) + "Creating task: " + id + " due: " + dateUtil.dateAndTimeAndSecondsString(tasks.getValue(id).`when`) ) } diff --git a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/WearUtil.kt b/wear/src/main/java/info/nightscout/androidaps/interaction/utils/WearUtil.kt index 927ed6bcdc..b703e1e5b2 100644 --- a/wear/src/main/java/info/nightscout/androidaps/interaction/utils/WearUtil.kt +++ b/wear/src/main/java/info/nightscout/androidaps/interaction/utils/WearUtil.kt @@ -44,7 +44,7 @@ open class WearUtil @Inject constructor( // return true if below rate limit @Synchronized fun isBelowRateLimit(named: String, onceForSeconds: Int): Boolean { // 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") return false } diff --git a/wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/BgGraphBuilder.kt b/wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/BgGraphBuilder.kt index 24e8ac5c38..7f4f799dc9 100644 --- a/wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/BgGraphBuilder.kt +++ b/wear/src/main/java/info/nightscout/androidaps/watchfaces/utils/BgGraphBuilder.kt @@ -2,17 +2,18 @@ package info.nightscout.androidaps.watchfaces.utils import android.graphics.DashPathEffect 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.SingleBg 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.AxisValue import lecho.lib.hellocharts.model.Line import lecho.lib.hellocharts.model.LineChartData import lecho.lib.hellocharts.model.PointValue -import java.util.* +import java.util.Calendar +import java.util.GregorianCalendar import kotlin.math.abs import kotlin.math.max import kotlin.math.min @@ -203,7 +204,7 @@ class BgGraphBuilder( if (!values.containsKey(color)) { 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) {