Ned Burns | 56a0ea1 | 2019-12-10 17:59:01 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui.log |
| 18 | |
| 19 | /** |
| 20 | * Recyclable implementation of [LogMessage]. |
| 21 | */ |
| 22 | data class LogMessageImpl( |
| 23 | override var level: LogLevel, |
| 24 | override var tag: String, |
| 25 | override var timestamp: Long, |
| 26 | override var printer: LogMessage.() -> String, |
| 27 | override var str1: String?, |
| 28 | override var str2: String?, |
| 29 | override var str3: String?, |
| 30 | override var int1: Int, |
| 31 | override var int2: Int, |
| 32 | override var long1: Long, |
Ned Burns | 30d6770 | 2020-01-28 12:58:45 -0500 | [diff] [blame] | 33 | override var long2: Long, |
| 34 | override var double1: Double, |
| 35 | override var bool1: Boolean, |
| 36 | override var bool2: Boolean, |
| 37 | override var bool3: Boolean, |
| 38 | override var bool4: Boolean |
Ned Burns | 56a0ea1 | 2019-12-10 17:59:01 -0500 | [diff] [blame] | 39 | ) : LogMessage { |
| 40 | |
| 41 | fun reset( |
| 42 | tag: String, |
| 43 | level: LogLevel, |
| 44 | timestamp: Long, |
| 45 | renderer: LogMessage.() -> String |
| 46 | ) { |
| 47 | this.level = level |
| 48 | this.tag = tag |
| 49 | this.timestamp = timestamp |
| 50 | this.printer = renderer |
| 51 | str1 = null |
| 52 | str2 = null |
| 53 | str3 = null |
| 54 | int1 = 0 |
| 55 | int2 = 0 |
| 56 | long1 = 0 |
Ned Burns | 30d6770 | 2020-01-28 12:58:45 -0500 | [diff] [blame] | 57 | long2 = 0 |
Ned Burns | 56a0ea1 | 2019-12-10 17:59:01 -0500 | [diff] [blame] | 58 | double1 = 0.0 |
Ned Burns | 30d6770 | 2020-01-28 12:58:45 -0500 | [diff] [blame] | 59 | bool1 = false |
| 60 | bool2 = false |
| 61 | bool3 = false |
| 62 | bool4 = false |
Ned Burns | 56a0ea1 | 2019-12-10 17:59:01 -0500 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | companion object Factory { |
| 66 | fun create(): LogMessageImpl { |
| 67 | return LogMessageImpl( |
| 68 | LogLevel.DEBUG, |
| 69 | DEFAULT_TAG, |
| 70 | 0, |
| 71 | DEFAULT_RENDERER, |
| 72 | null, |
| 73 | null, |
| 74 | null, |
| 75 | 0, |
| 76 | 0, |
| 77 | 0, |
Ned Burns | 30d6770 | 2020-01-28 12:58:45 -0500 | [diff] [blame] | 78 | 0, |
| 79 | 0.0, |
| 80 | false, |
| 81 | false, |
| 82 | false, |
| 83 | false) |
Ned Burns | 56a0ea1 | 2019-12-10 17:59:01 -0500 | [diff] [blame] | 84 | } |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | private const val DEFAULT_TAG = "UnknownTag" |
| 89 | private val DEFAULT_RENDERER: LogMessage.() -> String = { "Unknown message: $this" } |