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

File KeySupplierOfInt.java

 

Coverage histogram

../../../../img/srcFileCovDistChart9.png
53% of files have more coverage

Code metrics

4
29
11
1
128
77
13
0.45
2.64
11
1.18

Classes

Class Line # Actions
KeySupplierOfInt 10 29 0% 13 8
0.818181881.8%
 

Contributing tests

This file is covered by 23 tests. .

Source view

1    package guru.mikelue.foxglove.jdbc;
2   
3    import java.util.function.LongSupplier;
4   
5    import guru.mikelue.foxglove.functional.StatefulSupplier;
6   
7    /**
8    * Suppliers integral values with limiting number of generated values;
9    */
 
10    final class KeySupplierOfInt implements StatefulSupplier<Long> {
11    private int generatedCounter = 0;
12   
13    private long currentValue;
14    private final long step;
15    private final int limit;
16   
17    private long[] domain = null;
18    private final LongSupplier valueGetter;
19    private final int numberOfRows;
20   
21    /**
22    * Creates the supplier by specifying the range of values.
23    *
24    * @param currentValue The start value(inclusive)
25    * @param end The end value(exclusive)
26    * @param step The step value
27    *
28    * @return The created supplier
29    */
 
30  7 toggle static KeySupplierOfInt byRange(long currentValue, long end, int step)
31    {
32  7 return new KeySupplierOfInt(currentValue, (int)((end - currentValue) / step), step);
33    }
34   
35    /**
36    * Creates the supplier by specifying the maximum amount of values.
37    *
38    * @param currentValue The start value(inclusive)
39    * @param limit The maximum amount of values
40    * @param step The step value
41    *
42    * @return The created supplier
43    */
 
44  20 toggle static KeySupplierOfInt byLimit(long currentValue, int limit, int step)
45    {
46  20 return new KeySupplierOfInt(currentValue, limit, step);
47    }
48   
49    /**
50    * Creates the supplier by specifying the domain of values.
51    *
52    * @param domain The domain of values
53    *
54    * @return The created supplier
55    */
 
56  4 toggle static KeySupplierOfInt of(long[] domain)
57    {
58  4 return new KeySupplierOfInt(domain);
59    }
60   
 
61  27 toggle private KeySupplierOfInt(long currentValue, int limit, int step)
62    {
63  27 this.currentValue = currentValue;
64  27 this.limit = limit;
65  27 this.step = step;
66   
67  27 this.valueGetter = this::nextValueByRange;
68  27 this.numberOfRows = limit;
69    }
70   
 
71  4 toggle private KeySupplierOfInt(long[] domain)
72    {
73  4 this.currentValue = 0;
74  4 this.limit = -1;
75  4 this.step = 0;
76   
77  4 this.valueGetter = this::nextValueByDomain;
78  4 this.domain = domain;
79  4 this.numberOfRows = domain.length;
80    }
81   
 
82  19 toggle int getNumberOfRows()
83    {
84  19 return numberOfRows;
85    }
86   
 
87  0 toggle long nextValue()
88    {
89  0 return valueGetter.getAsLong();
90    }
91   
 
92  0 toggle long lastValue()
93    {
94  0 return currentValue;
95    }
96   
 
97  134 toggle @Override
98    public Long get()
99    {
100  134 return valueGetter.getAsLong();
101    }
102   
 
103  35 toggle private long nextValueByDomain()
104    {
105  35 if (generatedCounter >= domain.length) {
106  0 throw new IllegalStateException("Exceeds maximum amount[" + domain.length + "] of keys");
107    }
108   
109  35 long nextValue = domain[generatedCounter];
110  35 generatedCounter++;
111   
112  35 return nextValue;
113    }
114   
 
115  99 toggle private long nextValueByRange()
116    {
117  99 if (generatedCounter >= limit) {
118  0 throw new IllegalStateException("Exceeds maximum amount[" + limit + "] of keys");
119    }
120   
121  99 long nextValue = currentValue;
122   
123  99 currentValue += step;
124  99 generatedCounter++;
125   
126  99 return nextValue;
127    }
128    }