BaseUnit
has an additional argument Q
, but I see no realistic way to pass that when constructing the class, nor to retrieve it later. Using the Class
maybe, that's already done in other places like unit systems.
Hello, I'm trying to use this api to manage material quantities. I'm trying to parse string units from a DB to a Unit. Can someone advise? I tried this approach, but it seems the ServiceProvider needs to be configured with services. Is there an easier approach to identifying a unit? In this case, I'm assuming it's mass but it could also be a volume.
private void parseMeasurement() {
if (available > 0 && availableUnit != null) {
try {
UnitFormat format = ServiceProvider.current().getFormatService().getUnitFormat();
Unit<?> unit = format.parse(availableUnit);
if (unit.getSystemUnit() instanceof Mass) {
Quantity<?> mass = Quantities.getQuantity(available,unit);
massAvailProperty().set(mass);
} else {
log.debug("Unexpected unit {} is not a Mass", unit.getName());
}
} catch (MeasurementParseException e) {
log.debug("Can't parse unit",e);
}
}
}
Thanks