private void composeSymbol(StringBuilder bldr, Symbol symbol) { bldr.append('('); if (symbol.getPrefix() != null) { bldr.append(symbol.getPrefix().getNames().get(0)); } bldr.append(symbol.getUnit().getNames().get(0)); if (symbol.getExponent() != 1) { bldr.append(" ^ "); bldr.append(symbol.getExponent()); } bldr.append(')'); }
private Canonical normalise(String indent, Symbol sym) throws UcumException { Canonical result = new Canonical(new Decimal(1)); if (sym.getUnit() instanceof BaseUnit) { result.getUnits().add(new CanonicalUnit((BaseUnit) sym.getUnit(), sym.getExponent())); } else { Canonical can = expandDefinedUnit(indent, (DefinedUnit) sym.getUnit()); for (CanonicalUnit c : can.getUnits()) { c.setExponent(c.getExponent() * sym.getExponent()); } result.getUnits().addAll(can.getUnits()); if (sym.getExponent() > 0) for (int i = 0; i < sym.getExponent(); i++) result.multiplyValue(can.getValue()); else for (int i = 0; i > sym.getExponent(); i--) result.divideValue(can.getValue()); } if (sym.getPrefix() != null) { if (sym.getExponent() > 0) for (int i = 0; i < sym.getExponent(); i++) result.multiplyValue(sym.getPrefix().getValue()); else for (int i = 0; i > sym.getExponent(); i--) result.divideValue(sym.getPrefix().getValue()); } return result; }
private void composeSymbol(StringBuilder bldr, Symbol symbol) { bldr.append('('); if (symbol.getPrefix() != null) { bldr.append(symbol.getPrefix().getNames().get(0)); } bldr.append(symbol.getUnit().getNames().get(0)); if (symbol.getExponent() != 1) { bldr.append(" ^ "); bldr.append(symbol.getExponent()); } bldr.append(')'); }
private Canonical normalise(String indent, Symbol sym) throws UcumException { Canonical result = new Canonical(new Decimal(1)); if (sym.getUnit() instanceof BaseUnit) { result.getUnits().add(new CanonicalUnit((BaseUnit) sym.getUnit(), sym.getExponent())); } else { Canonical can = expandDefinedUnit(indent, (DefinedUnit) sym.getUnit()); for (CanonicalUnit c : can.getUnits()) { c.setExponent(c.getExponent() * sym.getExponent()); } result.getUnits().addAll(can.getUnits()); if (sym.getExponent() > 0) for (int i = 0; i < sym.getExponent(); i++) result.multiplyValue(can.getValue()); else for (int i = 0; i > sym.getExponent(); i--) result.divideValue(can.getValue()); } if (sym.getPrefix() != null) { if (sym.getExponent() > 0) for (int i = 0; i < sym.getExponent(); i++) result.multiplyValue(sym.getPrefix().getValue()); else for (int i = 0; i > sym.getExponent(); i--) result.divideValue(sym.getPrefix().getValue()); } return result; }