private static UnitConverter valueOf(double factor) { float asFloat = (float) factor; return asFloat == 1.0f ? UnitConverter.IDENTITY : new MultiplyConverter(factor); }
@Override public UnitConverter concatenate(UnitConverter converter) { if (converter instanceof MultiplyConverter) { double factor = _factor * ((MultiplyConverter) converter)._factor; return valueOf(factor); } else if (converter instanceof RationalConverter) { double factor = _factor * ((RationalConverter) converter).getDividend() / ((RationalConverter) converter).getDivisor(); return valueOf(factor); } else { return super.concatenate(converter); } }
} else if (cvtr instanceof MultiplyConverter) { result.append('*'); result.append(((MultiplyConverter) cvtr).getFactor()); } else { // Other converters. return "[" + baseUnits + "?]";
@Override public UnitConverter concatenate(UnitConverter converter) { if (converter instanceof MultiplyConverter) { double factor = _factor * ((MultiplyConverter) converter)._factor; return valueOf(factor); } else if (converter instanceof RationalConverter) { double factor = _factor * ((RationalConverter) converter).getDividend() / ((RationalConverter) converter).getDivisor(); return valueOf(factor); } else { return super.concatenate(converter); } }
} else if (cvtr instanceof MultiplyConverter) { result.append('*'); result.append(((MultiplyConverter) cvtr).getFactor()); } else { // Other converters. return "[" + baseUnits + "?]";
private static UnitConverter valueOf(double factor) { float asFloat = (float) factor; return asFloat == 1.0f ? UnitConverter.IDENTITY : new MultiplyConverter(factor); }
@Override public UnitConverter concatenate(UnitConverter converter) { if (converter instanceof MultiplyConverter) { double factor = _factor * ((MultiplyConverter) converter)._factor; return valueOf(factor); } else if (converter instanceof RationalConverter) { double factor = _factor * ((RationalConverter) converter).getDividend() / ((RationalConverter) converter).getDivisor(); return valueOf(factor); } else { return super.concatenate(converter); } }
result.append(((MultiplyConverter) cvtr).getFactor()); } else { // Other converters. return "[" + baseUnits + "?]";
private static UnitConverter valueOf(double factor) { float asFloat = (float) factor; return asFloat == 1.0f ? UnitConverter.IDENTITY : new MultiplyConverter(factor); }
@Override public UnitConverter inverse() { return new MultiplyConverter(1.0 / _factor); }
@Override public UnitConverter inverse() { return new MultiplyConverter(1.0 / _factor); }
@Override public UnitConverter inverse() { return new MultiplyConverter(1.0 / _factor); }
/** * Returns the result of multiplying this unit by a an approximate factor * * @param factor the approximate factor (e.g. * <code>ELECTRON_MASS = KILOGRAM.times(9.10938188e-31)</code>). * @return <code>this.transform(new MultiplyConverter(factor))</code> */ public final Unit<Q> times(double factor) { return transform(new MultiplyConverter(factor)); }
/** * Returns the result of multiplying this unit by a an approximate factor * * @param factor the approximate factor (e.g. * <code>ELECTRON_MASS = KILOGRAM.times(9.10938188e-31)</code>). * @return <code>this.transform(new MultiplyConverter(factor))</code> */ public final Unit<Q> times(double factor) { return transform(new MultiplyConverter(factor)); }
/** * Returns the result of dividing this unit by an approximate divisor. * * @param divisor the approximate divisor. * @return <code>this.transform(new MultiplyConverter(1.0 / divisor))</code> */ public final Unit<Q> divide(double divisor) { return transform(new MultiplyConverter(1.0 / divisor)); }
/** * Returns the result of dividing this unit by an approximate divisor. * * @param divisor the approximate divisor. * @return <code>this.transform(new MultiplyConverter(1.0 / divisor))</code> */ public final Unit<Q> divide(double divisor) { return transform(new MultiplyConverter(1.0 / divisor)); }
/** * Returns the result of dividing this unit by an approximate divisor. * * @param divisor the approximate divisor. * @return <code>this.transform(new MultiplyConverter(1.0 / divisor))</code> */ public final Unit<Q> divide(double divisor) { return transform(new MultiplyConverter(1.0 / divisor)); }
/** * Returns the result of multiplying this unit by a an approximate factor * * @param factor the approximate factor (e.g. * <code>ELECTRON_MASS = KILOGRAM.times(9.10938188e-31)</code>). * @return <code>this.transform(new MultiplyConverter(factor))</code> */ public final Unit<Q> times(double factor) { return transform(new MultiplyConverter(factor)); }
@Override public UnitConverter concatenate(UnitConverter converter) { if (converter instanceof RationalConverter) { RationalConverter that = (RationalConverter) converter; long dividendLong = this._dividend * that._dividend; long divisorLong = this._divisor * that._divisor; double dividendDouble = ((double)this._dividend) * that._dividend; double divisorDouble = ((double)this._divisor) * that._divisor; if ((dividendLong != dividendDouble) || (divisorLong != divisorDouble)) { // Long overflows. return new MultiplyConverter(dividendDouble / divisorDouble); } long gcd = gcd(dividendLong, divisorLong); return RationalConverter.valueOf(dividendLong / gcd, divisorLong / gcd); } else if (converter instanceof MultiplyConverter) { return converter.concatenate(this); } else { return super.concatenate(converter); } }
@Override public UnitConverter concatenate(UnitConverter converter) { if (converter instanceof RationalConverter) { RationalConverter that = (RationalConverter) converter; long dividendLong = this._dividend * that._dividend; long divisorLong = this._divisor * that._divisor; double dividendDouble = ((double)this._dividend) * that._dividend; double divisorDouble = ((double)this._divisor) * that._divisor; if ((dividendLong != dividendDouble) || (divisorLong != divisorDouble)) { // Long overflows. return new MultiplyConverter(dividendDouble / divisorDouble); } long gcd = gcd(dividendLong, divisorLong); return RationalConverter.valueOf(dividendLong / gcd, divisorLong / gcd); } else if (converter instanceof MultiplyConverter) { return converter.concatenate(this); } else { return super.concatenate(converter); } }