Merge branch '91-fixxing-sonarqube-bugs' into 'dev'

fix

Closes #91

See merge request sa4-2020/the-sanmarinoes/backend!191
This commit is contained in:
Matteo Omenetti 2020-05-26 15:43:51 +02:00
commit 3c4d295e44
4 changed files with 9 additions and 6 deletions

View File

@ -49,7 +49,7 @@ public class Sensor extends InputDevice implements RangeTriggerable {
private BigDecimal err = new BigDecimal(1);
@Column(nullable = false, precision = 11, scale = 1)
private BigDecimal typical = new BigDecimal(17);
private BigDecimal typical = BigDecimal.valueOf(17);
/** The type of this sensor */
@Column(nullable = false)
@Enumerated(value = EnumType.STRING)

View File

@ -84,7 +84,7 @@ public class Thermostat extends Switchable implements BooleanTriggerable {
private BigDecimal err = new BigDecimal(1);
@Column(nullable = false, precision = 11, scale = 1)
private BigDecimal typical = new BigDecimal(17.0);
private BigDecimal typical = BigDecimal.valueOf(17);
/** Creates a thermostat with a temperature sensor and its initial OFF state */
public Thermostat() {

View File

@ -19,14 +19,16 @@ public class SensorService {
@Autowired private SensorSocketEndpoint endpoint;
private Random ran = new Random();
private void randomJitter(Sensor sensor) {
double x;
Random ran = new Random();
x =
(ran.nextInt(sensor.getTypical().intValue()) + sensor.getError().intValue()) * 0.975
+ 1;
updateValueFromSensor(sensor, new BigDecimal(x));
updateValueFromSensor(sensor, BigDecimal.valueOf(x));
}
public void sensorFakeUpdate() {

View File

@ -22,6 +22,8 @@ public class ThermostatService {
private final ThermostatRepository thermostatRepository;
private Random ran = new Random();
@Autowired
public ThermostatService(
SensorSocketEndpoint endpoint,
@ -37,12 +39,11 @@ public class ThermostatService {
private void randomJitter(Thermostat thermostat) {
double x;
Random ran = new Random();
x =
(ran.nextInt(thermostat.getTypical().intValue()) + thermostat.getErr().intValue())
* 0.975
+ 1;
updateValueForThermostat(thermostat, new BigDecimal(x));
updateValueForThermostat(thermostat, BigDecimal.valueOf(x));
}
private void updateValueForThermostat(Thermostat thermostat, BigDecimal value) {