Skip to content

Commit 64d4f66

Browse files
committed
refactor WrappingReportTable
1 parent 5cbd28e commit 64d4f66

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/main/java/org/spacious_team/broker/report_parser/api/WrappingReportTable.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.Collection;
2828
import java.util.Collections;
2929
import java.util.List;
30+
import java.util.stream.Collectors;
3031

3132
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
3233
public class WrappingReportTable<RowType> implements ReportTable<RowType> {
@@ -85,14 +86,17 @@ private static class LazyWrappingReportTable<RowType> implements ReportTable<Row
8586
@Getter
8687
private final BrokerReport report;
8788
private final ReportTable<RowType>[] tables;
89+
private volatile List<RowType> data;
8890

8991
@Override
9092
public List<RowType> getData() {
91-
List<RowType> data = new ArrayList<>();
92-
for (ReportTable<RowType> table : tables) {
93-
data.addAll(table.getData());
93+
if (data == null) {
94+
data = Arrays.stream(tables)
95+
.map(ReportTable::getData)
96+
.flatMap(Collection::stream)
97+
.collect(Collectors.toUnmodifiableList());
9498
}
95-
return Collections.unmodifiableList(data);
99+
return data;
96100
}
97101
}
98102
}

0 commit comments

Comments
 (0)