@@ -25,11 +25,21 @@ public double get() {
25
25
// Return result in long
26
26
public long toLong () {
27
27
try {
28
- if (Double .isNaN (result )) throw new IllegalArgumentException ("Cannot convert NaN to long!" );
29
- if (result == Double .POSITIVE_INFINITY ) return Long .MAX_VALUE ;
30
- if (result == Double .NEGATIVE_INFINITY ) return Long .MIN_VALUE ;
31
- if (result > Long .MAX_VALUE ) return Long .MAX_VALUE ;
32
- if (result < Long .MIN_VALUE ) return Long .MIN_VALUE ;
28
+ if (Double .isNaN (result )) {
29
+ throw new IllegalArgumentException ("Cannot convert NaN to long!" );
30
+ }
31
+ if (result == Double .POSITIVE_INFINITY ) {
32
+ return Long .MAX_VALUE ;
33
+ }
34
+ if (result == Double .NEGATIVE_INFINITY ) {
35
+ return Long .MIN_VALUE ;
36
+ }
37
+ if (result > Long .MAX_VALUE ) {
38
+ return Long .MAX_VALUE ;
39
+ }
40
+ if (result < Long .MIN_VALUE ) {
41
+ return Long .MIN_VALUE ;
42
+ }
33
43
return Math .round (result );
34
44
} catch (Exception ex ) {
35
45
return 0 ;
@@ -61,7 +71,9 @@ public Builder add(double num) {
61
71
62
72
// Takes a number and a condition, only does the operation if condition is true.
63
73
public Builder addIf (double num , BiFunction <Double , Double , Boolean > condition ) {
64
- if (!condition .apply (number , num )) return this ;
74
+ if (!condition .apply (number , num )) {
75
+ return this ;
76
+ }
65
77
if (inParenthesis ) {
66
78
sideNumber += num ;
67
79
} else {
@@ -81,7 +93,9 @@ public Builder minus(double num) {
81
93
82
94
// Takes a number and a condition, only does the operation if condition is true.
83
95
public Builder minusIf (double num , BiFunction <Double , Double , Boolean > condition ) {
84
- if (!condition .apply (number , num )) return this ;
96
+ if (!condition .apply (number , num )) {
97
+ return this ;
98
+ }
85
99
if (inParenthesis ) {
86
100
sideNumber -= num ;
87
101
} else {
@@ -92,28 +106,36 @@ public Builder minusIf(double num, BiFunction<Double, Double, Boolean> condition
92
106
93
107
// Generates a random number and sets to NUMBER
94
108
public Builder rand (long seed ) {
95
- if (number != 0 ) throw new RuntimeException ("Number must be zero for random assignment!" );
109
+ if (number != 0 ) {
110
+ throw new RuntimeException ("Number must be zero for random assignment!" );
111
+ }
96
112
Random random = new Random ();
97
113
number = random .nextDouble (seed );
98
114
return this ;
99
115
}
100
116
101
117
// Takes PI value and sets to NUMBER
102
118
public Builder pi () {
103
- if (number != 0 ) throw new RuntimeException ("Number must be zero for PI assignment!" );
119
+ if (number != 0 ) {
120
+ throw new RuntimeException ("Number must be zero for PI assignment!" );
121
+ }
104
122
number = Math .PI ;
105
123
return this ;
106
124
}
107
125
108
126
// Takes E value and sets to NUMBER
109
127
public Builder e () {
110
- if (number != 0 ) throw new RuntimeException ("Number must be zero for E assignment!" );
128
+ if (number != 0 ) {
129
+ throw new RuntimeException ("Number must be zero for E assignment!" );
130
+ }
111
131
number = Math .E ;
112
132
return this ;
113
133
}
114
134
115
135
public Builder randomInRange (double min , double max ) {
116
- if (number != 0 ) throw new RuntimeException ("Number must be zero for random assignment!" );
136
+ if (number != 0 ) {
137
+ throw new RuntimeException ("Number must be zero for random assignment!" );
138
+ }
117
139
Random random = new Random ();
118
140
number = min + (max - min ) * random .nextDouble ();
119
141
return this ;
@@ -157,7 +179,9 @@ public Builder multiply(double num) {
157
179
158
180
// Takes a number and a condition, only does the operation if condition is true.
159
181
public Builder multiplyIf (double num , BiFunction <Double , Double , Boolean > condition ) {
160
- if (!condition .apply (number , num )) return this ;
182
+ if (!condition .apply (number , num )) {
183
+ return this ;
184
+ }
161
185
if (inParenthesis ) {
162
186
sideNumber *= num ;
163
187
} else {
@@ -167,7 +191,9 @@ public Builder multiplyIf(double num, BiFunction<Double, Double, Boolean> condit
167
191
}
168
192
169
193
public Builder divide (double num ) {
170
- if (num == 0 ) return this ;
194
+ if (num == 0 ) {
195
+ return this ;
196
+ }
171
197
if (inParenthesis ) {
172
198
sideNumber /= num ;
173
199
} else {
@@ -178,8 +204,12 @@ public Builder divide(double num) {
178
204
179
205
// Takes a number and a condition, only does the operation if condition is true.
180
206
public Builder divideIf (double num , BiFunction <Double , Double , Boolean > condition ) {
181
- if (num == 0 ) return this ;
182
- if (!condition .apply (number , num )) return this ;
207
+ if (num == 0 ) {
208
+ return this ;
209
+ }
210
+ if (!condition .apply (number , num )) {
211
+ return this ;
212
+ }
183
213
if (inParenthesis ) {
184
214
sideNumber /= num ;
185
215
} else {
@@ -199,7 +229,9 @@ public Builder mod(double num) {
199
229
200
230
// Takes a number and a condition, only does the operation if condition is true.
201
231
public Builder modIf (double num , BiFunction <Double , Double , Boolean > condition ) {
202
- if (!condition .apply (number , num )) return this ;
232
+ if (!condition .apply (number , num )) {
233
+ return this ;
234
+ }
203
235
if (inParenthesis ) {
204
236
sideNumber %= num ;
205
237
} else {
@@ -378,23 +410,33 @@ public Builder recall(boolean cleanMemory) {
378
410
379
411
// Recalls the NUMBER on condition
380
412
public Builder recallIf (Function <Double , Boolean > condition , boolean cleanMemory ) {
381
- if (!condition .apply (number )) return this ;
413
+ if (!condition .apply (number )) {
414
+ return this ;
415
+ }
382
416
number = memory ;
383
- if (cleanMemory ) memory = 0 ;
417
+ if (cleanMemory ) {
418
+ memory = 0 ;
419
+ }
384
420
return this ;
385
421
}
386
422
387
423
// Replaces NUMBER with given number
388
424
public Builder set (double num ) {
389
- if (number != 0 ) throw new RuntimeException ("Number must be zero to set!" );
425
+ if (number != 0 ) {
426
+ throw new RuntimeException ("Number must be zero to set!" );
427
+ }
390
428
number = num ;
391
429
return this ;
392
430
}
393
431
394
432
// Replaces NUMBER with given number on condition
395
433
public Builder setIf (double num , BiFunction <Double , Double , Boolean > condition ) {
396
- if (number != 0 ) throw new RuntimeException ("Number must be zero to set!" );
397
- if (condition .apply (number , num )) number = num ;
434
+ if (number != 0 ) {
435
+ throw new RuntimeException ("Number must be zero to set!" );
436
+ }
437
+ if (condition .apply (number , num )) {
438
+ number = num ;
439
+ }
398
440
return this ;
399
441
}
400
442
0 commit comments