/** * Returns the result of setting the origin of the scale of measurement to the given value. * For example {@code CELSIUS = KELVIN.shift(273.15)} returns a unit where 0°C is equals to 273.15 K. * * @param offset the value to add when converting from the new unit to this unit. * @return this unit offset by the specified value, or {@code this} if the given offset is zero. */ @Override public final Unit<Q> shift(final double offset) { return transform(LinearConverter.offset(offset, 1)); }
/** * Creates a quantity for the given value and unit of measurement symbol. * This is a convenience method that combines a call to {@link Units#valueOf(String)} * with {@link #create(double, Unit)}. * * @param value the quantity magnitude. * @param unit symbol of the unit of measurement associated to the given value. * @return a quantity of the given type for the given value and unit of measurement. * @throws ParserException if the given symbol can not be parsed. */ public static Quantity<?> create(final double value, final String unit) { return create(value, Units.valueOf(unit)); }
/** * Creates a quantity for the given value and unit of measurement. */ @Override public Quantity<Q> create(final Number value, final Unit<Q> unit) { final double v = AbstractConverter.doubleValue(value); if (factory != null) { return factory.create(v, unit); } else { return ScalarFallback.factory(v, unit, quantity); } } }
/** * Returns a unit equals to this unit raised to an exponent. * * @param n the exponent. * @return the result of raising this unit to the exponent. */ @Override public Unit<?> pow(final int n) { ensureRatioScale(); final Unit<?> result = target.pow(n); return (result == target) ? this : result.transform(LinearConverter.pow(toTarget, n, false)); }
/** * Invoked on deserialization for returning a unique instance of {@code AbstractUnit} if possible. */ final Object readResolve() throws ObjectStreamException { if (symbol != null && Units.initialized) { // Force Units class initialization. final Object existing = UnitRegistry.putIfAbsent(symbol, this); if (equals(existing)) { return (Unit<?>) existing; } } return this; } }
@Override public Quantity<Q> create(final Number value, final Unit<Q> unit) { return ScalarFallback.factory(AbstractConverter.doubleValue(value), unit, type); }
/** * Returns a unit equals to the given root of this unit. * * @param n the root's order. * @return the result of taking the given root of this unit. * @throws ArithmeticException if {@code n == 0}. */ @Override public Unit<?> root(final int n) { ensureRatioScale(); return applyConversion(target.root(n), n, true); }
/** * Invoked by {@code Units} static class initializer for registering SI base and derived units. * This method shall be invoked in a single thread by the {@code Units} class initializer only. */ private static <Q extends Quantity<Q>> SystemUnit<Q> add(Class<Q> quantity, ScalarFactory<Q> factory, UnitDimension dimension, String symbol, byte scope, short epsg) { return UnitRegistry.init(new SystemUnit<>(quantity, dimension, symbol, scope, epsg, factory)); }
/** * Returns a unit equals to this unit raised to an exponent. * * @param n the exponent. * @return the result of raising this unit to the exponent. */ @Override public Unit<?> pow(final int n) { ensureRatioScale(); return applyConversion(target.pow(n), n, false); }
@Override Quantity<javax.measure.quantity.Temperature> create(double value, Unit<javax.measure.quantity.Temperature> unit) { return new Temperature(value, unit); } }
/** * Creates a quantity for the given value and unit of measurement. */ @Override public Quantity<Q> create(final Number value, final Unit<Q> unit) { final double v = AbstractConverter.doubleValue(value); if (factory != null) { return factory.create(v, unit); } else { return ScalarFallback.factory(v, unit, quantity); } } }
/** * Invoked on deserialization for returning a unique instance of {@code AbstractUnit} if possible. */ final Object readResolve() throws ObjectStreamException { if (symbol != null && Units.initialized) { // Force Units class initialization. final Object existing = UnitRegistry.putIfAbsent(symbol, this); if (equals(existing)) { return (Unit<?>) existing; } } return this; } }
@Override public Quantity<Q> create(final Number value, final Unit<Q> unit) { return ScalarFallback.factory(AbstractConverter.doubleValue(value), unit, type); }