public String compose(Canonical can, boolean value) { StringBuilder b = new StringBuilder(); if (value) b.append(can.getValue().asDecimal()); boolean first = true; for (CanonicalUnit c : can.getUnits()) { if (first) first = false; else b.append("."); b.append(c.getBase().getCode()); if (c.getExponent() != 1) b.append(c.getExponent()); } return b.toString(); }
result.divideValue(temp.getValue()); for (CanonicalUnit c : temp.getUnits()) c.setExponent(0-c.getExponent()); } else { result.multiplyValue(temp.getValue()); result.divideValue(temp.getValue()); for (CanonicalUnit c : temp.getUnits()) c.setExponent(0-c.getExponent()); } else { result.multiplyValue(temp.getValue()); CanonicalUnit st = result.getUnits().get(j); if (st.getBase() == sf.getBase()) { st.setExponent(sf.getExponent()+st.getExponent()); result.getUnits().remove(i); break; if (sf.getExponent() == 0) result.getUnits().remove(i);
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; }
result.divideValue(temp.getValue()); for (CanonicalUnit c : temp.getUnits()) c.setExponent(0-c.getExponent()); } else { result.multiplyValue(temp.getValue()); result.divideValue(temp.getValue()); for (CanonicalUnit c : temp.getUnits()) c.setExponent(0-c.getExponent()); } else { result.multiplyValue(temp.getValue()); CanonicalUnit st = result.getUnits().get(j); if (st.getBase() == sf.getBase()) { st.setExponent(sf.getExponent()+st.getExponent()); result.getUnits().remove(i); break; if (sf.getExponent() == 0) result.getUnits().remove(i);
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; }
public String compose(Canonical can, boolean value) { StringBuilder b = new StringBuilder(); if (value) b.append(can.getValue().asDecimal()); boolean first = true; for (CanonicalUnit c : can.getUnits()) { if (first) first = false; else b.append("."); b.append(c.getBase().getCode()); if (c.getExponent() != 1) b.append(c.getExponent()); } return b.toString(); }