/** * Formats a unit in the underlying system of units. * * @param unit The unit to be formatted. * @param buf The buffer to append to. * @return The appended-to buffer. * @throws UnitClassException The class of the unit is unknown. */ public StringBuffer longFormat(Unit unit, StringBuffer buf) throws UnitClassException { return format(unit, buf, false); }
/** * Formats a unit. The symbol or name will be used if available; * otherwise, a specification in terms of underlying units will be * returned. * * @param unit The unit to be formatted. * @param buf The buffer to append to. * @return The appended-to buffer. * @throws UnitClassException The class of the unit is unknown. */ public StringBuffer format(Unit unit, StringBuffer buf) throws UnitClassException { return format(unit, buf, true); }
/** * Formats a unit in the underlying system of units. * * @param unit The unit to be formatted. * @param buf The buffer to append to. * @return The appended-to buffer. * @throws UnitClassException The class of the unit is unknown. */ public StringBuffer longFormat(Unit unit, StringBuffer buf) throws UnitClassException { return format(unit, buf, false); }
/** * Formats a unit. The symbol or name will be used if available; * otherwise, a specification in terms of underlying units will be * returned. * * @param unit The unit to be formatted. * @param buf The buffer to append to. * @return The appended-to buffer. * @throws UnitClassException The class of the unit is unknown. */ public StringBuffer format(Unit unit, StringBuffer buf) throws UnitClassException { return format(unit, buf, true); }
private StringBuffer format(DerivedUnit unit, StringBuffer buf) { Factor[] factors = unit.getDimension().getFactors(); Arrays.sort(factors, factorComparator); for (int i = 0; i < factors.length; i++) format(factors[i], buf).append('.'); if (factors.length != 0) buf.setLength(buf.length() - 1); return buf; }
private StringBuffer format(DerivedUnit unit, StringBuffer buf) { Factor[] factors = unit.getDimension().getFactors(); Arrays.sort(factors, factorComparator); for (int i = 0; i < factors.length; i++) format(factors[i], buf).append('.'); if (factors.length != 0) buf.setLength(buf.length() - 1); return buf; }
private StringBuffer format(ScaledUnit unit, StringBuffer buf, boolean normalize) throws UnitClassException { double scale = unit.getScale(); if (scale != 0.0) { if (scale == 1) { format(unit.getUnit(), buf, normalize); } else { buf.append(scale).append(' '); int start = buf.length(); format(unit.getUnit(), buf, normalize); if (start == buf.length()) buf.setLength(start - 1); } } return buf; }
private StringBuffer format(TimeScaleUnit unit, StringBuffer buf, boolean normalize) throws UnitClassException { return format(unit.getUnit(), buf, normalize). append(dateFormat.format(unit.getOrigin())); }
private StringBuffer format(TimeScaleUnit unit, StringBuffer buf, boolean normalize) throws UnitClassException { return format(unit.getUnit(), buf, normalize). append(dateFormat.format(unit.getOrigin())); }
format((BaseUnit) unit, buf); else if (unit instanceof DerivedUnit) format((DerivedUnit) unit, buf); else if (unit instanceof ScaledUnit) format((ScaledUnit) unit, buf, normalize); else if (unit instanceof OffsetUnit) format((OffsetUnit) unit, buf, normalize); else if (unit instanceof TimeScaleUnit) format((TimeScaleUnit) unit, buf, normalize); else throw new UnitClassException(unit);
private StringBuffer format(ScaledUnit unit, StringBuffer buf, boolean normalize) throws UnitClassException { double scale = unit.getScale(); if (scale != 0.0) { if (scale == 1) { format(unit.getUnit(), buf, normalize); } else { buf.append(scale).append(' '); int start = buf.length(); format(unit.getUnit(), buf, normalize); if (start == buf.length()) buf.setLength(start - 1); } } return buf; }
format((BaseUnit) unit, buf); else if (unit instanceof DerivedUnit) format((DerivedUnit) unit, buf); else if (unit instanceof ScaledUnit) format((ScaledUnit) unit, buf, normalize); else if (unit instanceof OffsetUnit) format((OffsetUnit) unit, buf, normalize); else if (unit instanceof TimeScaleUnit) format((TimeScaleUnit) unit, buf, normalize); else throw new UnitClassException(unit);
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; }