private FormItem buildJVMMemoryItem(String name, String value) {
Set<MeasurementUnits> supportedUnits = new LinkedHashSet<MeasurementUnits>();
supportedUnits.add(MeasurementUnits.MEGABYTES);
supportedUnits.add(MeasurementUnits.GIGABYTES);
ValueWithUnitsItem valueItem = new ValueWithUnitsItem(name, null, supportedUnits);
if (value != null && !value.isEmpty()) {
boolean megs = value.trim().substring(value.trim().length() - 1).equalsIgnoreCase("m");
MeasurementUnits units = megs ? MeasurementUnits.MEGABYTES : MeasurementUnits.GIGABYTES;
try {
int intVal = Integer.parseInt(value.substring(0, value.toLowerCase().indexOf(megs ? "m" : "g")));
valueItem.setValue(intVal, units);
} catch (StringIndexOutOfBoundsException e) {
// do nothing
}
}
return valueItem;