|
23 | 23 | import java.util.function.BiConsumer;
|
24 | 24 | import java.util.function.BiFunction;
|
25 | 25 | import java.util.function.BinaryOperator;
|
26 |
| -import java.util.function.Function; |
27 | 26 | import java.util.function.Predicate;
|
28 | 27 | import java.util.stream.Stream;
|
29 | 28 | import java.util.stream.StreamSupport;
|
@@ -482,6 +481,7 @@ class ColumnInfos {
|
482 | 481 |
|
483 | 482 | private final AggregatePath basePath;
|
484 | 483 | private final Map<AggregatePath, ColumnInfo> columnInfos;
|
| 484 | + private final Map<Table, List<Column>> columnCache = new HashMap<>(); |
485 | 485 |
|
486 | 486 | /**
|
487 | 487 | * Creates a new ColumnInfos instances based on the arguments.
|
@@ -542,18 +542,19 @@ public boolean isEmpty() {
|
542 | 542 | }
|
543 | 543 |
|
544 | 544 | /**
|
545 |
| - * Applies a function to all the {@link ColumnInfo} instances and returns the result in a list. |
| 545 | + * Converts the given {@link Table} into a list of {@link Column}s. This method retrieves and caches the list of |
| 546 | + * columns for the specified table. If the columns are not already cached, it computes the list by mapping |
| 547 | + * {@code columnInfos} to their corresponding {@link Column} in the provided table and then stores the result in the |
| 548 | + * cache. |
546 | 549 | *
|
547 |
| - * @param mapper the function to be applied |
548 |
| - * @param <T> the type returned by {@literal mapper} and contained in the resulting {@literal List} |
549 |
| - * @return the list of results from mapper. |
| 550 | + * @param table the {@link Table} for which the columns should be generated; must not be {@literal null}. |
| 551 | + * @return a list of {@link Column}s associated with the specified {@link Table}. Guaranteed no to be |
| 552 | + * {@literal null}. |
550 | 553 | */
|
551 |
| - public <T> List<T> toList(Function<ColumnInfo, T> mapper) { |
552 |
| - return columnInfos.values().stream().map(mapper).toList(); |
553 |
| - } |
554 |
| - |
555 | 554 | public List<Column> toColumnList(Table table) {
|
556 |
| - return toList(columnInfo -> table.column(columnInfo.name)); |
| 555 | + |
| 556 | + return columnCache.computeIfAbsent(table, |
| 557 | + t -> columnInfos.values().stream().map(columnInfo -> t.column(columnInfo.name)).toList()); |
557 | 558 | }
|
558 | 559 |
|
559 | 560 | /**
|
|
0 commit comments