From fb9c108c52c15b7bf37c2d4c9c8c15b507a0a9da Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sat, 16 Nov 2019 23:18:31 +0100 Subject: [PATCH] Fix long-int conversion (config) Forgot to commit yesterday --- .../lib/architecture/ConfigData.java | 16 +++++++++++----- CorePOM/CorePOM.iml | 2 -- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/ButtonCore/src/main/java/buttondevteam/lib/architecture/ConfigData.java b/ButtonCore/src/main/java/buttondevteam/lib/architecture/ConfigData.java index 2d74f3e..403fcee 100644 --- a/ButtonCore/src/main/java/buttondevteam/lib/architecture/ConfigData.java +++ b/ButtonCore/src/main/java/buttondevteam/lib/architecture/ConfigData.java @@ -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 { set(def); //Save default value - def is always set saved = true; } + BiFunction convert=(_val, _def) -> { + if (_val instanceof Number && _def != null) + _val = ChromaUtils.convertNumber((Number) _val, + (Class) _def.getClass()); + if (_val instanceof List && _def != null && _def.getClass().isArray()) + _val = ((List) _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) def.getClass()); - if (val instanceof List && def != null && def.getClass().isArray()) - val = ((List) val).toArray((T[]) Array.newInstance(def.getClass().getComponentType(), 0)); + val = convert.apply(val, def); return value = (T) val; //Always cache, if not cached yet } diff --git a/CorePOM/CorePOM.iml b/CorePOM/CorePOM.iml index de84cf2..b42e4ee 100644 --- a/CorePOM/CorePOM.iml +++ b/CorePOM/CorePOM.iml @@ -16,7 +16,5 @@ - - \ No newline at end of file