Skip to content

Commit

Permalink
opti: addComment will not cover old comment
Browse files Browse the repository at this point in the history
  • Loading branch information
tangcent committed Nov 26, 2019
1 parent da04135 commit bdde72c
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions common-api/src/main/kotlin/com/itangcent/common/utils/KVUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.itangcent.common.utils

import com.itangcent.common.constant.Attrs
import java.util.*
import kotlin.collections.ArrayList

object KVUtils {

Expand Down Expand Up @@ -101,8 +102,15 @@ object KVUtils {
if (comments == null) {
comments = HashMap<String, String>()
info[Attrs.COMMENT_ATTR] = comments
(comments as HashMap<Any?, Any?>)[field] = comment
} else {
val oldComment = (comments as HashMap<Any?, Any?>)[field]
if (oldComment == null) {
comments[field] = comment
} else {
comments[field] = "$oldComment\n$comment"
}
}
(comments as HashMap<Any?, Any?>)[field] = comment
}

@Suppress("UNCHECKED_CAST")
Expand Down Expand Up @@ -143,7 +151,16 @@ object KVUtils {
if (comments == null) {
comments = HashMap<String, String>()
info[Attrs.COMMENT_ATTR] = comments
(comments as HashMap<Any?, Any?>)["$field@options"] = options
} else {
val oldOptions = (comments as HashMap<Any?, Any?>)["$field@options"]
if (oldOptions == null) {
comments["$field@options"] = options
} else {
val mergeOptions: ArrayList<HashMap<String, Any?>> = ArrayList(oldOptions as ArrayList<HashMap<String, Any?>>)
mergeOptions.addAll(options)
comments["$field@options"] = mergeOptions
}
}
(comments as HashMap<Any?, Any?>)["$field@options"] = options
}
}

0 comments on commit bdde72c

Please sign in to comment.