Make attribute type safe.

This commit is contained in:
Michael Lipp 2023-06-11 13:48:13 +02:00
parent 3587e91150
commit 175d64e1ca
2 changed files with 22 additions and 8 deletions

View file

@ -108,14 +108,15 @@ class Configuration implements Dto {
/**
* Subsection "vm".
*/
@SuppressWarnings({ "PMD.ShortClassName", "PMD.TooManyFields" })
@SuppressWarnings({ "PMD.ShortClassName", "PMD.TooManyFields",
"PMD.DataClass" })
public static class Vm implements Dto {
public String name;
public String uuid;
public boolean useTpm;
public String firmware = "uefi";
public Object maximumRam;
public Object currentRam;
public BigInteger maximumRam;
public BigInteger currentRam;
public String cpuModel = "host";
public int maximumCpus = 1;
public int currentCpus = 1;
@ -130,6 +131,24 @@ class Configuration implements Dto {
public Network[] network = { new Network() };
public Drive[] drives;
public Spice spice;
/**
* Convert value from JSON parser.
*
* @param value the new maximum ram
*/
public void setMaximumRam(String value) {
maximumRam = parseMemory(value);
}
/**
* Convert value from JSON parser.
*
* @param value the new current ram
*/
public void setCurrentRam(String value) {
currentRam = parseMemory(value);
}
}
/**
@ -180,10 +199,6 @@ class Configuration implements Dto {
vm.maximumCpus = vm.currentCpus;
}
// Adjust memory specifications
vm.maximumRam = parseMemory(vm.maximumRam);
vm.currentRam = parseMemory(vm.currentRam);
return true;
}

View file

@ -446,7 +446,6 @@ public class Runner extends Component {
@Handler
public void onQemuMonitorOpened(QemuMonitorOpened event) {
Optional.ofNullable(config.vm.currentRam)
.map(Configuration::parseMemory)
.ifPresent(qemuMonitor::setCurrentRam);
state.set(State.RUNNING);
}