Skip to content

Commit

Permalink
chore: Clear up some minor deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
nhubbard committed Feb 10, 2024
1 parent f65f9bc commit ffd39a1
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/main/kotlin/com/nhubbard/konfig/SizeInBytes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ data class SizeInBytes(
ZEBIBYTES("zebi", Radix.KIBI, 7),
YOBIBYTES("yobi", Radix.KIBI, 8);

internal val bytes: BigInteger = BigInteger.valueOf(radix.toInt().toLong()).pow(power)
val bytes: BigInteger = BigInteger.valueOf(radix.toInt().toLong()).pow(power)

companion object {

private val unitsMap = mutableMapOf<String, MemoryUnit>().apply {
for (unit in MemoryUnit.values()) {
for (unit in MemoryUnit.entries) {
put(unit.prefix + "byte", unit)
put(unit.prefix + "bytes", unit)
if (unit.prefix.isEmpty()) {
Expand All @@ -137,7 +137,7 @@ data class SizeInBytes(
put("", unit) // no unit specified means bytes
} else {
val first = unit.prefix.substring(0, 1)
val firstUpper = first.toUpperCase()
val firstUpper = first.uppercase()
when (unit.radix) {
Radix.KILO -> {
if (unit.power == 1) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/com/nhubbard/konfig/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ fun String.notEmptyOr(default: String): String = if (isEmpty()) default else thi

fun String.toLittleCase(): String {
return if (this.all { it.isUpperCase() }) {
this.toLowerCase()
this.lowercase()
} else {
when (val firstLowerCaseIndex = this.indexOfFirst { it.isLowerCase() }) {
-1, 0 -> this
1 -> this[0].toLowerCase() + this.drop(1)
1 -> this[0].lowercaseChar() + this.drop(1)
else ->
this.substring(0, firstLowerCaseIndex - 1).toLowerCase() +
this.substring(0, firstLowerCaseIndex - 1).lowercase() +
this.substring(firstLowerCaseIndex - 1)
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/kotlin/com/nhubbard/konfig/source/DefaultLoaders.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.nhubbard.konfig.source.json.JsonProvider
import com.nhubbard.konfig.source.properties.PropertiesProvider
import kotlinx.coroutines.Dispatchers
import java.io.File
import java.net.URI
import java.net.URL
import java.util.concurrent.TimeUnit
import kotlin.coroutines.CoroutineContext
Expand Down Expand Up @@ -293,7 +294,7 @@ class DefaultLoaders(
* @return a child config containing values from specified url string
* @throws UnsupportedExtensionException
*/
fun url(url: String, optional: Boolean = this.optional): Config = url(URL(url), optional)
fun url(url: String, optional: Boolean = this.optional): Config = url(URI(url).toURL(), optional)

/**
* Returns a child config containing values from specified url,
Expand Down Expand Up @@ -360,7 +361,7 @@ class DefaultLoaders(
context: CoroutineContext = Dispatchers.Default,
optional: Boolean = this.optional,
onLoad: ((config: Config, source: Source) -> Unit)? = null
): Config = watchUrl(URL(url), period, unit, context, optional, onLoad)
): Config = watchUrl(URI(url).toURL(), period, unit, context, optional, onLoad)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.nhubbard.konfig.source.env.EnvProvider
import com.nhubbard.konfig.source.json.JsonProvider
import com.nhubbard.konfig.source.properties.PropertiesProvider
import java.io.File
import java.net.URI
import java.net.URL

/**
Expand Down Expand Up @@ -157,7 +158,7 @@ object DefaultProviders {
* @return a source from specified url string
* @throws UnsupportedExtensionException
*/
fun url(url: String, optional: Boolean = false): Source = url(URL(url), optional)
fun url(url: String, optional: Boolean = false): Source = url(URI(url).toURL(), optional)
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/main/kotlin/com/nhubbard/konfig/source/Loader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import kotlinx.coroutines.launch
import java.io.File
import java.io.InputStream
import java.io.Reader
import java.net.URI
import java.net.URL
import java.nio.file.FileSystems
import java.nio.file.StandardWatchEventKinds
Expand Down Expand Up @@ -126,7 +127,7 @@ class Loader(
}
onLoad?.invoke(newConfig, source)
val path = absoluteFile.toPath().parent
val isMac = "mac" in System.getProperty("os.name").toLowerCase()
val isMac = "mac" in System.getProperty("os.name").lowercase()
val watcher = FileSystems.getDefault().newWatchService()
path.register(
watcher,
Expand Down Expand Up @@ -316,7 +317,7 @@ class Loader(
optional: Boolean = this.optional,
onLoad: ((config: Config, source: Source) -> Unit)? = null
): Config =
watchUrl(URL(url), period, unit, context, optional, onLoad)
watchUrl(URI(url).toURL(), period, unit, context, optional, onLoad)

/**
* Returns a child config containing values from specified resource.
Expand Down
10 changes: 5 additions & 5 deletions src/main/kotlin/com/nhubbard/konfig/source/Provider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import com.nhubbard.konfig.source.json.JsonProvider
import com.nhubbard.konfig.source.properties.PropertiesProvider
import org.reflections.ReflectionUtils
import org.reflections.Reflections
import org.reflections.scanners.SubTypesScanner
import org.reflections.scanners.TypeAnnotationsScanner
import org.reflections.scanners.Scanners
import java.io.File
import java.io.IOException
import java.io.InputStream
import java.io.Reader
import java.net.URI
import java.net.URL
import java.util.concurrent.ConcurrentHashMap

Expand Down Expand Up @@ -163,7 +163,7 @@ interface Provider {
* @param optional whether this source is optional
* @return a new source from specified url string
*/
fun url(url: String, optional: Boolean = false): Source = url(URL(url), optional)
fun url(url: String, optional: Boolean = false): Source = url(URI(url).toURL(), optional)

/**
* Returns a new source from specified resource.
Expand Down Expand Up @@ -254,8 +254,8 @@ interface Provider {
init {
val reflections = Reflections(
"com.nhubbard.konfig",
SubTypesScanner(),
TypeAnnotationsScanner()
Scanners.SubTypes,
Scanners.TypesAnnotated
)
val providers = reflections.getSubTypesOf(Provider::class.java)
.intersect(reflections.getTypesAnnotatedWith(RegisterExtension::class.java))
Expand Down
10 changes: 5 additions & 5 deletions src/test/kotlin/com/nhubbard/konfig/source/DefaultLoadersSpec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ import org.jetbrains.spek.api.dsl.on
import org.jetbrains.spek.subject.SubjectSpek
import org.jetbrains.spek.subject.itBehavesLike
import spark.Service
import java.net.URL
import java.util.UUID
import java.net.URI
import java.util.*
import java.util.concurrent.TimeUnit

object DefaultLoadersSpec : SubjectSpek<DefaultLoaders>({
Expand Down Expand Up @@ -93,7 +93,7 @@ object DefaultLoadersSpec : SubjectSpek<DefaultLoaders>({
service.port(0)
service.get("/source.properties") { _, _ -> propertiesContent }
service.awaitInitialization()
val config = subject.url(URL("http://localhost:${service.port()}/source.properties"))
val config = subject.url(URI("http://localhost:${service.port()}/source.properties").toURL())
it("should load as auto-detected URL format") {
assertThat(config[item], equalTo("properties"))
}
Expand Down Expand Up @@ -213,7 +213,7 @@ object DefaultLoadersSpec : SubjectSpek<DefaultLoaders>({
service.get("/source.properties") { _, _ -> content }
service.awaitInitialization()
val url = "http://localhost:${service.port()}/source.properties"
val config = subject.watchUrl(URL(url), period = 1, unit = TimeUnit.SECONDS, context = Dispatchers.Sequential)
val config = subject.watchUrl(URI(url).toURL(), period = 1, unit = TimeUnit.SECONDS, context = Dispatchers.Sequential)
val originalValue = config[item]
content = propertiesContent.replace("properties", "newValue")
runBlocking(Dispatchers.Sequential) {
Expand All @@ -234,7 +234,7 @@ object DefaultLoadersSpec : SubjectSpek<DefaultLoaders>({
service.get("/source.properties") { _, _ -> content }
service.awaitInitialization()
val url = "http://localhost:${service.port()}/source.properties"
val config = subject.watchUrl(URL(url), context = Dispatchers.Sequential)
val config = subject.watchUrl(URI(url).toURL(), context = Dispatchers.Sequential)
val originalValue = config[item]
content = propertiesContent.replace("properties", "newValue")
runBlocking(Dispatchers.Sequential) {
Expand Down

0 comments on commit ffd39a1

Please sign in to comment.