diff --git a/src/main/java/io/avaje/config/Config.java b/src/main/java/io/avaje/config/Config.java index 6320095..23039ce 100644 --- a/src/main/java/io/avaje/config/Config.java +++ b/src/main/java/io/avaje/config/Config.java @@ -7,6 +7,8 @@ import java.util.Optional; import java.util.Properties; import java.util.function.Consumer; +import java.util.function.IntConsumer; +import java.util.function.LongConsumer; import io.avaje.applog.AppLog; @@ -424,7 +426,7 @@ public static void onChange(String key, Consumer callback) { * @param key The configuration key we want to detect changes to * @param callback The callback handling to fire when the configuration changes. */ - public static void onChangeInt(String key, Consumer callback) { + public static void onChangeInt(String key, IntConsumer callback) { data.onChangeInt(key, callback); } @@ -434,7 +436,7 @@ public static void onChangeInt(String key, Consumer callback) { * @param key The configuration key we want to detect changes to * @param callback The callback handling to fire when the configuration changes. */ - public static void onChangeLong(String key, Consumer callback) { + public static void onChangeLong(String key, LongConsumer callback) { data.onChangeLong(key, callback); } diff --git a/src/main/java/io/avaje/config/Configuration.java b/src/main/java/io/avaje/config/Configuration.java index 70cb51a..7c69c86 100644 --- a/src/main/java/io/avaje/config/Configuration.java +++ b/src/main/java/io/avaje/config/Configuration.java @@ -9,6 +9,8 @@ import java.util.Properties; import java.util.Set; import java.util.function.Consumer; +import java.util.function.IntConsumer; +import java.util.function.LongConsumer; /** * Configuration API for accessing property values and registering onChange listeners. @@ -306,7 +308,7 @@ default SetValue getSet() { * @param key The configuration key we want to detect changes to * @param callback The callback handling to fire when the configuration changes. */ - void onChangeInt(String key, Consumer callback); + void onChangeInt(String key, IntConsumer callback); /** * Register a callback for a change to the given configuration key as an Long value. @@ -314,7 +316,7 @@ default SetValue getSet() { * @param key The configuration key we want to detect changes to * @param callback The callback handling to fire when the configuration changes. */ - void onChangeLong(String key, Consumer callback); + void onChangeLong(String key, LongConsumer callback); /** * Register a callback for a change to the given configuration key as an Boolean value. @@ -498,4 +500,5 @@ interface SetValue { */ Set ofLong(String key, long... defaultValues); } + } diff --git a/src/main/java/io/avaje/config/CoreConfiguration.java b/src/main/java/io/avaje/config/CoreConfiguration.java index 3d25f9d..6fc762b 100644 --- a/src/main/java/io/avaje/config/CoreConfiguration.java +++ b/src/main/java/io/avaje/config/CoreConfiguration.java @@ -9,6 +9,8 @@ import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Consumer; +import java.util.function.IntConsumer; +import java.util.function.LongConsumer; /** * Core implementation of Configuration. @@ -280,12 +282,12 @@ public void onChange(String key, Consumer callback) { } @Override - public void onChangeInt(String key, Consumer callback) { + public void onChangeInt(String key, IntConsumer callback) { onChange(key).register(newValue -> callback.accept(Integer.parseInt(newValue))); } @Override - public void onChangeLong(String key, Consumer callback) { + public void onChangeLong(String key, LongConsumer callback) { onChange(key).register(newValue -> callback.accept(Long.parseLong(newValue))); }