/** * Returns the combination of this unit with the specified sub-unit. * Compound units are typically used for formatting purpose. * Examples of compound units:[code] * HOUR_MINUTE = NonSI.HOUR.compound(NonSI.MINUTE); * DEGREE_MINUTE_SECOND_ANGLE = NonSI.DEGREE_ANGLE.compound( * NonSI.DEGREE_MINUTE).compound(NonSI.SECOND_ANGLE); * [/code] * * @param subunit the sub-unit to combine with this unit. * @return the corresponding compound unit. */ public final CompoundUnit<Q> compound(Unit<Q> subunit) { return new CompoundUnit<>(this, subunit); }
StringBuffer formatCompound(double value, Unit<?> unit, StringBuffer toAppendTo, FieldPosition pos) { if (!(unit instanceof CompoundUnit)) { toAppendTo.append((long) value); return _unitFormat.format(unit, toAppendTo, pos); } Unit<?> high = ((CompoundUnit<?>) unit).getHigher(); Unit<?> low = ((CompoundUnit<?>) unit).getLower(); // The unit in which the value is stated. long highValue = (long) low.getConverterTo(high).convert(value); double lowValue = value - high.getConverterTo(low).convert(highValue); formatCompound(highValue, high, toAppendTo, pos); formatCompound(lowValue, low, toAppendTo, pos); return toAppendTo; }
StringBuffer formatCompound(double value, Unit<?> unit, StringBuffer toAppendTo, FieldPosition pos) { if (!(unit instanceof CompoundUnit)) { toAppendTo.append((long) value); return _unitFormat.format(unit, toAppendTo, pos); } Unit<?> high = ((CompoundUnit<?>) unit).getHigher(); Unit<?> low = ((CompoundUnit<?>) unit).getLower(); // The unit in which the value is stated. long highValue = (long) low.getConverterTo(high).convert(value); double lowValue = value - high.getConverterTo(low).convert(highValue); formatCompound(highValue, high, toAppendTo, pos); formatCompound(lowValue, low, toAppendTo, pos); return toAppendTo; }
StringBuffer formatCompound(double value, Unit<?> unit, StringBuffer toAppendTo, FieldPosition pos) { if (!(unit instanceof CompoundUnit)) { toAppendTo.append((long) value); return _unitFormat.format(unit, toAppendTo, pos); } Unit<?> high = ((CompoundUnit<?>) unit).getHigher(); Unit<?> low = ((CompoundUnit<?>) unit).getLower(); // The unit in which the value is stated. long highValue = (long) low.getConverterTo(high).convert(value); double lowValue = value - high.getConverterTo(low).convert(highValue); formatCompound(highValue, high, toAppendTo, pos); formatCompound(lowValue, low, toAppendTo, pos); return toAppendTo; }
/** * Returns the combination of this unit with the specified sub-unit. * Compound units are typically used for formatting purpose. * Examples of compound units:[code] * HOUR_MINUTE = NonSI.HOUR.compound(NonSI.MINUTE); * DEGREE_MINUTE_SECOND_ANGLE = NonSI.DEGREE_ANGLE.compound( * NonSI.DEGREE_MINUTE).compound(NonSI.SECOND_ANGLE); * [/code] * * @param subunit the sub-unit to combine with this unit. * @return the corresponding compound unit. */ public final CompoundUnit<Q> compound(Unit<Q> subunit) { return new CompoundUnit<Q>(this, subunit); }
/** * Returns the combination of this unit with the specified sub-unit. * Compound units are typically used for formatting purpose. * Examples of compound units:[code] * HOUR_MINUTE = NonSI.HOUR.compound(NonSI.MINUTE); * DEGREE_MINUTE_SECOND_ANGLE = NonSI.DEGREE_ANGLE.compound( * NonSI.DEGREE_MINUTE).compound(NonSI.SECOND_ANGLE); * [/code] * * @param subunit the sub-unit to combine with this unit. * @return the corresponding compound unit. */ public final CompoundUnit<Q> compound(Unit<Q> subunit) { return new CompoundUnit<Q>(this, subunit); }