private Canonical normalise(String indent, Term term) throws UcumException { Canonical result = new Canonical(new Decimal(1)); debug(indent, "canonicalise", term); boolean div = false; Term t = term; debug(indent, "collate", result); debug(indent, "sort", result); Collections.sort(result.getUnits(), new Comparator<CanonicalUnit>(){ @Override debug(indent, "done", result); return result;
private Canonical expandDefinedUnit(String indent, DefinedUnit unit) throws UcumException { String u = unit.getValue().getUnit(); if (unit.isSpecial()) { if (!handlers.exists(unit.getCode())) throw new UcumException("Not handled yet (special unit)"); else u = handlers.get(unit.getCode()).getUnits(); } Term t = new ExpressionParser(model).parse(u); debug(indent, "now handle", t); Canonical result = normalise(indent+" ", t); result.multiplyValue(unit.getValue().getValue()); return result; }
private Canonical normalise(String indent, Term term) throws UcumException { Canonical result = new Canonical(new Decimal(1)); debug(indent, "canonicalise", term); boolean div = false; Term t = term; debug(indent, "collate", result); debug(indent, "sort", result); Collections.sort(result.getUnits(), new Comparator<CanonicalUnit>(){ @Override debug(indent, "done", result); return result;
private Canonical expandDefinedUnit(String indent, DefinedUnit unit) throws UcumException { String u = unit.getValue().getUnit(); if (unit.isSpecial()) { if (!handlers.exists(unit.getCode())) throw new UcumException("Not handled yet (special unit)"); else u = handlers.get(unit.getCode()).getUnits(); } Term t = new ExpressionParser(model).parse(u); debug(indent, "now handle", t); Canonical result = normalise(indent+" ", t); result.multiplyValue(unit.getValue().getValue()); return result; }