mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-22 16:41:46 +03:00
[FEATURE] SimpleConfig
This commit is contained in:
parent
327d243761
commit
034e5c154e
1 changed files with 39 additions and 0 deletions
|
@ -0,0 +1,39 @@
|
|||
package pro.gravit.launcher.config;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public abstract class SimpleConfig<T> implements JsonConfigurableInterface<T> {
|
||||
private transient final Class<T> type;
|
||||
protected transient final Path configPath;
|
||||
|
||||
protected SimpleConfig(Class<T> type, Path configPath) {
|
||||
this.type = type;
|
||||
this.configPath = configPath;
|
||||
}
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public T getConfig() {
|
||||
return (T) this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getDefaultConfig() {
|
||||
try {
|
||||
return type.newInstance();
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Path getPath() {
|
||||
return configPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue