From 3b04866d7941fd47717e1b152545a887e7432173 Mon Sep 17 00:00:00 2001 From: Yusuf Arfan Ismail Date: Mon, 12 Sep 2022 21:39:12 +0100 Subject: [PATCH] some bug fixing and renaming --- Package.md | 6 ++-- README.md | 6 ++-- build.gradle.kts | 4 +-- .../realyusufismail/jconfig/JConfigObject.kt | 32 ++++++++--------- .../jconfig/classes/JConfigImpl.kt | 10 +++--- .../jconfig/classes/JConfigObjectImpl.kt | 32 ++++++++--------- .../jconfig/classes/JsonEntry.kt | 2 +- .../jconfig/util/JConfigUtils.kt | 36 +++++++++---------- 8 files changed, 65 insertions(+), 63 deletions(-) diff --git a/Package.md b/Package.md index 94ab2c0..de429dc 100644 --- a/Package.md +++ b/Package.md @@ -37,7 +37,7 @@ And thats it for getting the token. io.github.realyusufismail jconfig - 1.0.5 + 1.0.6 ``` @@ -46,11 +46,11 @@ And thats it for getting the token. ```groovy //kotlin dependencies { - implementation("io.github.realyusufismail:jconfig:${project.version}") + implementation("io.github.realyusufismail:jconfig:1.0.6") } //groovy dependencies { - implementation "io.github.realyusufismail:jconfig:${project.version}" + implementation "io.github.realyusufismail:jconfig:1.0.6" } ``` \ No newline at end of file diff --git a/README.md b/README.md index 17e7820..65da270 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ And thats it for getting the token. io.github.realyusufismail jconfig - 1.0.5 + 1.0.6 ``` @@ -48,12 +48,12 @@ And thats it for getting the token. ```groovy //kotlin dependencies { - implementation("io.github.realyusufismail:jconfig:${project.version}") + implementation("io.github.realyusufismail:jconfig:1.0.6") } //groovy dependencies { - implementation "io.github.realyusufismail:jconfig:${project.version}" + implementation "io.github.realyusufismail:jconfig:1.0.6" } ``` diff --git a/build.gradle.kts b/build.gradle.kts index d31b245..fb46c27 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -24,7 +24,7 @@ extra.apply { set("name", "JConfig") set("description", "Json Configurations used to store tokens and other sensitive data") set("group", "io.github.realyusufismail") - set("version", "1.0.5") + set("version", "1.0.6") set("dev_id", "yusuf") set("dev_name", "Yusuf Ismail") set("dev_email", "yusufgamer222@gmail.com") @@ -37,7 +37,7 @@ extra.apply { } group = "io.github.realyusufismail" -version = "1.0.5" +version = "1.0.6" repositories { mavenCentral() diff --git a/src/main/kotlin/io/github/realyusufismail/jconfig/JConfigObject.kt b/src/main/kotlin/io/github/realyusufismail/jconfig/JConfigObject.kt index 8c78779..884aa03 100644 --- a/src/main/kotlin/io/github/realyusufismail/jconfig/JConfigObject.kt +++ b/src/main/kotlin/io/github/realyusufismail/jconfig/JConfigObject.kt @@ -24,50 +24,50 @@ import java.math.BigInteger /** Used to get a value as a certain type. */ interface JConfigObject { /** Get the value as a [String]. */ - val string: String + val asString: String /** Get the value as an [Int]. */ - val int: Int + val asInt: Int /** Get the value as a [BigInteger]. */ - val bigInt: BigInteger + val asBigInt: BigInteger /** Get the value as a [Double]. */ - val double: Double + val asDouble: Double /** Get the value as a [Boolean]. */ - val boolean: Boolean + val asBoolean: Boolean /** Get the value as a [Byte]. */ - val byte: Byte + val asByte: Byte /** Get the value as a [Short]. */ - val short: Short + val asShort: Short /** Get the value as a [Long]. */ - val long: Long + val asLong: Long /** Get the value as a [Float]. */ - val float: Float + val asFloat: Float /** Get the value as a [Char]. */ - val char: Char + val asChar: Char /** Get the value as a [Number]. */ - val number: Number + val asNumber: Number /** Get the value as a [BigDecimal]. */ - val decimal: BigDecimal + val asDecimal: BigDecimal /** Get the value as an [Array]. */ - val array: Array + val asArray: Array /** Get the value as a [List]. */ - val list: List + val asList: List /** Get the value as a [Map]. */ - val map: Map + val asMap: Map /** Get the value as an [Any]. */ - val any: Any + val asAny: Any } diff --git a/src/main/kotlin/io/github/realyusufismail/jconfig/classes/JConfigImpl.kt b/src/main/kotlin/io/github/realyusufismail/jconfig/classes/JConfigImpl.kt index 6845847..063cc5a 100644 --- a/src/main/kotlin/io/github/realyusufismail/jconfig/classes/JConfigImpl.kt +++ b/src/main/kotlin/io/github/realyusufismail/jconfig/classes/JConfigImpl.kt @@ -57,17 +57,19 @@ class JConfigImpl(entries: List) : JConfig { value.isObject -> JConfigObjectImpl( value.fields().asSequence().map { it.key to it.value.asText() }.toMap()) - else -> throw IllegalArgumentException("Unknown type: ${value.javaClass}") + value.isNull -> throw JConfigException("The value of the key $key is null") + else -> + throw JConfigException("The key $key is not a valid type or is not supported") } } else { - throw IllegalArgumentException("Unknown type: ${value.javaClass}") + throw JConfigException("Unknown type: ${value.javaClass}") } } override fun get(key: String, defaultValue: Any): JConfigObject { - return try { + return if (mapEntries.containsKey(key)) { get(key) - } catch (e: NoSuchElementException) { + } else { JConfigObjectImpl(defaultValue) } } diff --git a/src/main/kotlin/io/github/realyusufismail/jconfig/classes/JConfigObjectImpl.kt b/src/main/kotlin/io/github/realyusufismail/jconfig/classes/JConfigObjectImpl.kt index 6efe032..a3f22ba 100644 --- a/src/main/kotlin/io/github/realyusufismail/jconfig/classes/JConfigObjectImpl.kt +++ b/src/main/kotlin/io/github/realyusufismail/jconfig/classes/JConfigObjectImpl.kt @@ -24,7 +24,7 @@ import java.math.BigInteger class JConfigObjectImpl(private val value: Any) : JConfigObject { - override val string: String + override val asString: String get() { if (value is String) { return value @@ -33,7 +33,7 @@ class JConfigObjectImpl(private val value: Any) : JConfigObject { } } - override val int: Int + override val asInt: Int get() { if (value is Int) { return value @@ -42,7 +42,7 @@ class JConfigObjectImpl(private val value: Any) : JConfigObject { } } - override val bigInt: BigInteger + override val asBigInt: BigInteger get() { if (value is BigInteger) { return value @@ -51,7 +51,7 @@ class JConfigObjectImpl(private val value: Any) : JConfigObject { } } - override val double: Double + override val asDouble: Double get() { if (value is Double) { return value @@ -60,7 +60,7 @@ class JConfigObjectImpl(private val value: Any) : JConfigObject { } } - override val boolean: Boolean + override val asBoolean: Boolean get() { if (value is Boolean) { return value @@ -69,7 +69,7 @@ class JConfigObjectImpl(private val value: Any) : JConfigObject { } } - override val byte: Byte + override val asByte: Byte get() { if (value is Byte) { return value @@ -78,7 +78,7 @@ class JConfigObjectImpl(private val value: Any) : JConfigObject { } } - override val short: Short + override val asShort: Short get() { if (value is Short) { return value @@ -87,7 +87,7 @@ class JConfigObjectImpl(private val value: Any) : JConfigObject { } } - override val long: Long + override val asLong: Long get() { if (value is Long) { return value @@ -96,7 +96,7 @@ class JConfigObjectImpl(private val value: Any) : JConfigObject { } } - override val float: Float + override val asFloat: Float get() { if (value is Float) { return value @@ -105,7 +105,7 @@ class JConfigObjectImpl(private val value: Any) : JConfigObject { } } - override val char: Char + override val asChar: Char get() { if (value is Char) { return value @@ -114,7 +114,7 @@ class JConfigObjectImpl(private val value: Any) : JConfigObject { } } - override val number: Number + override val asNumber: Number get() { if (value is Number) { return value @@ -123,7 +123,7 @@ class JConfigObjectImpl(private val value: Any) : JConfigObject { } } - override val decimal: BigDecimal + override val asDecimal: BigDecimal get() { if (value is BigDecimal) { return value @@ -132,7 +132,7 @@ class JConfigObjectImpl(private val value: Any) : JConfigObject { } } - override val array: Array + override val asArray: Array get() { if (value is Array<*>) { return value @@ -143,7 +143,7 @@ class JConfigObjectImpl(private val value: Any) : JConfigObject { } } - override val list: List + override val asList: List get() { if (value is List<*>) { return value.map { @@ -154,7 +154,7 @@ class JConfigObjectImpl(private val value: Any) : JConfigObject { } } - override val map: Map + override val asMap: Map get() { if (value is Map<*, *>) { return value @@ -169,7 +169,7 @@ class JConfigObjectImpl(private val value: Any) : JConfigObject { } } - override val any: Any + override val asAny: Any get() { return value } diff --git a/src/main/kotlin/io/github/realyusufismail/jconfig/classes/JsonEntry.kt b/src/main/kotlin/io/github/realyusufismail/jconfig/classes/JsonEntry.kt index 2fb0bb5..6038075 100644 --- a/src/main/kotlin/io/github/realyusufismail/jconfig/classes/JsonEntry.kt +++ b/src/main/kotlin/io/github/realyusufismail/jconfig/classes/JsonEntry.kt @@ -49,7 +49,7 @@ class JsonEntry ) { override fun toString(): String { - return "JsonEntry{key='$key', value=$value}" + return "{key: $key, value: $value}" } override fun equals(other: Any?): Boolean { diff --git a/src/main/kotlin/io/github/realyusufismail/jconfig/util/JConfigUtils.kt b/src/main/kotlin/io/github/realyusufismail/jconfig/util/JConfigUtils.kt index 01dc4e4..4493bb8 100644 --- a/src/main/kotlin/io/github/realyusufismail/jconfig/util/JConfigUtils.kt +++ b/src/main/kotlin/io/github/realyusufismail/jconfig/util/JConfigUtils.kt @@ -33,7 +33,7 @@ class JConfigUtils { */ @JvmStatic fun getString(key: String): String { - return jConfig[key].string + return jConfig[key].asString } /** @@ -46,7 +46,7 @@ class JConfigUtils { */ @JvmStatic fun getString(key: String, defaultValue: String): String { - return jConfig[key, defaultValue].string + return jConfig[key, defaultValue].asString } /** @@ -57,7 +57,7 @@ class JConfigUtils { */ @JvmStatic fun getInt(key: String): Int { - return jConfig[key].int + return jConfig[key].asInt } /** @@ -69,7 +69,7 @@ class JConfigUtils { */ @JvmStatic fun getInt(key: String, defaultValue: Int): Int { - return jConfig[key, defaultValue].int + return jConfig[key, defaultValue].asInt } /** @@ -80,7 +80,7 @@ class JConfigUtils { */ @JvmStatic fun getBoolean(key: String): Boolean { - return jConfig[key].boolean + return jConfig[key].asBoolean } /** @@ -93,7 +93,7 @@ class JConfigUtils { */ @JvmStatic fun getBoolean(key: String, defaultValue: Boolean): Boolean { - return jConfig[key, defaultValue].boolean + return jConfig[key, defaultValue].asBoolean } /** @@ -104,7 +104,7 @@ class JConfigUtils { */ @JvmStatic fun getDouble(key: String): Double { - return jConfig[key].double + return jConfig[key].asDouble } /** @@ -117,7 +117,7 @@ class JConfigUtils { */ @JvmStatic fun getDouble(key: String, defaultValue: Double): Double { - return jConfig[key, defaultValue].double + return jConfig[key, defaultValue].asDouble } /** @@ -128,7 +128,7 @@ class JConfigUtils { */ @JvmStatic fun getLong(key: String): Long { - return jConfig[key].long + return jConfig[key].asLong } /** @@ -140,7 +140,7 @@ class JConfigUtils { */ @JvmStatic fun getLong(key: String, defaultValue: Long): Long { - return jConfig[key, defaultValue].long + return jConfig[key, defaultValue].asLong } /** @@ -151,7 +151,7 @@ class JConfigUtils { */ @JvmStatic fun getFloat(key: String): Float { - return jConfig[key].float + return jConfig[key].asFloat } /** @@ -163,7 +163,7 @@ class JConfigUtils { */ @JvmStatic fun getFloat(key: String, defaultValue: Float): Float { - return jConfig[key, defaultValue].float + return jConfig[key, defaultValue].asFloat } /** @@ -174,7 +174,7 @@ class JConfigUtils { */ @JvmStatic fun getListNode(key: String): List<*> { - return jConfig[key].list + return jConfig[key].asList } /** @@ -186,7 +186,7 @@ class JConfigUtils { */ @JvmStatic fun getListNode(key: String, defaultValue: List<*>): List<*> { - return jConfig[key, defaultValue].list + return jConfig[key, defaultValue].asList } /** @@ -197,7 +197,7 @@ class JConfigUtils { */ @JvmStatic fun getMapNode(key: String): Map<*, *> { - return jConfig[key].map + return jConfig[key].asMap } /** @@ -209,7 +209,7 @@ class JConfigUtils { */ @JvmStatic fun getMapNode(key: String, defaultValue: Map<*, *>): Map<*, *> { - return jConfig[key, defaultValue].map + return jConfig[key, defaultValue].asMap } /** @@ -220,7 +220,7 @@ class JConfigUtils { */ @JvmStatic operator fun get(key: String): Any { - return jConfig[key] + return jConfig[key].asAny } /** @@ -232,7 +232,7 @@ class JConfigUtils { */ @JvmStatic operator fun get(key: String, defaultValue: Any): Any { - return jConfig[key, defaultValue] + return jConfig[key, defaultValue].asAny } } }