Configuration comments, fixes, command and other fixes #90

Merged
NorbiPeti merged 11 commits from dev into master 2020-02-01 19:11:40 +00:00
2 changed files with 11 additions and 7 deletions
Showing only changes of commit fb9c108c52 - Show all commits

View file

@ -16,6 +16,7 @@ import java.lang.reflect.Array;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import java.util.function.BiFunction;
import java.util.function.Function;
/**
@ -95,16 +96,21 @@ public class ConfigData<T> {
set(def); //Save default value - def is always set
saved = true;
}
BiFunction<Object, Object, Object> convert=(_val, _def) -> {
if (_val instanceof Number && _def != null)
_val = ChromaUtils.convertNumber((Number) _val,
(Class<? extends Number>) _def.getClass());
if (_val instanceof List && _def != null && _def.getClass().isArray())
_val = ((List<T>) _val).toArray((T[]) Array.newInstance(_def.getClass().getComponentType(), 0));
return _val;
};
if (getter != null) {
val = convert.apply(val, primitiveDef);
T hmm = getter.apply(val);
if (hmm == null) hmm = def; //Set if the getter returned null
return hmm;
}
if (val instanceof Number && def != null)
val = ChromaUtils.convertNumber((Number) val,
(Class<? extends Number>) def.getClass());
if (val instanceof List && def != null && def.getClass().isArray())
val = ((List<T>) val).toArray((T[]) Array.newInstance(def.getClass().getComponentType(), 0));
val = convert.apply(val, def);
return value = (T) val; //Always cache, if not cached yet
}

View file

@ -16,7 +16,5 @@
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:3.8.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.projectlombok:lombok:1.18.10" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:3.8.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.projectlombok:lombok:1.18.10" level="project" />
</component>
</module>