Skip to content

Commit

Permalink
fixed an issue with JConfigUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
RealYusufIsmail committed Sep 11, 2022
1 parent 48747e0 commit 740d41b
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 163 deletions.
2 changes: 1 addition & 1 deletion Package.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ And thats it for getting the token.
<dependency>
<groupId>io.github.realyusufismail</groupId>
<artifactId>jconfig</artifactId>
<version>1.0.4</version>
<version>1.0.5</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ And thats it for getting the token.
<dependency>
<groupId>io.github.realyusufismail</groupId>
<artifactId>jconfig</artifactId>
<version>1.0.4</version>
<version>1.0.5</version>
</dependency>
```

Expand Down
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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.4")
set("version", "1.0.5")
set("dev_id", "yusuf")
set("dev_name", "Yusuf Ismail")
set("dev_email", "yusufgamer222@gmail.com")
Expand All @@ -37,7 +37,7 @@ extra.apply {
}

group = "io.github.realyusufismail"
version = "1.0.4"
version = "1.0.5"

repositories {
mavenCentral()
Expand Down
48 changes: 33 additions & 15 deletions src/main/kotlin/io/github/realyusufismail/jconfig/JConfigObject.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,51 @@ import java.math.BigInteger

/** Used to get a value as a certain type. */
interface JConfigObject {
var string: String
/** Get the value as a [String]. */
val string: String

var int: Int
/** Get the value as an [Int]. */
val int: Int

var bigInt: BigInteger
/** Get the value as a [BigInteger]. */
val bigInt: BigInteger

var double: Double
/** Get the value as a [Double]. */
val double: Double

var boolean: Boolean
/** Get the value as a [Boolean]. */
val boolean: Boolean

var byte: Byte
/** Get the value as a [Byte]. */
val byte: Byte

var short: Short
/** Get the value as a [Short]. */
val short: Short

var long: Long
/** Get the value as a [Long]. */
val long: Long

var float: Float
/** Get the value as a [Float]. */
val float: Float

var char: Char
/** Get the value as a [Char]. */
val char: Char

var number: Number
/** Get the value as a [Number]. */
val number: Number

var decimal: BigDecimal
/** Get the value as a [BigDecimal]. */
val decimal: BigDecimal

var array: Array<JConfigObject>
/** Get the value as an [Array]. */
val array: Array<JConfigObject>

var map: Map<String, JConfigObject>
/** Get the value as a [List]. */
val list: List<JConfigObject>

var any: Any
/** Get the value as a [Map]. */
val map: Map<String, JConfigObject>

/** Get the value as an [Any]. */
val any: Any
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,151 +24,115 @@ import java.math.BigInteger

class JConfigObjectImpl(private val value: Any) : JConfigObject {

override var string: String
override val string: String
get() {
if (value is String) {
return value
} else {
throw ClassCastException("Cannot cast ${value::class.java} to String")
}
}
set(value) {
throw UnsupportedOperationException("Cannot set value of JConfigObject")
}

override var int: Int
override val int: Int
get() {
if (value is Int) {
return value
} else {
throw ClassCastException("Cannot cast $value to Int")
}
}
set(value) {
throw UnsupportedOperationException("Cannot set value of JConfigObject")
}

override var bigInt: BigInteger
override val bigInt: BigInteger
get() {
if (value is BigInteger) {
return value
} else {
throw ClassCastException("Cannot cast $value to BigInteger")
}
}
set(value) {
throw UnsupportedOperationException("Cannot set value of JConfigObject")
}

override var double: Double
override val double: Double
get() {
if (value is Double) {
return value
} else {
throw ClassCastException("Cannot cast $value to Double")
}
}
set(value) {
throw UnsupportedOperationException("Cannot set value of JConfigObject")
}

override var boolean: Boolean
override val boolean: Boolean
get() {
if (value is Boolean) {
return value
} else {
throw ClassCastException("Cannot cast $value to Boolean")
}
}
set(value) {
throw UnsupportedOperationException("Cannot set value of JConfigObject")
}

override var byte: Byte
override val byte: Byte
get() {
if (value is Byte) {
return value
} else {
throw ClassCastException("Cannot cast $value to Byte")
}
}
set(value) {
throw UnsupportedOperationException("Cannot set value of JConfigObject")
}

override var short: Short
override val short: Short
get() {
if (value is Short) {
return value
} else {
throw ClassCastException("Cannot cast $value to Short")
}
}
set(value) {
throw UnsupportedOperationException("Cannot set value of JConfigObject")
}

override var long: Long
override val long: Long
get() {
if (value is Long) {
return value
} else {
throw ClassCastException("Cannot cast $value to Long")
}
}
set(value) {
throw UnsupportedOperationException("Cannot set value of JConfigObject")
}

override var float: Float
override val float: Float
get() {
if (value is Float) {
return value
} else {
throw ClassCastException("Cannot cast $value to Float")
}
}
set(value) {
throw UnsupportedOperationException("Cannot set value of JConfigObject")
}

override var char: Char
override val char: Char
get() {
if (value is Char) {
return value
} else {
throw ClassCastException("Cannot cast $value to Char")
}
}
set(value) {
throw UnsupportedOperationException("Cannot set value of JConfigObject")
}

override var number: Number
override val number: Number
get() {
if (value is Number) {
return value
} else {
throw ClassCastException("Cannot cast $value to Number")
}
}
set(value) {
throw UnsupportedOperationException("Cannot set value of JConfigObject")
}

override var decimal: BigDecimal
override val decimal: BigDecimal
get() {
if (value is BigDecimal) {
return value
} else {
throw ClassCastException("Cannot cast $value to BigDecimal")
}
}
set(value) {
throw UnsupportedOperationException("Cannot set value of JConfigObject")
}

override var array: Array<JConfigObject>
override val array: Array<JConfigObject>
get() {
if (value is Array<*>) {
return value
Expand All @@ -178,11 +142,19 @@ class JConfigObjectImpl(private val value: Any) : JConfigObject {
throw ClassCastException("Cannot cast $value to Array")
}
}
set(value) {
throw UnsupportedOperationException("Cannot set value of JConfigObject")

override val list: List<JConfigObject>
get() {
if (value is List<*>) {
return value.map {
it?.let { it1 -> JConfigObjectImpl(it1) } ?: JConfigObjectImpl("")
}
} else {
throw ClassCastException("Cannot cast $value to List")
}
}

override var map: Map<String, JConfigObject>
override val map: Map<String, JConfigObject>
get() {
if (value is Map<*, *>) {
return value
Expand All @@ -196,15 +168,9 @@ class JConfigObjectImpl(private val value: Any) : JConfigObject {
throw ClassCastException("Cannot cast $value to Map")
}
}
set(value) {
throw UnsupportedOperationException("Cannot set value of JConfigObject")
}

override var any: Any
override val any: Any
get() {
return value
}
set(value) {
throw UnsupportedOperationException("Cannot set value of JConfigObject")
}
}
Loading

0 comments on commit 740d41b

Please sign in to comment.