Skip to content

Commit

Permalink
Added a Registry.find() (ReactiveX#478)
Browse files Browse the repository at this point in the history
Add find() method that will only return an existing object in a Registry
but will not create a new one.
  • Loading branch information
KingMob authored and RobWin committed May 30, 2019
1 parent fb143f3 commit 82a1f43
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ public interface Registry<E, C> {
*/
void addConfiguration(String configName, C configuration);

/**
* Find a named entry in the Registry
*
* @param name the name
*/
Optional<E> find(String name);

/**
* Remove an entry from the Registry
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ protected E computeIfAbsent(String name, Supplier<E> supplier){
});
}

@Override
public Optional<E> find(String name){
return Optional.ofNullable(entryMap.get(name));
}

@Override
public Optional<E> remove(String name){
Optional<E> removedEntry = Optional.ofNullable(entryMap.remove(name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ public void shouldConsumeRegistryEvents() {

}

@Test
public void shouldOnlyFindRegisteredObjects() {
TestRegistry testRegistry = new TestRegistry();

assertThat(testRegistry.find("test")).isEmpty();
testRegistry.entryMap.put("test", "value");
assertThat(testRegistry.find("test")).contains("value");
}


class TestRegistry extends AbstractRegistry<String, String> {

public TestRegistry() {
Expand All @@ -85,4 +95,4 @@ public TestRegistry() {
}
}

}
}

0 comments on commit 82a1f43

Please sign in to comment.