Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configuration.keys() returning the current keys #118

Merged
merged 1 commit into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions avaje-config/src/main/java/io/avaje/config/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,11 @@ default boolean enabled(String key, boolean enabledDefault) {
*/
void reloadSources();

/**
* Return the property keys in this configuration.
*/
Set<String> keys();

/**
* Return the number of configuration properties.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ public Configuration forPath(String pathPrefix) {
return new CoreConfiguration(this, newEntryMap, dotPrefix);
}

@Override
public Set<String> keys() {
return properties.entries.keys();
}

@Override
public ListValue list() {
return listValue;
Expand Down
4 changes: 4 additions & 0 deletions avaje-config/src/main/java/io/avaje/config/CoreEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ private boolean putIfChanged(String key, String value, String source) {
return false;
}

Set<String> keys() {
return entryMap.keySet();
}

boolean containsKey(String key) {
return entryMap.containsKey(key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ void forPath() {
CoreConfiguration base = createSample();
Configuration foo = base.forPath("foo");

assertThat(foo.keys()).contains("bar", "t", "f");
assertThat(foo.size()).isEqualTo(3);
assertThat(foo.getInt("bar")).isEqualTo(42);
assertThat(foo.getBool("t")).isTrue();
Expand Down
Loading