Skip to content

Commit bb4b203

Browse files
Merge pull request #18 from simplecloudapp/ref/config-factory-t
ref: change any to t in ConfigFactory.kt
2 parents b2c5f5a + 6e6dcbf commit bb4b203

File tree

1 file changed

+8
-8
lines changed
  • plugin-shared/src/main/kotlin/app/simplecloud/plugin/api/shared/config

1 file changed

+8
-8
lines changed

plugin-shared/src/main/kotlin/app/simplecloud/plugin/api/shared/config/ConfigFactory.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ import kotlin.coroutines.CoroutineContext
2424
* val factory = ConfigFactory.create<MyConfig>(File("config.json"), Dispatchers.Default)
2525
* ```
2626
*/
27-
class ConfigFactory(
27+
class ConfigFactory<T>(
2828
private val file: File,
29-
private val configClass: Class<*>,
29+
private val configClass: Class<T>,
3030
private val coroutineContext: CoroutineContext = Dispatchers.IO
3131
) : AutoCloseable {
3232

33-
private var config: Any? = null
33+
private var config: T? = null
3434
private val path: Path = file.toPath()
3535
private var watchJob: Job? = null
3636

@@ -45,7 +45,7 @@ class ConfigFactory(
4545
}
4646
.build()
4747

48-
fun loadOrCreate(defaultConfig: Any) {
48+
fun loadOrCreate(defaultConfig: T) {
4949
if (!configClass.isInstance(defaultConfig)) {
5050
throw IllegalArgumentException("Default config must be an instance of ${configClass.name}")
5151
}
@@ -59,7 +59,7 @@ class ConfigFactory(
5959
registerWatcher()
6060
}
6161

62-
private fun createDefaultConfig(defaultConfig: Any) {
62+
private fun createDefaultConfig(defaultConfig: T) {
6363
path.parent?.let { Files.createDirectories(it) }
6464
Files.createFile(path)
6565

@@ -70,8 +70,8 @@ class ConfigFactory(
7070
}
7171

7272
@Suppress("UNCHECKED_CAST")
73-
fun <T> getConfig(): T {
74-
return config as? T ?: throw IllegalStateException("Configuration not loaded or invalid type")
73+
fun getConfig(): T {
74+
return config ?: throw IllegalStateException("Configuration not loaded or invalid type")
7575
}
7676

7777
@Throws(ConfigurationException::class)
@@ -133,6 +133,6 @@ class ConfigFactory(
133133
inline fun <reified T : Any> create(
134134
file: File,
135135
coroutineContext: CoroutineContext = Dispatchers.IO
136-
): ConfigFactory = ConfigFactory(file, T::class.java, coroutineContext)
136+
): ConfigFactory<T> = ConfigFactory(file, T::class.java, coroutineContext)
137137
}
138138
}

0 commit comments

Comments
 (0)