Config fix
This commit is contained in:
parent
15ea52ed7e
commit
9b5dee0917
2 changed files with 11 additions and 10 deletions
|
@ -210,8 +210,14 @@ public final class ConfigKeeper {
|
||||||
|
|
||||||
public static class EnumEntry<T extends Enum<T>> extends Entry<T> {
|
public static class EnumEntry<T extends Enum<T>> extends Entry<T> {
|
||||||
|
|
||||||
|
private final Type type;
|
||||||
|
|
||||||
public EnumEntry(T defaultValue) {
|
public EnumEntry(T defaultValue) {
|
||||||
super(defaultValue);
|
super(defaultValue);
|
||||||
|
TypeToken<T> token = new TypeToken<T>(){
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
};
|
||||||
|
this.type = token.getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -257,7 +263,6 @@ public final class ConfigKeeper {
|
||||||
public static abstract class Entry<T> {
|
public static abstract class Entry<T> {
|
||||||
|
|
||||||
protected final T defaultValue;
|
protected final T defaultValue;
|
||||||
protected final Type type;
|
|
||||||
protected Consumer<T> writer;
|
protected Consumer<T> writer;
|
||||||
protected Supplier<T> reader;
|
protected Supplier<T> reader;
|
||||||
|
|
||||||
|
@ -266,7 +271,6 @@ public final class ConfigKeeper {
|
||||||
|
|
||||||
public Entry (T defaultValue) {
|
public Entry (T defaultValue) {
|
||||||
this.defaultValue = defaultValue;
|
this.defaultValue = defaultValue;
|
||||||
this.type = new EntryType().getType();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setWriter(Consumer<T> writer) {
|
protected void setWriter(Consumer<T> writer) {
|
||||||
|
@ -277,10 +281,6 @@ public final class ConfigKeeper {
|
||||||
this.reader = reader;
|
this.reader = reader;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Type getType() {
|
|
||||||
return this.type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public T getValue() {
|
public T getValue() {
|
||||||
return this.reader.get();
|
return this.reader.get();
|
||||||
}
|
}
|
||||||
|
@ -296,9 +296,5 @@ public final class ConfigKeeper {
|
||||||
public void setDefault() {
|
public void setDefault() {
|
||||||
this.setValue(defaultValue);
|
this.setValue(defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected class EntryType extends TypeToken<T> {
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,11 @@ public class ConfigKey {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return String.format("%s:%s:%s", owner, category, entry);
|
||||||
|
}
|
||||||
|
|
||||||
private void validate(String owner, String category, String entry) {
|
private void validate(String owner, String category, String entry) {
|
||||||
if (owner == null) {
|
if (owner == null) {
|
||||||
throw new NullPointerException("Failed to create ConfigKey: 'owner' can't be null.");
|
throw new NullPointerException("Failed to create ConfigKey: 'owner' can't be null.");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue