Skip to content

Commit

Permalink
Use lazy iterables instead of streams
Browse files Browse the repository at this point in the history
  • Loading branch information
mwilliamson committed Jun 10, 2024
1 parent 67267f1 commit dad0679
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/main/java/org/zwobble/mammoth/internal/docx/Numbering.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.zwobble.mammoth.internal.docx;

import org.zwobble.mammoth.internal.documents.NumberingLevel;
import org.zwobble.mammoth.internal.util.Iterables;
import org.zwobble.mammoth.internal.util.Maps;

import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;

import static org.zwobble.mammoth.internal.util.Maps.lookup;
import static org.zwobble.mammoth.internal.util.Maps.map;
Expand Down Expand Up @@ -66,10 +67,16 @@ public Numbering(
Styles styles
) {
this.abstractNums = abstractNums;
this.levelsByParagraphStyleId = abstractNums.values().stream()
.flatMap(abstractNum -> abstractNum.levels.values().stream())
.filter(level -> level.paragraphStyleId.isPresent())
.collect(Collectors.toMap(level -> level.paragraphStyleId.get(), level -> level));
this.levelsByParagraphStyleId = Maps.toMapWithKey(
Iterables.lazyFilter(
Iterables.lazyFlatMap(
abstractNums.values(),
abstractNum -> abstractNum.levels.values()
),
level -> level.paragraphStyleId.isPresent()
),
level -> level.paragraphStyleId.get()
);
this.nums = nums;
this.styles = styles;
}
Expand Down

0 comments on commit dad0679

Please sign in to comment.