Skip to content

Instantly share code, notes, and snippets.

View vi6six's full-sized avatar

vi_six vi6six

View GitHub Profile
@vi6six
vi6six / Java 8 streams
Last active January 23, 2024 18:17
Java 8 streams Map of maps transformation
private static void checkTreesForMissingDefinitions(Map<String, String> glossary) {
FinancialTrees.getTrees(false).values().stream() // Map<IndustryTemplate, Map<FinancialGroup, FinancialTree>>
.map(Map::values) // Stream<Collection<FinancialTree>>
.flatMap(Collection::stream) // Stream<FinancialTree>
.map(FinancialTree::getAllChildren) // Stream<List<FinancialTreeNode>> Get nodes fron tree as a List<Node>
.flatMap(List::stream) // Stream<FinancialTreeNode>
.map(FinancialTreeNode::getField) // Stream<FinField>
.distinct() // remove duplicated fields
.filter(Objects::nonNull) // remove null objects