Skip to content

Commit bbb7071

Browse files
committed
♻️ refactor to use internal Utils and add Encoder/Decoder for improved structure
1 parent 316fafd commit bbb7071

File tree

9 files changed

+26
-14
lines changed

9 files changed

+26
-14
lines changed

qs-kotlin/src/main/kotlin/io/github/techouse/qskotlin/Decoder.kt renamed to qs-kotlin/src/main/kotlin/io/github/techouse/qskotlin/internal/Decoder.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.github.techouse.qskotlin
1+
package io.github.techouse.qskotlin.internal
22

33
import io.github.techouse.qskotlin.enums.Duplicates
44
import io.github.techouse.qskotlin.enums.Sentinel
@@ -226,7 +226,7 @@ internal object Decoder {
226226
index.toString() == decodedRoot &&
227227
options.parseLists &&
228228
index <= options.listLimit -> {
229-
val list = MutableList<Any?>(index + 1) { Undefined() }
229+
val list = MutableList<Any?>(index + 1) { Undefined.Companion() }
230230
list[index] = leaf
231231
obj = list
232232
}

qs-kotlin/src/main/kotlin/io/github/techouse/qskotlin/Encoder.kt renamed to qs-kotlin/src/main/kotlin/io/github/techouse/qskotlin/internal/Encoder.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
1-
package io.github.techouse.qskotlin
1+
package io.github.techouse.qskotlin.internal
22

33
import io.github.techouse.qskotlin.enums.Format
44
import io.github.techouse.qskotlin.enums.Formatter
55
import io.github.techouse.qskotlin.enums.ListFormat
66
import io.github.techouse.qskotlin.enums.ListFormatGenerator
7-
import io.github.techouse.qskotlin.models.*
7+
import io.github.techouse.qskotlin.models.DateSerializer
8+
import io.github.techouse.qskotlin.models.Filter
9+
import io.github.techouse.qskotlin.models.FunctionFilter
10+
import io.github.techouse.qskotlin.models.IterableFilter
11+
import io.github.techouse.qskotlin.models.Sorter
12+
import io.github.techouse.qskotlin.models.Undefined
13+
import io.github.techouse.qskotlin.models.ValueEncoder
14+
import io.github.techouse.qskotlin.models.WeakWrapper
815
import java.nio.charset.Charset
916
import java.nio.charset.StandardCharsets
1017
import java.time.Instant
1118
import java.time.LocalDateTime
12-
import java.util.*
19+
import java.util.WeakHashMap
20+
import kotlin.collections.get
1321

1422
/** A helper object for encoding data into a query string format. */
1523
internal object Encoder {
@@ -153,7 +161,7 @@ internal object Encoder {
153161

154162
listOf(mapOf("value" to objKeysValue.ifEmpty { null }))
155163
} else {
156-
listOf(mapOf("value" to Undefined()))
164+
listOf(mapOf("value" to Undefined.Companion()))
157165
}
158166
}
159167

qs-kotlin/src/main/kotlin/io/github/techouse/qskotlin/Utils.kt renamed to qs-kotlin/src/main/kotlin/io/github/techouse/qskotlin/internal/Utils.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.github.techouse.qskotlin
1+
package io.github.techouse.qskotlin.internal
22

33
import io.github.techouse.qskotlin.constants.HexTable
44
import io.github.techouse.qskotlin.enums.Format
@@ -11,6 +11,8 @@ import java.nio.charset.Charset
1111
import java.nio.charset.StandardCharsets
1212
import java.time.Instant
1313
import java.time.LocalDateTime
14+
import java.util.Collections
15+
import java.util.IdentityHashMap
1416

1517
/** A collection of utility methods used by the library. */
1618
internal object Utils {
@@ -473,8 +475,7 @@ internal object Utils {
473475
stack.add(root)
474476

475477
// Identity-based visited set: avoids infinite loops on cycles
476-
val visited: MutableSet<Any> =
477-
java.util.Collections.newSetFromMap(java.util.IdentityHashMap())
478+
val visited: MutableSet<Any> = Collections.newSetFromMap(IdentityHashMap())
478479

479480
visited.add(root)
480481

qs-kotlin/src/main/kotlin/io/github/techouse/qskotlin/models/DecodeOptions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.github.techouse.qskotlin.models
22

3-
import io.github.techouse.qskotlin.Utils
43
import io.github.techouse.qskotlin.enums.Duplicates
4+
import io.github.techouse.qskotlin.internal.Utils
55
import java.nio.charset.Charset
66
import java.nio.charset.StandardCharsets
77

qs-kotlin/src/main/kotlin/io/github/techouse/qskotlin/models/EncodeOptions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package io.github.techouse.qskotlin.models
22

3-
import io.github.techouse.qskotlin.Utils
43
import io.github.techouse.qskotlin.enums.Format
54
import io.github.techouse.qskotlin.enums.Formatter
65
import io.github.techouse.qskotlin.enums.ListFormat
6+
import io.github.techouse.qskotlin.internal.Utils
77
import java.nio.charset.Charset
88
import java.nio.charset.StandardCharsets
99
import java.time.LocalDateTime

qs-kotlin/src/main/kotlin/io/github/techouse/qskotlin/api.kt renamed to qs-kotlin/src/main/kotlin/io/github/techouse/qskotlin/qs.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ package io.github.techouse.qskotlin
55

66
import io.github.techouse.qskotlin.enums.ListFormat
77
import io.github.techouse.qskotlin.enums.Sentinel
8+
import io.github.techouse.qskotlin.internal.Decoder
9+
import io.github.techouse.qskotlin.internal.Encoder
10+
import io.github.techouse.qskotlin.internal.Utils
811
import io.github.techouse.qskotlin.models.DecodeOptions
912
import io.github.techouse.qskotlin.models.EncodeOptions
1013
import io.github.techouse.qskotlin.models.FunctionFilter

qs-kotlin/src/test/kotlin/io/github/techouse/qskotlin/unit/DecodeSpec.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package io.github.techouse.qskotlin.unit
22

3-
import io.github.techouse.qskotlin.Utils
43
import io.github.techouse.qskotlin.decode
54
import io.github.techouse.qskotlin.encode
65
import io.github.techouse.qskotlin.enums.Duplicates
76
import io.github.techouse.qskotlin.fixtures.data.EmptyTestCases
7+
import io.github.techouse.qskotlin.internal.Utils
88
import io.github.techouse.qskotlin.models.DecodeOptions
99
import io.github.techouse.qskotlin.models.RegexDelimiter
1010
import io.github.techouse.qskotlin.models.StringDelimiter

qs-kotlin/src/test/kotlin/io/github/techouse/qskotlin/unit/EncodeSpec.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package io.github.techouse.qskotlin.unit
22

3-
import io.github.techouse.qskotlin.Utils
43
import io.github.techouse.qskotlin.encode
54
import io.github.techouse.qskotlin.enums.Format
65
import io.github.techouse.qskotlin.enums.ListFormat
76
import io.github.techouse.qskotlin.fixtures.DummyEnum
87
import io.github.techouse.qskotlin.fixtures.data.EmptyTestCases
8+
import io.github.techouse.qskotlin.internal.Utils
99
import io.github.techouse.qskotlin.models.*
1010
import io.kotest.assertions.throwables.shouldNotThrow
1111
import io.kotest.assertions.throwables.shouldThrow

qs-kotlin/src/test/kotlin/io/github/techouse/qskotlin/unit/UtilsSpec.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package io.github.techouse.qskotlin.unit
22

3-
import io.github.techouse.qskotlin.Utils
43
import io.github.techouse.qskotlin.enums.Format
54
import io.github.techouse.qskotlin.fixtures.DummyEnum
5+
import io.github.techouse.qskotlin.internal.Utils
66
import io.github.techouse.qskotlin.models.Undefined
77
import io.kotest.core.spec.style.FunSpec
88
import io.kotest.matchers.maps.shouldContainKey

0 commit comments

Comments
 (0)