Skip to content

Commit

Permalink
Merge pull request #50 from SentryMan/func
Browse files Browse the repository at this point in the history
Use Int/Long Consumer
  • Loading branch information
rbygrave authored Feb 15, 2023
2 parents def5c1f + ede36e3 commit a282ff2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/main/java/io/avaje/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -424,7 +426,7 @@ public static void onChange(String key, Consumer<String> 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<Integer> callback) {
public static void onChangeInt(String key, IntConsumer callback) {
data.onChangeInt(key, callback);
}

Expand All @@ -434,7 +436,7 @@ public static void onChangeInt(String key, Consumer<Integer> 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<Long> callback) {
public static void onChangeLong(String key, LongConsumer callback) {
data.onChangeLong(key, callback);
}

Expand Down
7 changes: 5 additions & 2 deletions src/main/java/io/avaje/config/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -306,15 +308,15 @@ 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<Integer> callback);
void onChangeInt(String key, IntConsumer callback);

/**
* Register a callback for a change to the given configuration key as an Long value.
*
* @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<Long> callback);
void onChangeLong(String key, LongConsumer callback);

/**
* Register a callback for a change to the given configuration key as an Boolean value.
Expand Down Expand Up @@ -498,4 +500,5 @@ interface SetValue {
*/
Set<Long> ofLong(String key, long... defaultValues);
}

}
6 changes: 4 additions & 2 deletions src/main/java/io/avaje/config/CoreConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -280,12 +282,12 @@ public void onChange(String key, Consumer<String> callback) {
}

@Override
public void onChangeInt(String key, Consumer<Integer> callback) {
public void onChangeInt(String key, IntConsumer callback) {
onChange(key).register(newValue -> callback.accept(Integer.parseInt(newValue)));
}

@Override
public void onChangeLong(String key, Consumer<Long> callback) {
public void onChangeLong(String key, LongConsumer callback) {
onChange(key).register(newValue -> callback.accept(Long.parseLong(newValue)));
}

Expand Down

0 comments on commit a282ff2

Please sign in to comment.