/** * 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); }
/** * Indicates if this unit is dimensionless. * * @return <code>true</code> if and only if this unit is dimensionless. */ public boolean isDimensionless() { return getUnit().isDimensionless(); }
/** * Indicates if this unit is dimensionless. * * @return <code>true</code> if and only if this unit is dimensionless. */ public boolean isDimensionless() { return getUnit().isDimensionless(); }
/** * Multiply this unit by another unit. * * @param that * The unit to multiply this unit by. * @return The product of this unit and <code>that</code>. The offset of * this unit will be ignored; thus, for example * "celsius.myMultiplyBy(day)" is equivalent to * "kelvin.myMultiplyBy(day)". * @throws MultiplyException * Can't multiply these units together. */ @Override protected Unit myMultiplyBy(final Unit that) throws MultiplyException { return that instanceof OffsetUnit ? getUnit().multiplyBy(((OffsetUnit) that).getUnit()) : getUnit().multiplyBy(that); }
/** * Divide this unit into another unit. * * @param that * The unit to divide this unit into. * @return The quotient of <code>that</code> unit and this unit. The offset * of this unit will be ignored; thus, for example * "celsius.myDivideInto(day)" is equivalent to * "kelvin.myDivideInto(day)". * @throws OperationException * Can't divide these units. */ @Override protected Unit myDivideInto(final Unit that) throws OperationException { return that instanceof OffsetUnit ? getUnit().divideInto(((OffsetUnit) that).getUnit()) : getUnit().divideInto(that); }
/** * Divide this unit into another unit. * * @param that * The unit to divide this unit into. * @return The quotient of <code>that</code> unit and this unit. The offset * of this unit will be ignored; thus, for example * "celsius.myDivideInto(day)" is equivalent to * "kelvin.myDivideInto(day)". * @throws OperationException * Can't divide these units. */ @Override protected Unit myDivideInto(final Unit that) throws OperationException { return that instanceof OffsetUnit ? getUnit().divideInto(((OffsetUnit) that).getUnit()) : getUnit().divideInto(that); }
/** * Raise this unit to a power. * * @param power * The power to raise this unit by. * @return The result of raising this unit by the power <code>power</code>. * The offset of this unit will be ignored; thus, for example * "celsius.myRaiseTo(2)" is equivalent to "kelvin.myRaiseTo(2)". * @throws RaiseException * Can't raise this unit to a power. */ // Ignore offset (e.g. "Cel2" == "K2") @Override protected Unit myRaiseTo(final int power) throws RaiseException { return getUnit().raiseTo(power); }
/** * Returns the hash code of this instance. * * @return The hash code of this instance. */ @Override public int hashCode() { return (getOffset() == 0 ? 0 : Double.valueOf(getOffset()).hashCode()) ^ getUnit().hashCode(); }
/** * Raise this unit to a power. * * @param power * The power to raise this unit by. * @return The result of raising this unit by the power <code>power</code>. * The offset of this unit will be ignored; thus, for example * "celsius.myRaiseTo(2)" is equivalent to "kelvin.myRaiseTo(2)". * @throws RaiseException * Can't raise this unit to a power. */ // Ignore offset (e.g. "Cel2" == "K2") @Override protected Unit myRaiseTo(final int power) throws RaiseException { return getUnit().raiseTo(power); }
/** * Returns the hash code of this instance. * * @return The hash code of this instance. */ @Override public int hashCode() { return (getOffset() == 0 ? 0 : Double.valueOf(getOffset()).hashCode()) ^ getUnit().hashCode(); }
private StringBuffer format(OffsetUnit unit, StringBuffer buf, boolean normalize) throws UnitClassException { double offset = unit.getOffset(); if (offset == 0.0) { format(unit.getUnit(), buf, normalize); } else { int start = buf.length(); format(unit.getUnit(), buf, normalize); return (isBlackSpace(buf, start) ? buf : buf.insert(start, '(').append(')')). append(" @ ").append(offset); } return buf; }
private StringBuffer format(OffsetUnit unit, StringBuffer buf, boolean normalize) throws UnitClassException { double offset = unit.getOffset(); if (offset == 0.0) { format(unit.getUnit(), buf, normalize); } else { int start = buf.length(); format(unit.getUnit(), buf, normalize); return (isBlackSpace(buf, start) ? buf : buf.insert(start, '(').append(')')). append(" @ ").append(offset); } return buf; }
/** * 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); }
/** * 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); }
/** * Returns the canonical string representation of the unit. * * @return The canonical string representation. */ public String getCanonicalString() { return "(" + getUnit().toString() + ") @ " + getOffset(); } }
/** * Returns the canonical string representation of the unit. * * @return The canonical string representation. */ public String getCanonicalString() { return "(" + getUnit().toString() + ") @ " + getOffset(); } }
/** * 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()); }
/** * 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(); }
/** * 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()); }
/** * 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(); }