add convenience method

This commit is contained in:
Carsten Otto
2023-08-03 16:35:23 +02:00
parent ed2b40a657
commit 260ffd9aba
3 changed files with 16 additions and 6 deletions

View File

@@ -45,12 +45,8 @@ public class NodeWarningsService {
.map(LocalChannel::getRemotePubkey)
.distinct()
.map(pubkey -> new AbstractMap.SimpleEntry<>(pubkey, getNodeWarnings(pubkey)))
.filter(this::hasWarnings)
.filter(entry -> entry.getValue().hasWarnings())
.map(entry -> new AbstractMap.SimpleEntry<>(nodeService.getNode(entry.getKey()), entry.getValue()))
.collect(toMap(Entry::getKey, Entry::getValue));
}
private boolean hasWarnings(Entry<?, NodeWarnings> entry) {
return !entry.getValue().warnings().isEmpty();
}
}

View File

@@ -14,4 +14,8 @@ public record NodeWarnings(Set<NodeWarning> warnings) {
public Set<String> descriptions() {
return warnings.stream().map(NodeWarning::description).collect(Collectors.toSet());
}
public boolean hasWarnings() {
return !warnings.isEmpty();
}
}

View File

@@ -33,4 +33,14 @@ class NodeWarningsTest {
void none() {
assertThat(NodeWarnings.NONE).isEqualTo(new NodeWarnings(Set.of()));
}
}
@Test
void hasWarnings_empty() {
assertThat(NodeWarnings.NONE.hasWarnings()).isFalse();
}
@Test
void hasWarnings_several_warnings() {
assertThat(NODE_WARNINGS.hasWarnings()).isTrue();
}
}