| 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 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (33) |
Complexity: 7 |
Complexity Density: 0.3 |
|
| 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 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
| 25 |
10 |
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 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 39 |
11 |
int getNumberOfRows()... |
| 40 |
|
{ |
| 41 |
11 |
init(); |
| 42 |
11 |
return numberOfRows; |
| 43 |
|
} |
| 44 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 3 |
Complexity Density: 0.23 |
|
| 45 |
17 |
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 |
|
|
| 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 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 82 |
6 |
Supplier<T> buildLazySupplier()... |
| 83 |
|
{ |
| 84 |
6 |
return lazySupplier( |
| 85 |
|
() -> { |
| 86 |
6 |
init(); |
| 87 |
6 |
return RoundRobinValueSupplier.of(values); |
| 88 |
|
} |
| 89 |
|
); |
| 90 |
|
} |
| 91 |
|
} |