55import lombok .NonNull ;
66
77import java .math .BigDecimal ;
8+ import java .math .BigInteger ;
89import java .util .HashMap ;
910import java .util .Map ;
1011import java .util .Random ;
@@ -16,6 +17,12 @@ public class BiggerThanValueSource implements ValueSource {
1617 private static final Random RANDOM = new Random ();
1718
1819 static {
20+ TYPE_SOURCES .put (Byte .class , BiggerThanValueSource ::getByteStream );
21+ TYPE_SOURCES .put (byte .class , BiggerThanValueSource ::getByteStream );
22+
23+ TYPE_SOURCES .put (Short .class , BiggerThanValueSource ::getShortStream );
24+ TYPE_SOURCES .put (short .class , BiggerThanValueSource ::getShortStream );
25+
1926 TYPE_SOURCES .put (Integer .class , BiggerThanValueSource ::getIntegerStream );
2027 TYPE_SOURCES .put (int .class , BiggerThanValueSource ::getIntegerStream );
2128
@@ -28,11 +35,12 @@ public class BiggerThanValueSource implements ValueSource {
2835 TYPE_SOURCES .put (Double .class , BiggerThanValueSource ::getDoubleStream );
2936 TYPE_SOURCES .put (double .class , BiggerThanValueSource ::getDoubleStream );
3037
38+ TYPE_SOURCES .put (BigInteger .class , BiggerThanValueSource ::getBigIntegerStream );
3139 TYPE_SOURCES .put (BigDecimal .class , BiggerThanValueSource ::getBigDecimalStream );
3240 TYPE_SOURCES .put (ScaledBigDecimal .class , BiggerThanValueSource ::getScaledBigDecimalStream );
3341 }
3442
35- @ SuppressWarnings ("unchecked " )
43+ @ SuppressWarnings ("unused " )
3644 public static void registerType (Class <?> type , Function <Object [], Stream <?>> source ) {
3745 TYPE_SOURCES .put (type , source );
3846 }
@@ -48,14 +56,38 @@ public <T> Stream<T> values(Class<T> propertyClass, Object... args) {
4856 throw new IllegalArgumentException ("Property class not supported!" );
4957 }
5058
59+ @ NonNull
60+ private static Stream <Byte > getByteStream (Object [] args ) {
61+ var minValue = (byte ) (Long .valueOf ((long ) args [0 ]).byteValue () + 1 );
62+ var maxValue = Byte .MAX_VALUE ;
63+
64+ return Stream .concat (
65+ Stream .of (minValue , maxValue ),
66+ RANDOM .ints (1 , minValue , maxValue )
67+ .mapToObj (value -> Byte .valueOf ((byte ) value ))
68+ );
69+ }
70+
71+ @ NonNull
72+ private static Stream <Short > getShortStream (Object [] args ) {
73+ var minValue = (short ) (Long .valueOf ((long ) args [0 ]).shortValue () + 1 );
74+ var maxValue = Short .MAX_VALUE ;
75+
76+ return Stream .concat (
77+ Stream .of (minValue , maxValue ),
78+ RANDOM .ints (1 , minValue , maxValue )
79+ .mapToObj (value -> Short .valueOf ((short ) value ))
80+ );
81+ }
82+
5183 @ NonNull
5284 private static Stream <Integer > getIntegerStream (Object [] args ) {
5385 var minValue = Long .valueOf ((long ) args [0 ]).intValue () + 1 ;
5486 var maxValue = Integer .MAX_VALUE ;
5587
5688 return Stream .concat (
5789 Stream .of (minValue , maxValue ),
58- RANDOM .ints (minValue , maxValue ). limit ( 1 ).boxed ()
90+ RANDOM .ints (1 , minValue , maxValue ).boxed ()
5991 );
6092 }
6193
@@ -66,7 +98,7 @@ private static Stream<Long> getLongStream(Object[] args) {
6698
6799 return Stream .concat (
68100 Stream .of (minValue , maxValue ),
69- RANDOM .longs (minValue , maxValue ). limit ( 1 ).boxed ()
101+ RANDOM .longs (1 , minValue , maxValue ).boxed ()
70102 );
71103 }
72104
@@ -77,7 +109,7 @@ private static Stream<Float> getFloatStream(Object[] args) {
77109
78110 return Stream .concat (
79111 Stream .of (minValue , maxValue ),
80- RANDOM .doubles (minValue , maxValue ). limit ( 1 ).boxed ().map (
112+ RANDOM .doubles (1 , minValue , maxValue ).boxed ().map (
81113 Double ::floatValue
82114 )
83115 );
@@ -90,18 +122,20 @@ private static Stream<Double> getDoubleStream(Object[] args) {
90122
91123 return Stream .concat (
92124 Stream .of (minValue , maxValue ),
93- RANDOM .doubles (minValue , maxValue ). limit ( 1 ).boxed ()
125+ RANDOM .doubles (1 , minValue , maxValue ).boxed ()
94126 );
95127 }
96128
97129 @ NonNull
98- private static Stream <ScaledBigDecimal > getScaledBigDecimalStream (Object [] args ) {
99- var minValue = Long . valueOf (( long ) args [0 ]). doubleValue () + 0.1d ;
100- var maxValue = Double .MAX_VALUE ;
130+ private static Stream <BigInteger > getBigIntegerStream (Object [] args ) {
131+ var minValue = ( long ) args [0 ] + 1 ;
132+ var maxValue = Long .MAX_VALUE ;
101133
102134 return Stream .concat (
103- Stream .of (ScaledBigDecimal .valueOf (minValue ), ScaledBigDecimal .valueOf (maxValue )),
104- RANDOM .doubles (minValue , maxValue ).limit (1 ).boxed ().map (ScaledBigDecimal ::valueOf )
135+ Stream .of (BigInteger .valueOf (minValue ), BigInteger .valueOf (maxValue )),
136+ RANDOM .longs (1 , minValue , maxValue ).boxed ().map (
137+ BigInteger ::valueOf
138+ )
105139 );
106140 }
107141
@@ -112,7 +146,22 @@ private static Stream<BigDecimal> getBigDecimalStream(Object[] args) {
112146
113147 return Stream .concat (
114148 Stream .of (BigDecimal .valueOf (minValue ), BigDecimal .valueOf (maxValue )),
115- RANDOM .doubles (minValue , maxValue ).limit (1 ).boxed ().map (BigDecimal ::valueOf )
149+ RANDOM .doubles (1 , minValue , maxValue ).boxed ().map (
150+ BigDecimal ::valueOf
151+ )
152+ );
153+ }
154+
155+ @ NonNull
156+ private static Stream <ScaledBigDecimal > getScaledBigDecimalStream (Object [] args ) {
157+ var minValue = Long .valueOf ((long ) args [0 ]).doubleValue () + 0.1d ;
158+ var maxValue = Double .MAX_VALUE ;
159+
160+ return Stream .concat (
161+ Stream .of (ScaledBigDecimal .valueOf (minValue ), ScaledBigDecimal .valueOf (maxValue )),
162+ RANDOM .doubles (1 , minValue , maxValue ).boxed ().map (
163+ ScaledBigDecimal ::valueOf
164+ )
116165 );
117166 }
118167}
0 commit comments