1. Project Clover database Fri Jul 17 2026 06:10:26 UTC
  2. Package guru.mikelue.foxglove.jdbc

File ColumnSettingSteps.java

 

Coverage histogram

../../../../img/srcFileCovDistChart6.png
80% of files have more coverage

Code metrics

0
22
11
7
424
108
11
0.5
2
1.57
1

Classes

Class Line # Actions
ColumnSettingSteps 21 0 - 0 0
-1.0 -
ColumnSettingSteps.ColumnSimpleStep 30 4 0% 2 3
0.550%
ColumnSettingSteps.ColumnFromStep 115 0 - 0 0
-1.0 -
ColumnSettingSteps.ReferenceSettingStep 150 0 - 0 0
-1.0 -
ColumnSettingSteps.ReferenceSettingStep.CardinalityStep 154 0 - 0 0
-1.0 -
ColumnSettingSteps.KeyOfIntSettingStep 201 10 0% 7 10
0.411764741.2%
ColumnSettingSteps.CartesianProductSettingStep 369 8 0% 2 3
0.770%
 

Contributing tests

This file is covered by 28 tests. .

Source view

1    package guru.mikelue.foxglove.jdbc;
2   
3    import org.apache.commons.lang3.Validate;
4   
5    import java.util.ArrayList;
6    import java.util.List;
7    import java.util.function.Function;
8    import java.util.stream.LongStream;
9    import java.util.stream.Stream;
10   
11    import guru.mikelue.foxglove.functional.Int4SequenceSupplier;
12    import guru.mikelue.foxglove.functional.Int8SequenceSupplier;
13    import guru.mikelue.foxglove.functional.RowIndexToValue;
14    import guru.mikelue.foxglove.functional.SequenceSupplier;
15    import guru.mikelue.foxglove.jdbc.JdbcTableFacet.Builder;
16    import guru.mikelue.foxglove.setting.ColumnConfig;
17   
18    /**
19    * Aggregation of steps for column setting steps.
20    */
 
21    public interface ColumnSettingSteps {
22    /**
23    * The step to configure column.
24    *
25    * <p>
26    * This interface supports same methods as {@link ColumnConfig}.
27    *
28    * @param <T> The type of value generated for the column
29    */
 
30    public interface ColumnSimpleStep<T> extends ColumnConfig<T, Builder> {
31    /**
32    * Uses a function that converts row index to value.
33    *
34    * @param rowIndexToValue The function that converts row index to value
35    *
36    * @return The builder for {@link JdbcTableFacet}
37    */
38    Builder forRow(RowIndexToValue<? extends T> rowIndexToValue);
39   
40    /**
41    * Uses a fixed value for the column.
42    *
43    * @param fixedValue The fixed value
44    *
45    * @return The builder for {@link JdbcTableFacet}
46    */
47    Builder fixed(T fixedValue);
48   
49    /**
50    * Configures the column to get values from another table's column.
51    *
52    * <p>
53    * This is differ from {@link JdbcTableFacet.Builder#referencing(String)} in that
54    * the number of rows is not affected by this configuration.
55    *
56    * @param referencedTable The referenced table facet
57    * @param referencedColumn The column name of referenced in referenced table
58    *
59    * @return The step to configure column from another table
60    */
61    ColumnFromStep<T> from(JdbcTableFacet referencedTable, String referencedColumn);
62   
63    /**
64    * Generates data by round-robin of values.
65    *
66    * @param values The values
67    *
68    * @return The builder for {@link JdbcTableFacet}
69    *
70    * @see #roundRobin(List)
71    */
72    @SuppressWarnings("unchecked")
73    Builder roundRobin(T... values);
74   
75    /**
76    * Generates data by round-robin of values.
77    *
78    * @param domain The stream of values
79    *
80    * @return The builder for {@link JdbcTableFacet}
81    *
82    * @see #roundRobin(List)
83    */
 
84  0 toggle @SuppressWarnings("unchecked")
85    default Builder roundRobin(Stream<? extends T> domain)
86    {
87  0 Validate.notNull(domain, "Domain stream must not be null");
88   
89  0 return roundRobin((T[])domain.toArray());
90    };
91   
92    /**
93    * Generates data by round-robin of values.
94    *
95    * @param values The list of values
96    *
97    * @return The builder for {@link JdbcTableFacet}
98    *
99    * @see #roundRobin(Object...)
100    */
 
101  4 toggle @SuppressWarnings("unchecked")
102    default Builder roundRobin(List<? extends T> values)
103    {
104  4 Validate.notNull(values, "Domain stream must not be null");
105   
106  4 return roundRobin((T[])values.toArray());
107    }
108    }
109   
110    /**
111    * The step to configure column from another table.
112    *
113    * @param <T> The type of value generated for the column
114    */
 
115    public interface ColumnFromStep<T> {
116    /**
117    * Transforms the domain of referenced column to another domain values.
118    *
119    * @param <V> The type to which the value of referencing column is converted
120    * @param domainConverter The function to convert stream of values
121    *
122    * @return The step to configure column from another table
123    */
124    <V> ColumnFromStep<V> transformDomain(Function<? super Stream<T>, ? extends Stream<V>> domainConverter);
125   
126    /**
127    * Uses round-robin strategy to assign values from referenced column of another table.
128    *
129    * @return The builder for {@link JdbcTableFacet}
130    *
131    * @see #random()
132    */
133    Builder roundRobin();
134   
135    /**
136    * Uses random choosing over values from referenced column of another table.
137    *
138    * @return The builder for {@link JdbcTableFacet}
139    *
140    * @see #roundRobin()
141    */
142    Builder random();
143    }
144   
145    /**
146    * The step to configure reference column.
147    *
148    * @param <T> The type of value generated for the column
149    */
 
150    public interface ReferenceSettingStep<T> {
151    /**
152    * The step to configure cardinality of reference.
153    */
 
154    public interface CardinalityStep {
155    /**
156    * Sets the number of rows in child table per one row in parent table.
157    *
158    * @param numberOfChildrenPerParent The number of rows in child table. At least 1.
159    *
160    * @return The builder for {@link JdbcTableFacet}
161    */
162    Builder cardinality(int numberOfChildrenPerParent);
163   
164    /**
165    * Makes the number of rows is generated randomly in child table per one row in parent table.
166    *
167    * @param min The minimum number of rows in child table, At least 0.
168    * @param max The maximum number of rows in child table
169    *
170    * @return The builder for {@link JdbcTableFacet}
171    */
172    Builder cardinality(int min, int max);
173    }
174   
175    /**
176    * Assigns the key column explicitly.
177    *
178    * @param parentTable The parent table facet
179    * @param referencedColumn The column name of referenced in parent table
180    *
181    * @return The next step to configure reference column
182    */
183    CardinalityStep parent(JdbcTableFacet parentTable, String referencedColumn);
184    }
185   
186    /**
187    * The step used to limit the number of rows by
188    * bounding integral value for a column,
189    *
190    * <p>
191    * <em>This interface is not about uniqueness,
192    * is about to assign number of rows.</em>
193    *
194    * If what you need only integral sequence for a column,
195    * just use {@link Builder#column(String)} with {@link Int4SequenceSupplier}, etc.
196    *
197    * @see SequenceSupplier
198    * @see Int4SequenceSupplier
199    * @see Int8SequenceSupplier
200    */
 
201    public interface KeyOfIntSettingStep {
202    /**
203    * Sets the range of values for key column(starts with 1, step 1).
204    *
205    * @param end The end value (exclusive)
206    *
207    * @return The builder for {@link JdbcTableFacet}
208    *
209    * @see #range(long, long)
210    * @see #limit(int)
211    */
 
212  0 toggle default Builder range(long end)
213    {
214  0 return range(1, end, 1);
215    }
216   
217    /**
218    * Sets the range of values for key column(with step 1).
219    *
220    * @param start The start value (inclusive)
221    * @param end The end value (exclusive)
222    *
223    * @return The builder for {@link JdbcTableFacet}
224    *
225    * @see #range(long, long, int)
226    * @see #limit(long, int)
227    */
 
228  4 toggle default Builder range(long start, long end)
229    {
230  4 return range(start, end, 1);
231    }
232   
233    /**
234    * Sets the range of values for key column.
235    *
236    * @param start The start value (inclusive)
237    * @param end The end value (exclusive)
238    * @param step The step value
239    *
240    * @return The builder for {@link JdbcTableFacet}
241    *
242    * @see #range(long)
243    * @see #range(long, long)
244    * @see #limit(long, int, int)
245    */
246    Builder range(long start, long end, int step);
247   
248    /**
249    * Sets the limit number of values can be generated for key column(starts with 1, steps with 1).
250    *
251    * @param number The number of values can be generated
252    *
253    * @return The builder for {@link JdbcTableFacet}
254    *
255    * @see #limit(long, int)
256    * @see #range(long)
257    */
 
258  0 toggle default Builder limit(int number)
259    {
260  0 return limit(1, number, 1);
261    }
262   
263    /**
264    * Sets the limit number of values can be generated for key column(steps with 1).
265    *
266    * @param start The start value
267    * @param number The number of values can be generated
268    *
269    * @return The builder for {@link JdbcTableFacet}
270    *
271    * @see #limit(long, int, int)
272    * @see #range(long, long)
273    */
 
274  17 toggle default Builder limit(long start, int number)
275    {
276  17 return limit(start, number, 1);
277    }
278   
279    /**
280    * Sets the limit number of values can be generated for key column.
281    *
282    * @param start The start value
283    * @param number The number of values can be generated
284    * @param step The step value
285    *
286    * @return The builder for {@link JdbcTableFacet}
287    *
288    * @see #limit(int)
289    * @see #limit(long, int)
290    * @see #range(long, long, int)
291    */
292    Builder limit(long start, int number, int step);
293   
294    /**
295    * Sets the domain of numbers to be used for key column.
296    *
297    * @param domain The list of values
298    *
299    * @return The builder for {@link JdbcTableFacet}
300    *
301    * @see #range(long, long, int)
302    * @see #limit(long, int, int)
303    */
 
304  0 toggle default Builder domain(Stream<Long> domain)
305    {
306  0 Validate.notNull(domain, "Domain stream must not be null");
307   
308  0 return domain(
309    domain.mapToLong(Long::longValue)
310    .toArray()
311    );
312    }
313   
314    /**
315    * Sets the domain of numbers to be used for key column.
316    *
317    * @param domain The list of values
318    *
319    * @return The builder for {@link JdbcTableFacet}
320    *
321    * @see #range(long, long, int)
322    * @see #limit(long, int, int)
323    */
 
324  3 toggle default Builder domain(List<Long> domain)
325    {
326  3 Validate.noNullElements(domain, "Domain list must not have null element");
327   
328  3 return domain(
329    domain.stream().mapToLong(Long::longValue)
330    .toArray()
331    );
332    }
333   
334    /**
335    * Sets the set of number of values to be used for key column.
336    *
337    * @param domain The list of values
338    *
339    * @return The builder for {@link JdbcTableFacet}
340    *
341    * @see #range(long, long, int)
342    * @see #limit(long, int, int)
343    */
 
344  0 toggle default Builder domain(LongStream domain)
345    {
346  0 Validate.notNull(domain, "Domain stream must not be null");
347   
348  0 return domain(domain.toArray());
349    }
350   
351    /**
352    * Sets the set of number of values to be used for key column.
353    *
354    * @param domain The list of values
355    *
356    * @return The builder for {@link JdbcTableFacet}
357    *
358    * @see #range(long, long, int)
359    * @see #limit(long, int, int)
360    */
361    Builder domain(long[] domain);
362    }
363   
364    /**
365    * The step to configure Cartesian product for a column.
366    *
367    * @param <T> The type of value generated for the column
368    */
 
369    public interface CartesianProductSettingStep<T> {
370    /**
371    * Sets the domain of values for Cartesian product.
372    *
373    * @param values The values to use
374    *
375    * @return The builder for {@link JdbcTableFacet}
376    */
 
377  12 toggle @SuppressWarnings("unchecked")
378    default Builder domain(T... values)
379    {
380  12 Validate.notEmpty(values, "Rest values must not have null element");
381  12 Validate.noNullElements(values, "Rest values must not have null element");
382   
383  12 var allValues = new ArrayList<T>(values.length);
384  12 for (var value : values) {
385  31 allValues.add(value);
386    }
387   
388  12 return domain(allValues);
389    }
390   
391    /**
392    * Sets the domain of values for Cartesian product.
393    *
394    * @param domain The stream of values
395    *
396    * @return The builder for {@link JdbcTableFacet}
397    */
 
398  0 toggle default Builder domain(Stream<? extends T> domain)
399    {
400  0 Validate.notNull(domain, "Domain stream must not be null");
401   
402  0 return domain(domain.toList());
403    }
404   
405    /**
406    * Sets the domain of values for Cartesian product.
407    *
408    * @param values The list of values
409    *
410    * @return The builder for {@link JdbcTableFacet}
411    */
412    Builder domain(List<? extends T> values);
413   
414    /**
415    * References values from column of another table's for Cartesian product.
416    *
417    * @param referencedTable The referenced table facet
418    * @param referencedColumn The column name of referenced in referenced table
419    *
420    * @return The builder for {@link JdbcTableFacet}
421    */
422    Builder referencing(JdbcTableFacet referencedTable, String referencedColumn);
423    }
424    }