/** * 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(); } }
/** * 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); }
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; }
/** * 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(); }
/** * Converts values in this unit to the equivalent values in the convertible * derived unit. * * @param input * The values in this unit. * @param output * The equivalent values in the convertible derived unit. May be * the same array as <code>input</code>. * @return <code>output</code>. * @throws ConversionException * Can't convert between units. */ public double[] toDerivedUnit(final double[] input, final double[] output) throws ConversionException { if (!(_unit instanceof DerivableUnit)) { throw new ConversionException(this, getDerivedUnit()); } final double origin = getOffset(); for (int i = input.length; --i >= 0;) { output[i] = input[i] + origin; } return ((DerivableUnit) getUnit()).toDerivedUnit(output, output); }
/** * Converts values in this unit to the equivalent values in the convertible * derived unit. * * @param input * The values in this unit. * @param output * The equivalent values in the convertible derived unit. May be * the same array as <code>input</code>. * @return <code>output</code>. * @throws ConversionException * Can't convert between units. */ public float[] toDerivedUnit(final float[] input, final float[] output) throws ConversionException { if (!(_unit instanceof DerivableUnit)) { throw new ConversionException(this, getDerivedUnit()); } final float origin = (float) getOffset(); for (int i = input.length; --i >= 0;) { output[i] = input[i] + origin; } return ((DerivableUnit) getUnit()).toDerivedUnit(output, output); }
/** * Converts values in this unit to the equivalent values in the convertible * derived unit. * * @param input * The values in this unit. * @param output * The equivalent values in the convertible derived unit. May be * the same array as <code>input</code>. * @return <code>output</code>. * @throws ConversionException * Can't convert between units. */ public double[] toDerivedUnit(final double[] input, final double[] output) throws ConversionException { if (!(_unit instanceof DerivableUnit)) { throw new ConversionException(this, getDerivedUnit()); } final double origin = getOffset(); for (int i = input.length; --i >= 0;) { output[i] = input[i] + origin; } return ((DerivableUnit) getUnit()).toDerivedUnit(output, output); }
/** * Converts values in the convertible derived unit to the equivalent values * in this unit. * * @param input * The values in the convertible derived unit. * @param output * The equivalent values in this unit. May be the same array as * <code>input</code>. * @return <code>output</code>. * @throws ConversionException * Can't convert between units. */ public float[] fromDerivedUnit(final float[] input, final float[] output) throws ConversionException { if (!(_unit instanceof DerivableUnit)) { throw new ConversionException(getDerivedUnit(), this); } ((DerivableUnit) getUnit()).fromDerivedUnit(input, output); final float origin = (float) getOffset(); for (int i = input.length; --i >= 0;) { output[i] -= origin; } return output; }
/** * Converts values in this unit to the equivalent values in the convertible * derived unit. * * @param input * The values in this unit. * @param output * The equivalent values in the convertible derived unit. May be * the same array as <code>input</code>. * @return <code>output</code>. * @throws ConversionException * Can't convert between units. */ public float[] toDerivedUnit(final float[] input, final float[] output) throws ConversionException { if (!(_unit instanceof DerivableUnit)) { throw new ConversionException(this, getDerivedUnit()); } final float origin = (float) getOffset(); for (int i = input.length; --i >= 0;) { output[i] = input[i] + origin; } return ((DerivableUnit) getUnit()).toDerivedUnit(output, output); }
/** * Converts values in the convertible derived unit to the equivalent values * in this unit. * * @param input * The values in the convertible derived unit. * @param output * The equivalent values in this unit. May be the same array as * <code>input</code>. * @return <code>output</code>. * @throws ConversionException * Can't convert between units. */ public double[] fromDerivedUnit(final double[] input, final double[] output) throws ConversionException { if (!(_unit instanceof DerivableUnit)) { throw new ConversionException(getDerivedUnit(), this); } ((DerivableUnit) getUnit()).fromDerivedUnit(input, output); final double origin = getOffset(); for (int i = input.length; --i >= 0;) { output[i] -= origin; } return output; }
/** * Converts values in the convertible derived unit to the equivalent values * in this unit. * * @param input * The values in the convertible derived unit. * @param output * The equivalent values in this unit. May be the same array as * <code>input</code>. * @return <code>output</code>. * @throws ConversionException * Can't convert between units. */ public float[] fromDerivedUnit(final float[] input, final float[] output) throws ConversionException { if (!(_unit instanceof DerivableUnit)) { throw new ConversionException(getDerivedUnit(), this); } ((DerivableUnit) getUnit()).fromDerivedUnit(input, output); final float origin = (float) getOffset(); for (int i = input.length; --i >= 0;) { output[i] -= origin; } return output; }
/** * Converts values in the convertible derived unit to the equivalent values * in this unit. * * @param input * The values in the convertible derived unit. * @param output * The equivalent values in this unit. May be the same array as * <code>input</code>. * @return <code>output</code>. * @throws ConversionException * Can't convert between units. */ public double[] fromDerivedUnit(final double[] input, final double[] output) throws ConversionException { if (!(_unit instanceof DerivableUnit)) { throw new ConversionException(getDerivedUnit(), this); } ((DerivableUnit) getUnit()).fromDerivedUnit(input, output); final double origin = getOffset(); for (int i = input.length; --i >= 0;) { output[i] -= origin; } return output; }