Skip to content

Commit 0b66931

Browse files
committed
Added Parenthesis in MathBuilder
1 parent 9d5f234 commit 0b66931

File tree

1 file changed

+90
-60
lines changed

1 file changed

+90
-60
lines changed

src/main/java/com/thealgorithms/maths/MathBuilder.java

+90-60
Original file line numberDiff line numberDiff line change
@@ -51,38 +51,42 @@ public Builder(double num) {
5151
}
5252

5353
public Builder add(double num) {
54-
if (inParenthesis)
54+
if (inParenthesis) {
5555
sideNumber += num;
56-
else
56+
} else {
5757
number += num;
58+
}
5859
return this;
5960
}
6061

6162
// Takes a number and a condition, only does the operation if condition is true.
6263
public Builder addIf(double num, BiFunction<Double, Double, Boolean> condition) {
6364
if (!condition.apply(number, num)) return this;
64-
if (inParenthesis)
65+
if (inParenthesis) {
6566
sideNumber += num;
66-
else
67+
} else {
6768
number += num;
69+
}
6870
return this;
6971
}
7072

7173
public Builder minus(double num) {
72-
if (inParenthesis)
74+
if (inParenthesis) {
7375
sideNumber -= num;
74-
else
76+
} else {
7577
number -= num;
78+
}
7679
return this;
7780
}
7881

7982
// Takes a number and a condition, only does the operation if condition is true.
8083
public Builder minusIf(double num, BiFunction<Double, Double, Boolean> condition) {
8184
if (!condition.apply(number, num)) return this;
82-
if (inParenthesis)
85+
if (inParenthesis) {
8386
sideNumber -= num;
84-
else
87+
} else {
8588
number -= num;
89+
}
8690
return this;
8791
}
8892

@@ -116,218 +120,244 @@ public Builder randomInRange(double min, double max) {
116120
}
117121

118122
public Builder toDegrees() {
119-
if (inParenthesis)
123+
if (inParenthesis) {
120124
sideNumber = Math.toDegrees(sideNumber);
121-
else
125+
} else {
122126
number = Math.toDegrees(number);
127+
}
123128
return this;
124129
}
125130

126131
public Builder max(double num) {
127-
if (inParenthesis)
132+
if (inParenthesis) {
128133
sideNumber = Math.max(sideNumber, num);
129-
else
134+
} else {
130135
number = Math.max(number, num);
136+
}
131137
return this;
132138
}
133139

134140
public Builder min(double num) {
135-
if (inParenthesis)
141+
if (inParenthesis) {
136142
sideNumber = Math.min(sideNumber, num);
137-
else
143+
} else {
138144
number = Math.min(number, num);
145+
}
139146
return this;
140147
}
141148

142149
public Builder multiply(double num) {
143-
if (inParenthesis)
150+
if (inParenthesis) {
144151
sideNumber *= num;
145-
else
152+
} else {
146153
number *= num;
154+
}
147155
return this;
148156
}
149157

150158
// Takes a number and a condition, only does the operation if condition is true.
151159
public Builder multiplyIf(double num, BiFunction<Double, Double, Boolean> condition) {
152160
if (!condition.apply(number, num)) return this;
153-
if (inParenthesis)
161+
if (inParenthesis) {
154162
sideNumber *= num;
155-
else
163+
} else {
156164
number *= num;
165+
}
157166
return this;
158167
}
159168

160169
public Builder divide(double num) {
161170
if (num == 0) return this;
162-
if (inParenthesis)
171+
if (inParenthesis) {
163172
sideNumber /= num;
164-
else
173+
} else {
165174
number /= num;
175+
}
166176
return this;
167177
}
168178

169179
// Takes a number and a condition, only does the operation if condition is true.
170180
public Builder divideIf(double num, BiFunction<Double, Double, Boolean> condition) {
171181
if (num == 0) return this;
172182
if (!condition.apply(number, num)) return this;
173-
if (inParenthesis)
183+
if (inParenthesis) {
174184
sideNumber /= num;
175-
else
185+
} else {
176186
number /= num;
187+
}
177188
return this;
178189
}
179190

180191
public Builder mod(double num) {
181-
if (inParenthesis)
192+
if (inParenthesis) {
182193
sideNumber %= num;
183-
else
194+
} else {
184195
number %= num;
196+
}
185197
return this;
186198
}
187199

188200
// Takes a number and a condition, only does the operation if condition is true.
189201
public Builder modIf(double num, BiFunction<Double, Double, Boolean> condition) {
190202
if (!condition.apply(number, num)) return this;
191-
if (inParenthesis)
203+
if (inParenthesis) {
192204
sideNumber %= num;
193-
else
205+
} else {
194206
number %= num;
207+
}
195208
return this;
196209
}
197210

198211
public Builder pow(double num) {
199-
if (inParenthesis)
212+
if (inParenthesis) {
200213
sideNumber = Math.pow(sideNumber, num);
201-
else
214+
} else {
202215
number = Math.pow(number, num);
216+
}
203217
return this;
204218
}
205219

206220
public Builder sqrt() {
207-
if (inParenthesis)
221+
if (inParenthesis) {
208222
sideNumber = Math.sqrt(sideNumber);
209-
else
223+
} else {
210224
number = Math.sqrt(number);
225+
}
211226
return this;
212227
}
213228

214229
public Builder round() {
215-
if (inParenthesis)
230+
if (inParenthesis) {
216231
sideNumber = Math.round(sideNumber);
217-
else
232+
} else {
218233
number = Math.round(number);
234+
}
219235
return this;
220236
}
221237

222238
public Builder floor() {
223-
if (inParenthesis)
239+
if (inParenthesis) {
224240
sideNumber = Math.floor(sideNumber);
225-
else
241+
} else {
226242
number = Math.floor(number);
243+
}
227244
return this;
228245
}
229246

230247
public Builder ceil() {
231-
if (inParenthesis)
248+
if (inParenthesis) {
232249
sideNumber = Math.ceil(sideNumber);
233-
else
250+
} else {
234251
number = Math.ceil(number);
252+
}
235253
return this;
236254
}
237255

238256
public Builder abs() {
239-
if (inParenthesis)
257+
if (inParenthesis) {
240258
sideNumber = Math.abs(sideNumber);
241-
else
259+
} else {
242260
number = Math.abs(number);
261+
}
243262
return this;
244263
}
245264

246265
public Builder cbrt() {
247-
if (inParenthesis)
266+
if (inParenthesis) {
248267
sideNumber = Math.cbrt(sideNumber);
249-
else
268+
} else {
250269
number = Math.cbrt(number);
270+
}
251271
return this;
252272
}
253273

254274
public Builder log() {
255-
if (inParenthesis)
275+
if (inParenthesis) {
256276
sideNumber = Math.log(sideNumber);
257-
else
277+
} else {
258278
number = Math.log(number);
279+
}
259280
return this;
260281
}
261282

262283
public Builder log10() {
263-
if (inParenthesis)
284+
if (inParenthesis) {
264285
sideNumber = Math.log10(sideNumber);
265-
else
286+
} else {
266287
number = Math.log10(number);
288+
}
267289
return this;
268290
}
269291

270292
public Builder sin() {
271-
if (inParenthesis)
293+
if (inParenthesis) {
272294
sideNumber = Math.sin(sideNumber);
273-
else
295+
} else {
274296
number = Math.sin(number);
297+
}
275298
return this;
276299
}
277300

278301
public Builder cos() {
279-
if (inParenthesis)
302+
if (inParenthesis) {
280303
sideNumber = Math.cos(sideNumber);
281-
else
304+
} else {
282305
number = Math.cos(number);
306+
}
283307
return this;
284308
}
285309

286310
public Builder tan() {
287-
if (inParenthesis)
311+
if (inParenthesis) {
288312
sideNumber = Math.tan(sideNumber);
289-
else
313+
} else {
290314
number = Math.tan(number);
315+
}
291316
return this;
292317
}
293318

294319
public Builder sinh() {
295-
if (inParenthesis)
320+
if (inParenthesis) {
296321
sideNumber = Math.sinh(sideNumber);
297-
else
322+
} else {
298323
number = Math.sinh(number);
324+
}
299325
return this;
300326
}
301327

302328
public Builder cosh() {
303-
if (inParenthesis)
329+
if (inParenthesis) {
304330
sideNumber = Math.cosh(sideNumber);
305-
else
331+
} else {
306332
number = Math.cosh(number);
333+
}
307334
return this;
308335
}
309336

310337
public Builder tanh() {
311-
if (inParenthesis)
338+
if (inParenthesis) {
312339
sideNumber = Math.tanh(sideNumber);
313-
else
340+
} else {
314341
number = Math.tanh(number);
342+
}
315343
return this;
316344
}
317345

318346
public Builder exp() {
319-
if (inParenthesis)
347+
if (inParenthesis) {
320348
sideNumber = Math.exp(sideNumber);
321-
else
349+
} else {
322350
number = Math.exp(number);
351+
}
323352
return this;
324353
}
325354

326355
public Builder toRadians() {
327-
if (inParenthesis)
356+
if (inParenthesis) {
328357
sideNumber = Math.toRadians(sideNumber);
329-
else
358+
} else {
330359
number = Math.toRadians(number);
360+
}
331361
return this;
332362
}
333363

0 commit comments

Comments
 (0)