/** * Clones this unit, changing the identifier. * * @param id * The identifier for the new unit. * @return This unit with its identifier changed. */ public Unit clone(final UnitName id) { return new OffsetUnit(getUnit(), getOffset(), id); }
/** * Converts a value in the convertible derived unit to the equivalent value * in this unit. * * @param amount * The value in the convertible derived unit. * @return The equivalent value in this unit. * @throws ConversionException * Can't convert between units. */ public float fromDerivedUnit(final float amount) throws ConversionException { return (float) fromDerivedUnit((double) amount); }
public Unit shiftTo(final double origin) throws ShiftException { return OffsetUnit.getInstance(this, origin); }
/** * Converts a value in this unit to the equivalent value in the convertible * derived unit. * * @param amount * The value in this unit. * @return The equivalent value in the convertible derived unit. * @throws ConversionException * Can't convert between units. */ public double toDerivedUnit(final double amount) throws ConversionException { if (!(_unit instanceof DerivableUnit)) { throw new ConversionException(this, getDerivedUnit()); } return ((DerivableUnit) getUnit()).toDerivedUnit(amount + getOffset()); }
/** * 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>. The offset of * this unit will be ignored; thus, for example * "celsius.myDivideBy(day)" is equivalent to * "kelvin.myDivideBy(day)". * @throws OperationException * Can't divide these units. */ @Override protected Unit myDivideBy(final Unit that) throws OperationException { return that instanceof OffsetUnit ? getUnit().divideBy(((OffsetUnit) that).getUnit()) : getUnit().divideBy(that); }
/** * Returns the string representation of this unit. * * @return The string representation of this unit. */ @Override public String toString() { final String string = super.toString(); // get symbol or name return string != null ? string : getCanonicalString(); }
/** * Converts a value in this unit to the equivalent value in the convertible * derived unit. * * @param amount * The value in this unit. * @return The equivalent value in the convertible derived unit. * @throws ConversionException * Can't convert between units. */ public float toDerivedUnit(final float amount) throws ConversionException { return (float) toDerivedUnit((double) amount); }
static Unit getInstance(final Unit unit, final double origin) { return (origin == 0) ? unit : new OffsetUnit(unit, origin); }
/** * Converts a value in the convertible derived unit to the equivalent value * in this unit. * * @param amount * The value in the convertible derived unit. * @return The equivalent value in this unit. * @throws ConversionException * Can't convert between units. */ public double fromDerivedUnit(final double amount) throws ConversionException { if (!(_unit instanceof DerivableUnit)) { throw new ConversionException(getDerivedUnit(), this); } return ((DerivableUnit) getUnit()).fromDerivedUnit(amount) - getOffset(); }
/** * Indicates if this unit is dimensionless. * * @return <code>true</code> if and only if this unit is dimensionless. */ public boolean isDimensionless() { return getUnit().isDimensionless(); }
/** * Returns the string representation of this unit. * * @return The string representation of this unit. */ @Override public String toString() { final String string = super.toString(); // get symbol or name return string != null ? string : getCanonicalString(); }
/** * Converts a value in this unit to the equivalent value in the convertible * derived unit. * * @param amount * The value in this unit. * @return The equivalent value in the convertible derived unit. * @throws ConversionException * Can't convert between units. */ public float toDerivedUnit(final float amount) throws ConversionException { return (float) toDerivedUnit((double) amount); }
static Unit getInstance(final Unit unit, final double origin) { return (origin == 0) ? unit : new OffsetUnit(unit, origin); }
/** * Converts a value in this unit to the equivalent value in the convertible * derived unit. * * @param amount * The value in this unit. * @return The equivalent value in the convertible derived unit. * @throws ConversionException * Can't convert between units. */ public double toDerivedUnit(final double amount) throws ConversionException { if (!(_unit instanceof DerivableUnit)) { throw new ConversionException(this, getDerivedUnit()); } return ((DerivableUnit) getUnit()).toDerivedUnit(amount + getOffset()); }
/** * Clones this unit, changing the identifier. * * @param id * The identifier for the new unit. * @return This unit with its identifier changed. */ public Unit clone(final UnitName id) { return new OffsetUnit(getUnit(), getOffset(), id); }
/** * Indicates if this unit is dimensionless. * * @return <code>true</code> if and only if this unit is dimensionless. */ public boolean isDimensionless() { return getUnit().isDimensionless(); }
@Override public Unit shiftTo(final double origin) { return getInstance(_unit, origin + _offset); }