/** * Extract the value, can only be called for ScaledUnit. * @return value of this unit if ScaledUnit, else NaN */ public double getValue() { if (!(uu instanceof ScaledUnit)) return Double.NaN; ScaledUnit offset = (ScaledUnit) uu; return offset.getScale(); }
/** * Extract the value, can only be called for ScaledUnit. * @return value of this unit if ScaledUnit, else NaN */ public double getValue() { if (!(uu instanceof ScaledUnit)) return Double.NaN; ScaledUnit offset = (ScaledUnit) uu; return offset.getScale(); }
/** * Extract the value, can only be called for ScaledUnit. * @return value of this unit if ScaledUnit, else NaN */ public double getValue() { if (!(uu instanceof ScaledUnit)) return Double.NaN; ScaledUnit offset = (ScaledUnit) uu; return offset.getScale(); }
private StringBuffer format(ScaledUnit unit, StringBuffer buf, boolean normalize) throws UnitClassException { double scale = unit.getScale(); if (scale != 0.0) { if (scale == 1) { format(unit.getUnit(), buf, normalize); } else { buf.append(scale).append(' '); int start = buf.length(); format(unit.getUnit(), buf, normalize); if (start == buf.length()) buf.setLength(start - 1); } } return buf; }
private StringBuffer format(ScaledUnit unit, StringBuffer buf, boolean normalize) throws UnitClassException { double scale = unit.getScale(); if (scale != 0.0) { if (scale == 1) { format(unit.getUnit(), buf, normalize); } else { buf.append(scale).append(' '); int start = buf.length(); format(unit.getUnit(), buf, normalize); if (start == buf.length()) buf.setLength(start - 1); } } return buf; }
/** * Raises this unit to a power. * * @param power * The power. * @return The result of raising this unit to the power. * @throws RaiseException * Can't raise this unit to a power. */ @Override protected Unit myRaiseTo(final int power) throws RaiseException { return new ScaledUnit(Math.pow(getScale(), power), getUnit().raiseTo( power)); }
/** * Divides this unit into another unit. * * @param that * The other unit. * @return The quotient of this unit divided into the other unit. * @throws OperationException * Can't divide these units. */ @Override protected Unit myDivideInto(final Unit that) throws OperationException { return that instanceof ScaledUnit ? new ScaledUnit(((ScaledUnit) that).getScale() / getScale(), getUnit().divideInto(((ScaledUnit) that).getUnit())) : new ScaledUnit(1 / getScale(), getUnit().divideInto(that)); }
/** * Raises this unit to a power. * * @param power * The power. * @return The result of raising this unit to the power. * @throws RaiseException * Can't raise this unit to a power. */ @Override protected Unit myRaiseTo(final int power) throws RaiseException { return new ScaledUnit(Math.pow(getScale(), power), getUnit().raiseTo( power)); }
/** * Divides this unit by another unit. * * @param that * The other unit. * @return The quotient of this unit divided by the other unit. * @throws OperationException * Can't divide these units. */ @Override protected Unit myDivideBy(final Unit that) throws OperationException { return that instanceof ScaledUnit ? new ScaledUnit(getScale() / ((ScaledUnit) that).getScale(), getUnit().divideBy(((ScaledUnit) that).getUnit())) : new ScaledUnit(getScale(), getUnit().divideBy(that)); }
/** * Multiplies this unit by another unit. * * @param that * The other unit. * @return The product of this unit and the other unit. * @throws MultiplyException * Can't multiply these units together. */ @Override protected Unit myMultiplyBy(final Unit that) throws MultiplyException { return that instanceof ScaledUnit ? new ScaledUnit(getScale() * ((ScaledUnit) that).getScale(), getUnit().multiplyBy(((ScaledUnit) that).getUnit())) : new ScaledUnit(getScale(), getUnit().multiplyBy(that)); }
/** * Divides this unit into another unit. * * @param that * The other unit. * @return The quotient of this unit divided into the other unit. * @throws OperationException * Can't divide these units. */ @Override protected Unit myDivideInto(final Unit that) throws OperationException { return that instanceof ScaledUnit ? new ScaledUnit(((ScaledUnit) that).getScale() / getScale(), getUnit().divideInto(((ScaledUnit) that).getUnit())) : new ScaledUnit(1 / getScale(), getUnit().divideInto(that)); }
/** * Multiplies this unit by another unit. * * @param that * The other unit. * @return The product of this unit and the other unit. * @throws MultiplyException * Can't multiply these units together. */ @Override protected Unit myMultiplyBy(final Unit that) throws MultiplyException { return that instanceof ScaledUnit ? new ScaledUnit(getScale() * ((ScaledUnit) that).getScale(), getUnit().multiplyBy(((ScaledUnit) that).getUnit())) : new ScaledUnit(getScale(), getUnit().multiplyBy(that)); }
/** * Converts a numeric value from this unit to the underlying derived unit. * * @param amount * The numeric value in this unit. * @return The equivalent value in the underlying derived unit. * @throws ConversionException * Can't convert value to the underlying derived unit. */ public double toDerivedUnit(final double amount) throws ConversionException { if (!(_unit instanceof DerivableUnit)) { throw new ConversionException(this, getDerivedUnit()); } return ((DerivableUnit) _unit).toDerivedUnit(amount * getScale()); }
/** * Converts a numeric value from this unit to the underlying derived unit. * * @param amount * The numeric value in this unit. * @return The equivalent value in the underlying derived unit. * @throws ConversionException * Can't convert value to the underlying derived unit. */ public double toDerivedUnit(final double amount) throws ConversionException { if (!(_unit instanceof DerivableUnit)) { throw new ConversionException(this, getDerivedUnit()); } return ((DerivableUnit) _unit).toDerivedUnit(amount * getScale()); }
/** * Converts a numeric value from the underlying derived unit to this unit. * * @param amount * The numeric value in the underlying derived unit. * @return The equivalent value in this unit. * @throws ConversionException * Can't convert value. */ public double fromDerivedUnit(final double amount) throws ConversionException { if (!(_unit instanceof DerivableUnit)) { throw new ConversionException(getDerivedUnit(), this); } return ((DerivableUnit) getUnit()).fromDerivedUnit(amount) / getScale(); }
/** * Converts a numeric value from the underlying derived unit to this unit. * * @param amount * The numeric value in the underlying derived unit. * @return The equivalent value in this unit. * @throws ConversionException * Can't convert value. */ public double fromDerivedUnit(final double amount) throws ConversionException { if (!(_unit instanceof DerivableUnit)) { throw new ConversionException(getDerivedUnit(), this); } return ((DerivableUnit) getUnit()).fromDerivedUnit(amount) / getScale(); }