@Override public String validateInProperty(String unit, String property) { assert checkStringParam(unit) : paramError("validate", "unit", "must not be null or empty"); assert checkStringParam(property) : paramError("validateInProperty", "property", "must not be null or empty"); try { Term term = new ExpressionParser(model).parse(unit); Canonical can = new Converter(model, handlers).convert(term); String cu = new ExpressionComposer().compose(can, false); if (can.getUnits().size() == 1) { if (property.equals(can.getUnits().get(0).getBase().getProperty())) return null; else return "unit "+unit+" is of the property type "+can.getUnits().get(0).getBase().getProperty()+" ("+cu+"), not "+property+" as required."; } // defined special case if ("concentration".equals(property) && ("g/L".equals(cu) || "mol/L".equals(cu))) return null; return "unit "+unit+" has the base units "+cu+", and are not from the property "+property+" as required."; } catch (Exception e) { return e.getMessage(); } }
@Override public String validateInProperty(String unit, String property) { assert checkStringParam(unit) : paramError("validate", "unit", "must not be null or empty"); assert checkStringParam(property) : paramError("validateInProperty", "property", "must not be null or empty"); try { Term term = new ExpressionParser(model).parse(unit); Canonical can = new Converter(model, handlers).convert(term); String cu = new ExpressionComposer().compose(can, false); if (can.getUnits().size() == 1) { if (property.equals(can.getUnits().get(0).getBase().getProperty())) return null; else return "unit "+unit+" is of the property type "+can.getUnits().get(0).getBase().getProperty()+" ("+cu+"), not "+property+" as required."; } // defined special case if ("concentration".equals(property) && ("g/L".equals(cu) || "mol/L".equals(cu))) return null; return "unit "+unit+" has the base units "+cu+", and are not from the property "+property+" as required."; } catch (Exception e) { return e.getMessage(); } }