calc(float)   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 25
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 24
dl 0
loc 25
rs 9.304
c 1
b 0
f 0
cc 2
1
package com.osomapps.pt.estimation;
2
3
public class CurveEstimation {
4
    private float impact = 1F;
5
    private float zeroAdjustmentBefore = 0;
0 ignored issues
show
Unused Code introduced by
Consider removing the unused private field zeroAdjustmentBefore.
Loading history...
6
    private float zeroAdjustmentAfter = 2.5F;
7
    private float baseNumber = 2F;
8
    private float limit = 50F;
9
10
    private CurveEstimation(
11
            float impact,
12
            float zeroAdjustmentBefore,
13
            float zeroAdjustmentAfter,
14
            float baseNumber,
15
            float limit) {
16
        this.impact = impact; // B1
17
        this.zeroAdjustmentBefore = zeroAdjustmentBefore; // B2
18
        this.zeroAdjustmentAfter = zeroAdjustmentAfter; // B3
19
        this.baseNumber = baseNumber; // B4
20
        this.limit = limit; // B5
21
    }
22
23
    public static CurveEstimation of(
24
            float impact,
25
            float zeroAdjustmentBefore,
26
            float zeroAdjustmentAfter,
27
            float baseNumber,
28
            float limit) {
29
        return new CurveEstimation(
30
                impact, zeroAdjustmentBefore, zeroAdjustmentAfter, baseNumber, limit);
31
    }
32
33
    public float calc(float value) {
34
        if (value < 0) {
35
            return (float)
36
                    (Math.abs(
37
                                            Math.min(
38
                                                    Math.max(
39
                                                            (Math.pow(value / 100, baseNumber)
40
                                                                    * 100
41
                                                                    / impact),
42
                                                            -limit),
43
                                                    limit * 0.5F))
44
                                    * Math.signum(value)
45
                            + zeroAdjustmentAfter);
46
        }
47
        return (float)
48
                (Math.abs(
49
                                        Math.min(
50
                                                Math.max(
51
                                                        (Math.pow(value / 100, baseNumber)
52
                                                                * 100
53
                                                                / impact),
54
                                                        -limit),
55
                                                limit))
56
                                * Math.signum(value)
57
                        + zeroAdjustmentAfter);
58
    }
59
}
60