Skip to content

Commit

Permalink
Merge pull request #118 from avaje/feature/keys
Browse files Browse the repository at this point in the history
Add configuration.keys() returning the current keys
  • Loading branch information
SentryMan authored Feb 4, 2024
2 parents 4201562 + d317da9 commit fe26ca9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
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

0 comments on commit fe26ca9

Please sign in to comment.