/** * Clones this unit, changing the identifier. * * @param id * The new identifier. * @return A ScaledUnit with the new identifier. */ public Unit clone(final UnitName id) { return new ScaledUnit(_scale, getUnit(), id); }
/** * Gets the derived unit underlying this unit. * * @return The derived unit which underlies this unit. */ public DerivedUnit getDerivedUnit() { return getUnit().getDerivedUnit(); }
/** * Indicates if this unit is dimensionless. A ScaledUnit is dimensionless if * and only if the reference unit is dimensionless. * * @return <code>true</code> if and only if this unit is dimensionless. */ public boolean isDimensionless() { return getUnit().isDimensionless(); }
/** * Clones this unit, changing the identifier. * * @param id * The new identifier. * @return A ScaledUnit with the new identifier. */ public Unit clone(final UnitName id) { return new ScaledUnit(_scale, getUnit(), id); }
/** * Gets the derived unit underlying this unit. * * @return The derived unit which underlies this unit. */ public DerivedUnit getDerivedUnit() { return getUnit().getDerivedUnit(); }
/** * Indicates if this unit is dimensionless. A ScaledUnit is dimensionless if * and only if the reference unit is dimensionless. * * @return <code>true</code> if and only if this unit is dimensionless. */ public boolean isDimensionless() { return getUnit().isDimensionless(); }
/** * Returns the hash code of this instance. * * @return The hash code of this instance. */ @Override public int hashCode() { return (getScale() == 1 ? 0 : Double.valueOf(getScale()).hashCode()) ^ getUnit().hashCode(); }
/** * Returns the hash code of this instance. * * @return The hash code of this instance. */ @Override public int hashCode() { return (getScale() == 1 ? 0 : Double.valueOf(getScale()).hashCode()) ^ getUnit().hashCode(); }
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)); }
/** * 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)); }
/** * 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)); }
/** * 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)); }
/** * 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(); }