From bdde72c79fbd75f30b63db73e7c52b1dbc697398 Mon Sep 17 00:00:00 2001 From: tangcent Date: Tue, 26 Nov 2019 13:04:17 +0800 Subject: [PATCH] opti: `addComment` will not cover old comment --- .../com/itangcent/common/utils/KVUtils.kt | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/common-api/src/main/kotlin/com/itangcent/common/utils/KVUtils.kt b/common-api/src/main/kotlin/com/itangcent/common/utils/KVUtils.kt index 2e75f5145..e0aa3157e 100644 --- a/common-api/src/main/kotlin/com/itangcent/common/utils/KVUtils.kt +++ b/common-api/src/main/kotlin/com/itangcent/common/utils/KVUtils.kt @@ -2,6 +2,7 @@ package com.itangcent.common.utils import com.itangcent.common.constant.Attrs import java.util.* +import kotlin.collections.ArrayList object KVUtils { @@ -101,8 +102,15 @@ object KVUtils { if (comments == null) { comments = HashMap() info[Attrs.COMMENT_ATTR] = comments + (comments as HashMap)[field] = comment + } else { + val oldComment = (comments as HashMap)[field] + if (oldComment == null) { + comments[field] = comment + } else { + comments[field] = "$oldComment\n$comment" + } } - (comments as HashMap)[field] = comment } @Suppress("UNCHECKED_CAST") @@ -143,7 +151,16 @@ object KVUtils { if (comments == null) { comments = HashMap() info[Attrs.COMMENT_ATTR] = comments + (comments as HashMap)["$field@options"] = options + } else { + val oldOptions = (comments as HashMap)["$field@options"] + if (oldOptions == null) { + comments["$field@options"] = options + } else { + val mergeOptions: ArrayList> = ArrayList(oldOptions as ArrayList>) + mergeOptions.addAll(options) + comments["$field@options"] = mergeOptions + } } - (comments as HashMap)["$field@options"] = options } }