(float) tunit1.getSystemConverter() .concatenate(tunit2.getSystemConverter().inverse()) .convert(1.0f);
@Override public UnitConverter getSystemConverter() { return parentUnit.getSystemConverter().concatenate(converter); }
@Override public UnitConverter getSystemConverter() { return parentUnit.getSystemConverter().concatenate(converter); }
@Override public UnitConverter getSystemConverter() { return parentUnit.getSystemConverter().concatenate(converter); }
/** * Concatenates this converter with another converter. The resulting converter is equivalent to first converting * by the specified converter (right converter), and then converting by this converter (left converter). */ @Override public UnitConverter concatenate(final UnitConverter converter) { ArgumentChecks.ensureNonNull("converter", converter); if (equals(converter.inverse())) { return LinearConverter.IDENTITY; } // Delegate to c1 and c2 because they may provide more intelligent 'concatenate' implementations. return c2.concatenate(c1.concatenate(converter)); }
/** * Concatenates this converter with another converter. The resulting converter is equivalent to first converting * by the specified converter (right converter), and then converting by this converter (left converter). */ @Override public UnitConverter concatenate(final UnitConverter converter) { ArgumentChecks.ensureNonNull("converter", converter); if (equals(converter.inverse())) { return LinearConverter.IDENTITY; } // Delegate to c1 and c2 because they may provide more intelligent 'concatenate' implementations. return c2.concatenate(c1.concatenate(converter)); }
@Override public UnitConverter getSystemConverter() { UnitConverter converter = AbstractConverter.IDENTITY; for (Element e : elements) { if (e.unit instanceof AbstractUnit) { UnitConverter cvtr = ((AbstractUnit) e.unit).getSystemConverter(); if (!(cvtr.isLinear())) throw new UnsupportedOperationException(e.unit + " is non-linear, cannot convert"); if (e.root != 1) throw new UnsupportedOperationException(e.unit + " holds a base unit with fractional exponent"); int pow = e.pow; if (pow < 0) { // Negative power. pow = -pow; cvtr = cvtr.inverse(); } for (int j = 0; j < pow; j++) { converter = converter.concatenate(cvtr); } } } return converter; }
@Override public UnitConverter getSystemConverter() { UnitConverter converter = AbstractConverter.IDENTITY; for (Element e : elements) { if (e.unit instanceof AbstractUnit) { UnitConverter cvtr = ((AbstractUnit) e.unit).getSystemConverter(); if (!(cvtr.isLinear())) throw new UnsupportedOperationException(e.unit + " is non-linear, cannot convert"); if (e.root != 1) throw new UnsupportedOperationException(e.unit + " holds a base unit with fractional exponent"); int pow = e.pow; if (pow < 0) { // Negative power. pow = -pow; cvtr = cvtr.inverse(); } for (int j = 0; j < pow; j++) { converter = converter.concatenate(cvtr); } } } return converter; }
@Override public final Unit<Q> transform(UnitConverter operation) { Unit<Q> systemUnit = this.getSystemUnit(); UnitConverter cvtr; if (this.isSystemUnit()) { cvtr = this.getSystemConverter().concatenate(operation); } else { cvtr = operation; } if (cvtr.equals(AbstractConverter.IDENTITY)) { return systemUnit; } else { return new TransformedUnit<>(null, this, systemUnit, cvtr); } }
@Override public final AbstractUnit<Q> transform(UnitConverter operation) { Unit<Q> systemUnit = this.getSystemUnit(); UnitConverter cvtr; if (this.isSystemUnit()) { cvtr = this.getSystemConverter().concatenate(operation); } else { cvtr = operation; } if (cvtr.equals(AbstractConverter.IDENTITY) && systemUnit instanceof AbstractUnit<?>) { return (AbstractUnit<Q>) systemUnit; } else { return new TransformedUnit<>(null, this, systemUnit, cvtr); } }
@Override public final Unit<Q> transform(UnitConverter operation) { Unit<Q> systemUnit = this.getSystemUnit(); UnitConverter cvtr; if (this.isSystemUnit()) { cvtr = this.getSystemConverter().concatenate(operation); } else { cvtr = operation; } if (cvtr.equals(AbstractConverter.IDENTITY)) { return systemUnit; } else { return new TransformedUnit<>(null, this, systemUnit, cvtr); } }
/** * Returns the unit derived from this unit using the specified converter. * * @param operation the converter from the transformed unit to this unit. * @return the unit after the specified transformation. */ @Override @SuppressWarnings("unchecked") public Unit<Q> transform(UnitConverter operation) { ArgumentChecks.ensureNonNull("operation", operation); AbstractUnit<Q> base = this; if (this == Units.KILOGRAM) { base = (AbstractUnit<Q>) Units.GRAM; operation = operation.concatenate(LinearConverter.forPrefix('k')); } return ConventionalUnit.create(base, operation); }
/** * Returns the unit derived from this unit using the specified converter. * * @param operation the converter from the transformed unit to this unit. * @return the unit after the specified transformation. */ @Override public Unit<Q> transform(UnitConverter operation) { ArgumentChecks.ensureNonNull("operation", operation); AbstractUnit<Q> base = this; if (!isPrefixable()) { base = target; operation = toTarget.concatenate(operation); } return create(base, operation); }
/** * Returns the unit derived from this unit using the specified converter. * * @param operation the converter from the transformed unit to this unit. * @return the unit after the specified transformation. */ @Override public Unit<Q> transform(UnitConverter operation) { ArgumentChecks.ensureNonNull("operation", operation); AbstractUnit<Q> base = this; if (!isPrefixable()) { base = target; operation = toTarget.concatenate(operation); } return create(base, operation); }
@SuppressWarnings("rawtypes") public final UnitConverter getConverterToAny(Unit<?> that) throws IncommensurableException, UnconvertibleException { if (!isCompatible(that)) throw new IncommensurableException(this + " is not compatible with " + that); AbstractUnit thatAbstr = (AbstractUnit) that; // Since both units are // compatible they must // be both abstract // units. DimensionalModel model = DimensionalModel.current(); AbstractUnit thisSystemUnit = this.getSystemUnit(); UnitConverter thisToDimension = model.getDimensionalTransform(thisSystemUnit.getDimension()).concatenate(this.getSystemConverter()); AbstractUnit thatSystemUnit = thatAbstr.getSystemUnit(); UnitConverter thatToDimension = model.getDimensionalTransform(thatSystemUnit.getDimension()).concatenate(thatAbstr.getSystemConverter()); return thatToDimension.inverse().concatenate(thisToDimension); }
@Override public final UnitConverter getConverterTo(Unit<Q> that) throws UnconvertibleException { if ((this == that) || this.equals(that)) return AbstractConverter.IDENTITY; // Shortcut. Unit<Q> thisSystemUnit = this.getSystemUnit(); Unit<Q> thatSystemUnit = that.getSystemUnit(); if (!thisSystemUnit.equals(thatSystemUnit)) try { return getConverterToAny(that); } catch (IncommensurableException e) { throw new UnconvertibleException(e); } UnitConverter thisToSI = this.getSystemConverter(); UnitConverter thatToSI = that.getConverterTo(thatSystemUnit); return thatToSI.inverse().concatenate(thisToSI); }
public final UnitConverter getConverterTo(Unit<Q> that) throws UnconvertibleException { if ((this == that) || this.equals(that)) return AbstractConverter.IDENTITY; // Shortcut. Unit<Q> thisSystemUnit = this.getSystemUnit(); Unit<Q> thatSystemUnit = that.getSystemUnit(); if (!thisSystemUnit.equals(thatSystemUnit)) try { return getConverterToAny(that); } catch (IncommensurableException e) { throw new UnconvertibleException(e); } UnitConverter thisToSI = this.getSystemConverter(); UnitConverter thatToSI = that.getConverterTo(thatSystemUnit); return thatToSI.inverse().concatenate(thisToSI); }
private final UnitConverter internalGetConverterTo(Unit<Q> that, boolean useEquals) throws UnconvertibleException { if (useEquals) { if ((this == that) || this.equals(that)) return AbstractConverter.IDENTITY; } else { if (this == that) return AbstractConverter.IDENTITY; } Unit<Q> thisSystemUnit = this.getSystemUnit(); Unit<Q> thatSystemUnit = that.getSystemUnit(); if (!thisSystemUnit.equals(thatSystemUnit)) try { return getConverterToAny(that); } catch (IncommensurableException e) { throw new UnconvertibleException(e); } UnitConverter thisToSI = this.getSystemConverter(); UnitConverter thatToSI = that.getConverterTo(thatSystemUnit); return thatToSI.inverse().concatenate(thisToSI); }
@SuppressWarnings("rawtypes") @Override public final UnitConverter getConverterToAny(Unit<?> that) throws IncommensurableException, UnconvertibleException { if (!isCompatible(that)) throw new IncommensurableException(this + " is not compatible with " + that); AbstractUnit thatAbstr = (AbstractUnit) that; // Since both units are // compatible they must // be both physics // units. DimensionalModel model = DimensionalModel.current(); Unit thisSystemUnit = this.getSystemUnit(); UnitConverter thisToDimension = model.getDimensionalTransform(thisSystemUnit.getDimension()).concatenate(this.getSystemConverter()); Unit thatSystemUnit = thatAbstr.getSystemUnit(); UnitConverter thatToDimension = model.getDimensionalTransform(thatSystemUnit.getDimension()).concatenate(thatAbstr.getSystemConverter()); return thatToDimension.inverse().concatenate(thisToDimension); }
@SuppressWarnings("rawtypes") @Override public final UnitConverter getConverterToAny(Unit<?> that) throws IncommensurableException, UnconvertibleException { if (!isCompatible(that)) throw new IncommensurableException(this + " is not compatible with " + that); AbstractUnit thatAbstr = (AbstractUnit) that; // Since both units are // compatible they must // be both physics // units. DimensionalModel model = DimensionalModel.current(); Unit thisSystemUnit = this.getSystemUnit(); UnitConverter thisToDimension = model.getDimensionalTransform(thisSystemUnit.getDimension()).concatenate(this.getSystemConverter()); Unit thatSystemUnit = thatAbstr.getSystemUnit(); UnitConverter thatToDimension = model.getDimensionalTransform(thatSystemUnit.getDimension()).concatenate(thatAbstr.getSystemConverter()); return thatToDimension.inverse().concatenate(thisToDimension); }