mirror of
https://github.com/chylex/IntelliJ-Rainbow-Brackets.git
synced 2025-05-14 12:34:03 +02:00
refactoring: using jackson
instead of org.json
since org.json
not bundled with SDK
This commit is contained in:
parent
9e50fe501f
commit
909f251152
@ -1,22 +1,18 @@
|
||||
package com.github.izhangzhihao.rainbow.brackets
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
|
||||
import com.fasterxml.jackson.module.kotlin.readValue
|
||||
import com.github.izhangzhihao.rainbow.brackets.color.Luminosity
|
||||
import com.github.izhangzhihao.rainbow.brackets.color.fromString
|
||||
import org.json.JSONObject
|
||||
import java.awt.Color
|
||||
|
||||
fun randomColor(options: String): Color {
|
||||
val options = JSONObject(options)
|
||||
return com.github.izhangzhihao.rainbow.brackets.color.randomColor(
|
||||
fromString(options.getStringOrDefault("hue", "random")),
|
||||
Luminosity.valueOf(options.getStringOrDefault("luminosity", "random"))
|
||||
)
|
||||
}
|
||||
val mapper: ObjectMapper by lazy { jacksonObjectMapper() }
|
||||
|
||||
fun org.json.JSONObject.getStringOrDefault(key: String, default: String): String {
|
||||
return try {
|
||||
this.getString(key)
|
||||
} catch (e: Exception) {
|
||||
default
|
||||
}
|
||||
fun randomColor(options: String): Color {
|
||||
val ops: Map<String, String> = mapper.readValue(options)
|
||||
return com.github.izhangzhihao.rainbow.brackets.color.randomColor(
|
||||
fromString(ops.getOrDefault("hue", "random")),
|
||||
Luminosity.valueOf(ops.getOrDefault("luminosity", "random"))
|
||||
)
|
||||
}
|
Loading…
Reference in New Issue
Block a user