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

[CONNECTOR] Fix some issues in connector #1487

Merged
merged 11 commits into from
Feb 12, 2023
12 changes: 6 additions & 6 deletions common/src/main/java/org/astraea/common/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,17 @@ default String requireString(String key) {
}

/**
* @param filteredString the string to be filtered and removed
* @return new Configuration only contains which the key value includes the filteredString, and
* the filteredString and the following dot will be removed from the key
* @param prefix the string to be filtered and removed
* @return new Configuration only contains which the key value starts with the prefix, and the
* prefix string and the following dot will be removed from the key
*/
default Configuration filteredConfigs(String filteredString) {
default Configuration filteredConfigs(String prefix) {
return of(
entrySet().stream()
.filter(k -> k.getKey().contains(filteredString))
.filter(k -> k.getKey().startsWith(prefix))
.collect(
Collectors.toMap(
i -> i.getKey().replaceAll(filteredString + '.', ""), Map.Entry::getValue)));
i -> i.getKey().replaceFirst(prefix + '.', ""), Map.Entry::getValue)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void testMap() {

@Test
void testFilteredConfigs() {
var config = Configuration.of(Map.of("key", "v1", "filtered.key", "v2"));
var config = Configuration.of(Map.of("key", "v1", "filtered.key", "v2", "key.filtered", "v3"));
Assertions.assertEquals(Map.of("key", "v2"), config.filteredConfigs("filtered").raw());
}
}