1. Project Clover database Wed Nov 12 2025 05:07:35 UTC
  2. Package guru.mikelue.foxglove.jdbc

File CardinalityInfo.java

 

Coverage histogram

../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

6
23
4
1
91
68
7
0.3
5.75
4
1.75

Classes

Class Line # Actions
CardinalityInfo 15 23 0% 7 0
1.0100%
 

Contributing tests

This file is covered by 9 tests. .

Source view

1    package guru.mikelue.foxglove.jdbc;
2   
3    import java.util.ArrayList;
4    import java.util.List;
5    import java.util.function.Supplier;
6   
7    import org.instancio.Instancio;
8    import org.slf4j.Logger;
9    import org.slf4j.LoggerFactory;
10   
11    import guru.mikelue.foxglove.functional.RoundRobinValueSupplier;
12   
13    import static guru.mikelue.foxglove.functional.Suppliers.lazySupplier;
14   
 
15    class CardinalityInfo<T> {
16    private final Logger logger = LoggerFactory.getLogger(ReferenceSettingStepImpl.class);
17   
18    private final String columnName;
19    private final Supplier<Integer> numberPerParent;
20    private final ValueTomb valueTomb;
21   
22    private List<T> values = null;
23    private int numberOfRows = -1;
24   
 
25  10 toggle CardinalityInfo(
26    int min, int max,
27    JdbcTableFacet table, String columnName
28    ) {
29  10 this.valueTomb = table.getValueTomb();
30  10 this.columnName = columnName;
31   
32  10 if (min == max) {
33  8 this.numberPerParent = () -> min;
34    } else {
35  2 this.numberPerParent = () -> Instancio.gen().ints().range(min, max).get();
36    }
37    }
38   
 
39  11 toggle int getNumberOfRows()
40    {
41  11 init();
42  11 return numberOfRows;
43    }
44   
 
45  17 toggle private void init()
46    {
47  17 if (this.values != null) {
48  7 return;
49    }
50   
51  10 var sourceValues = valueTomb.<T>getValues(columnName);
52  10 this.values = new ArrayList<>(sourceValues.size());
53   
54  10 logger.debug(
55    "Setting up reference values for column[{}]. Parent size[{}].",
56    columnName, sourceValues.size()
57    );
58   
59    /*
60    * Builds the list of values by cardinality number
61    */
62  10 int newNumberOfRows = 0;
63  10 for (var sourceValue: sourceValues) {
64  64 int numberOfChildren = numberPerParent.get();
65   
66  64 logger.trace(
67    "Put value[{}]. Size per parent[{}].",
68    columnName, numberOfChildren
69    );
70   
71  276 for (int i = 0; i < numberOfChildren; i++) {
72  212 this.values.add(sourceValue);
73    }
74   
75  64 newNumberOfRows += numberOfChildren;
76    }
77   
78  10 this.numberOfRows = newNumberOfRows;
79    // :~)
80    }
81   
 
82  6 toggle Supplier<T> buildLazySupplier()
83    {
84  6 return lazySupplier(
85    () -> {
86  6 init();
87  6 return RoundRobinValueSupplier.of(values);
88    }
89    );
90    }
91    }