static Unit getInstance(final double scale, final Unit unit) throws MultiplyException { if (scale == 0) { throw new MultiplyException(scale, unit); } return scale == 1 ? unit : new ScaledUnit(scale, unit); }
/** * 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); }
/** * 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); }
static Unit getInstance(final double scale, final Unit unit) throws MultiplyException { if (scale == 0) { throw new MultiplyException(scale, unit); } return scale == 1 ? unit : new ScaledUnit(scale, unit); }
/** * 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)); }
/** * 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)); }
/** * Multiply this unit by another unit. * * @param that * The unit to multiply this unit by. Must be dimensionless. * @return The product of this unit and <code>that</code>. * @throws MultiplyException * Can't multiply these units together. */ @Override protected Unit myMultiplyBy(final Unit that) throws MultiplyException { if (!that.isDimensionless()) { throw new MultiplyException(that); } return that instanceof ScaledUnit ? new ScaledUnit(((ScaledUnit) that).getScale(), this) : this; }
/** * Divide this unit by another unit. * * @param that * The unit to divide this unit by. * @return The quotient of this unit and <code>that</code>. * @throws DivideException * Can't divide these units. */ @Override protected Unit myDivideBy(final Unit that) throws DivideException { if (!that.isDimensionless()) { throw new DivideException(that); } return that instanceof ScaledUnit ? new ScaledUnit(1.0 / ((ScaledUnit) that).getScale(), this) : this; }
/** * Multiply this unit by another unit. * * @param that * The unit to multiply this unit by. Must be dimensionless. * @return The product of this unit and <code>that</code>. * @throws MultiplyException * Can't multiply these units together. */ @Override protected Unit myMultiplyBy(final Unit that) throws MultiplyException { if (!that.isDimensionless()) { throw new MultiplyException(that); } return that instanceof ScaledUnit ? new ScaledUnit(((ScaledUnit) that).getScale(), this) : this; }
/** * Divide this unit by another unit. * * @param that * The unit to divide this unit by. * @return The quotient of this unit and <code>that</code>. * @throws DivideException * Can't divide these units. */ @Override protected Unit myDivideBy(final Unit that) throws DivideException { if (!that.isDimensionless()) { throw new DivideException(that); } return that instanceof ScaledUnit ? new ScaledUnit(1.0 / ((ScaledUnit) that).getScale(), this) : this; }
/** * 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 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)); }
/** * 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)); }
/** * 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)); }
final BaseUnit meter = BaseUnit.getOrCreate(UnitName.newUnitName( "meter", null, "m"), BaseQuantity.LENGTH); final ScaledUnit nauticalMile = new ScaledUnit(1852f, meter); System.out.println("nauticalMile.getUnit().equals(meter)=" + nauticalMile.getUnit().equals(meter)); System.out.println("nauticalMile.equals(nauticalMile)=" + nauticalMile.equals(nauticalMile)); final ScaledUnit nautical2Mile = new ScaledUnit(2, nauticalMile); System.out.println("nauticalMile.equals(nautical2Mile)=" + nauticalMile.equals(nautical2Mile)); final BaseUnit radian = BaseUnit.getOrCreate(UnitName.newUnitName( "radian", null, "rad"), BaseQuantity.PLANE_ANGLE); final ScaledUnit degree = new ScaledUnit(3.14159 / 180, radian); System.out.println("degree.isDimensionless()=" + degree.isDimensionless());
final BaseUnit meter = BaseUnit.getOrCreate(UnitName.newUnitName( "meter", null, "m"), BaseQuantity.LENGTH); final ScaledUnit nauticalMile = new ScaledUnit(1852f, meter); System.out.println("nauticalMile.getUnit().equals(meter)=" + nauticalMile.getUnit().equals(meter)); System.out.println("nauticalMile.equals(nauticalMile)=" + nauticalMile.equals(nauticalMile)); final ScaledUnit nautical2Mile = new ScaledUnit(2, nauticalMile); System.out.println("nauticalMile.equals(nautical2Mile)=" + nauticalMile.equals(nautical2Mile)); final BaseUnit radian = BaseUnit.getOrCreate(UnitName.newUnitName( "radian", null, "rad"), BaseQuantity.PLANE_ANGLE); final ScaledUnit degree = new ScaledUnit(3.14159 / 180, radian); System.out.println("degree.isDimensionless()=" + degree.isDimensionless());