Skip to content

Commit

Permalink
refactor WrappingReportTable
Browse files Browse the repository at this point in the history
  • Loading branch information
vananiev committed Dec 23, 2021
1 parent 64d4f66 commit 90e6735
Showing 1 changed file with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,30 @@ public EagerWrappingReportTable(BrokerReport report, Collection<RowType>... data
}
}

@RequiredArgsConstructor
private static class LazyWrappingReportTable<RowType> implements ReportTable<RowType> {
@Getter
private final BrokerReport report;
private final ReportTable<RowType>[] tables;
private volatile ReportTable<RowType>[] tables;
private volatile List<RowType> data;

@SafeVarargs
private LazyWrappingReportTable(BrokerReport report, ReportTable<RowType>... tables) {
this.report = report;
this.tables = tables;
}

@Override
public List<RowType> getData() {
if (data == null) {
data = Arrays.stream(tables)
.map(ReportTable::getData)
.flatMap(Collection::stream)
.collect(Collectors.toUnmodifiableList());
synchronized (this) {
if (data == null) {
data = Arrays.stream(tables)
.map(ReportTable::getData)
.flatMap(Collection::stream)
.collect(Collectors.toUnmodifiableList());
tables = null; // erase for GC
}
}
}
return data;
}
Expand Down

0 comments on commit 90e6735

Please sign in to comment.