mirror of
https://github.com/HMCore/Core.git
synced 2026-01-23 10:22:46 +00:00
Refactor Gson saving to Kotlin
This commit is contained in:
@@ -1,30 +0,0 @@
|
|||||||
package org.hmcore.registration.config;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.GsonBuilder;
|
|
||||||
import org.hmcore.modules.Module;
|
|
||||||
|
|
||||||
public class ObjectInfoConfigHandler {
|
|
||||||
|
|
||||||
public static String generateFreshJSON(Module<?,?>[] modules) {
|
|
||||||
|
|
||||||
ModuleInfo[] moduleInfos = new ModuleInfo[modules.length];
|
|
||||||
|
|
||||||
for (int i = 0; i < modules.length; i++) {
|
|
||||||
|
|
||||||
Module<?,?> module = modules[i];
|
|
||||||
moduleInfos[i] = new ModuleInfo(module.getName(),
|
|
||||||
module.getObjectInfoArray());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
ObjectInfoConfig objectInfoConfig = new ObjectInfoConfig(moduleInfos);
|
|
||||||
|
|
||||||
GsonBuilder builder = new GsonBuilder().setPrettyPrinting();
|
|
||||||
Gson gson = builder.create();
|
|
||||||
|
|
||||||
return gson.toJson(objectInfoConfig);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -5,12 +5,12 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
public class ObjectInfoData {
|
public class ObjectInfoData {
|
||||||
|
|
||||||
public final String objectName;
|
public final String objectName;
|
||||||
public final String objectInfoChoosen;
|
public final String objectInfoChosen;
|
||||||
public final String _availableOptions;
|
public final String _availableOptions;
|
||||||
|
|
||||||
public ObjectInfoData(String objectName, @Nullable String objectInfoChoosen, String availableOptions) {
|
public ObjectInfoData(String objectName, @Nullable String objectInfoChosen, String availableOptions) {
|
||||||
this.objectName = objectName;
|
this.objectName = objectName;
|
||||||
this.objectInfoChoosen = objectInfoChoosen == null ? "default" : objectInfoChoosen;
|
this.objectInfoChosen = objectInfoChosen == null ? "default" : objectInfoChosen;
|
||||||
_availableOptions = availableOptions;
|
_availableOptions = availableOptions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
7
src/main/kotlin/extensions/Array.kt
Normal file
7
src/main/kotlin/extensions/Array.kt
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
package extensions
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map a Java array to another Java array
|
||||||
|
*/
|
||||||
|
inline fun <T, reified I> Array<T>.map(crossinline transform: (T) -> I) =
|
||||||
|
Array(size) { transform(this[it]) }
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
@file:JvmName("ObjectInfoConfigHandler")
|
||||||
|
|
||||||
|
package org.hmcore.registration.config
|
||||||
|
|
||||||
|
import com.google.gson.GsonBuilder
|
||||||
|
import org.hmcore.modules.Module
|
||||||
|
import extensions.map
|
||||||
|
|
||||||
|
private val GSON = GsonBuilder().setPrettyPrinting().create()
|
||||||
|
|
||||||
|
fun Array<Module<*, *>>.generateFreshJSON(): String =
|
||||||
|
GSON.toJson(ObjectInfoConfig(map { ModuleInfo(it.name, it.objectInfoArray) }))
|
||||||
Reference in New Issue
Block a user