use of tec.uom.se.AbstractUnit in project uom-se by unitsofmeasurement.
the class EBNFHelper method newUnitPrecedenceInternal.
private static int newUnitPrecedenceInternal(Unit<?> unit, Appendable buffer, SymbolMap symbolMap) throws IOException {
UnitConverter converter = null;
boolean printSeparator = false;
StringBuilder temp = new StringBuilder();
int unitPrecedence = NOOP_PRECEDENCE;
Unit<?> parentUnit = unit.getSystemUnit();
converter = ((AbstractUnit<?>) unit).getSystemConverter();
if (KILOGRAM.equals(parentUnit)) {
if (unit instanceof TransformedUnit<?>) {
// incosistency
if (unit.equals(GRAM)) {
return noopPrecedenceInternal(buffer, symbolMap.getSymbol(GRAM));
} else {
// parentUnit = GRAM;
// converter = unit.getConverterTo((Unit) KILOGRAM);
converter = ((TransformedUnit) unit).getConverter();
}
// parentUnit = GRAM;
} else {
converter = unit.getConverterTo((Unit) GRAM);
}
} else if (CUBIC_METRE.equals(parentUnit)) {
if (converter != null) {
parentUnit = LITRE;
}
}
// https://github.com/unitsofmeasurement/si-units/issues/4
if (unit instanceof TransformedUnit) {
TransformedUnit transUnit = (TransformedUnit) unit;
if (parentUnit == null)
parentUnit = transUnit.getParentUnit();
// String x = parentUnit.toString();
converter = transUnit.getConverter();
}
unitPrecedence = formatInternal(parentUnit, temp, symbolMap);
printSeparator = !parentUnit.equals(AbstractUnit.ONE);
int result = ConverterFormatter.formatConverter(converter, printSeparator, unitPrecedence, temp, symbolMap);
buffer.append(temp);
return result;
}
use of tec.uom.se.AbstractUnit in project uom-se by unitsofmeasurement.
the class ProductUnit method getSystemConverter.
@Override
public UnitConverter getSystemConverter() {
UnitConverter converter = AbstractConverter.IDENTITY;
for (Element e : elements) {
if (e.unit instanceof AbstractUnit) {
UnitConverter cvtr = ((AbstractUnit) e.unit).getSystemConverter();
if (!(cvtr.isLinear()))
throw new UnsupportedOperationException(e.unit + " is non-linear, cannot convert");
if (e.root != 1)
throw new UnsupportedOperationException(e.unit + " holds a base unit with fractional exponent");
int pow = e.pow;
if (pow < 0) {
// Negative power.
pow = -pow;
cvtr = cvtr.inverse();
}
for (int j = 0; j < pow; j++) {
converter = converter.concatenate(cvtr);
}
}
}
return converter;
}
Aggregations