Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ public void testSet() throws Exception {
assertThat(later.read(), hasItems("C", "D"));
assertFalse(later.contains("A").read());

value.remove("B");
value.remove("C");
value.remove("D");
assertTrue(value.isEmpty().read());

// clear
value.clear();
assertThat(value.read(), Matchers.emptyIterable());
Expand Down Expand Up @@ -389,6 +394,11 @@ public void testMap() throws Exception {
// isEmpty
assertFalse(value.isEmpty().read());

value.remove("B");
value.remove("D");
value.remove("E");
assertTrue(value.isEmpty().read());

// clear
value.clear();
assertThat(value.entries().read(), Matchers.emptyIterable());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,11 @@ private Map<MapKeyT, MapValueT> readAsMap() {
public void remove(MapKeyT key) {
Map<MapKeyT, MapValueT> sparkMapState = readAsMap();
sparkMapState.remove(key);
writeValue(sparkMapState);
if (sparkMapState.isEmpty()) {
clear();
} else {
writeValue(sparkMapState);
}
}

@Override
Expand Down Expand Up @@ -537,7 +541,11 @@ public ReadableState<Boolean> addIfAbsent(InputT input) {
public void remove(InputT input) {
Set<InputT> sparkSetState = readAsSet();
sparkSetState.remove(input);
writeValue(sparkSetState);
if (sparkSetState.isEmpty()) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: redundancy of the code can be improved using Collection Generic

clear();
} else {
writeValue(sparkSetState);
}
}

@Override
Expand Down
Loading