/** * Creates a transformed unit from the specified system unit. * * @parem symbol the symbol to use with this transformed unit. * @param parentUnit the system unit from which this unit is derived. * @param unitConverter the converter to the parent units. * @throws IllegalArgumentException if the specified parent unit is not an {@link * AbstractUnit#isSystemUnit() system unit} */ public TransformedUnit(String symbol, Unit<Q> parentUnit, UnitConverter unitConverter) { if (parentUnit instanceof AbstractUnit) { final AbstractUnit<Q> abParent = (AbstractUnit<Q>) parentUnit; if (!abParent.isSystemUnit()) { throw new IllegalArgumentException( "The parent unit: " + abParent + " is not a system unit"); } this.parentUnit = abParent; this.converter = unitConverter; // this.symbol = symbol; //TODO see // https://github.com/unitsofmeasurement/uom-se/issues/54 } else { throw new IllegalArgumentException( "The parent unit: " + parentUnit + " is not an abstract unit."); } }
/** * Creates a transformed unit from the specified system unit. * * @param parentUnit the system unit from which this unit is derived. * @param unitConverter the converter to the parent units. * @throws IllegalArgumentException if the specified parent unit is not an {@link * AbstractUnit#isSystemUnit() system unit} */ public TransformedUnit(AbstractUnit<Q> parentUnit, UnitConverter unitConverter) { if (!parentUnit.isSystemUnit()) throw new IllegalArgumentException( "The parent unit: " + parentUnit + " is not a system unit"); this.parentUnit = parentUnit; this.converter = unitConverter; // this.symbol = parentUnit.getSymbol(); }
@Override public int hashCode() { return parentUnit.hashCode() + converter.hashCode(); }
@Override public Map<? extends Unit<?>, Integer> getProductUnits() { return parentUnit.getProductUnits(); }
@Override public AbstractUnit<Q> toSystemUnit() { return parentUnit.getSystemUnit(); }
@Override public UnitConverter getSystemConverter() { return parentUnit.getSystemConverter().concatenate(converter); }
@Override public Dimension getDimension() { return parentUnit.getDimension(); }