private Prefix parsePrefix(XmlPullParser xpp) throws XmlPullParserException, IOException, UcumException { Prefix prefix = new Prefix(xpp.getAttributeValue(null, "Code"), xpp.getAttributeValue(null, "CODE")); xpp.next(); skipWhitespace(xpp); prefix.getNames().add(readElement(xpp, "name", "prefix "+prefix.getCode(), false)); prefix.setPrintSymbol(readElement(xpp, "printSymbol", "prefix "+prefix.getCode(), false)); checkAtElement(xpp, "value", "prefix "+prefix.getCode()); prefix.setValue(new Decimal(xpp.getAttributeValue(null, "value"), 24)); readElement(xpp, "value", "prefix "+prefix.getCode(), true); xpp.next(); skipWhitespace(xpp); return prefix; }
private void composeSymbol(StringBuilder bldr, Symbol symbol) { if (symbol.getPrefix() != null) { bldr.append(symbol.getPrefix().getCode()); } bldr.append(symbol.getUnit().getCode()); if (symbol.getExponent() != 1) { bldr.append(symbol.getExponent()); } }
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; }
private Prefix parsePrefix(XmlPullParser xpp) throws XmlPullParserException, IOException, UcumException { Prefix prefix = new Prefix(xpp.getAttributeValue(null, "Code"), xpp.getAttributeValue(null, "CODE")); xpp.next(); skipWhitespace(xpp); prefix.getNames().add(readElement(xpp, "name", "prefix "+prefix.getCode(), false)); prefix.setPrintSymbol(readElement(xpp, "printSymbol", "prefix "+prefix.getCode(), false)); checkAtElement(xpp, "value", "prefix "+prefix.getCode()); prefix.setValue(new Decimal(xpp.getAttributeValue(null, "value"), 24)); readElement(xpp, "value", "prefix "+prefix.getCode(), true); xpp.next(); skipWhitespace(xpp); return prefix; }
private void composeSymbol(StringBuilder bldr, Symbol symbol) { if (symbol.getPrefix() != null) { bldr.append(symbol.getPrefix().getCode()); } bldr.append(symbol.getUnit().getCode()); if (symbol.getExponent() != 1) { bldr.append(symbol.getExponent()); } }