/** * Workaround for RFE #4093999 ("Relax constraint on placement of this()/super() call in * constructors"). * * @throws IncommensurableException */ private static UnitConverter getConverter(final Unit<Time> source) throws IncommensurableException { if (source == null) { throw new UnconvertibleException(Errors.format(ErrorKeys.NO_UNIT)); } return source.getConverterTo(MILLISECOND); }
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); }
@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); }
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); }
/** * Returns a converter of numeric values from this unit to another unit of same type. * * @param unit the unit of same type to which to convert the numeric values. * @return the converter from this unit to {@code that} unit. * @throws UnconvertibleException if the converter can not be constructed. */ @Override public UnitConverter getConverterTo(final Unit<Q> unit) throws UnconvertibleException { ArgumentChecks.ensureNonNull("unit", unit); final Unit<Q> step = unit.getSystemUnit(); if (step != this && !equalsIgnoreMetadata(step)) { // Should never occur unless parameterized type has been compromised. throw new UnconvertibleException(incompatible(unit)); } if (step == unit) { return LinearConverter.IDENTITY; } /* * At this point we know that the given units is not a system unit. Ask the conversion * FROM the given units (before to inverse it) instead than TO the given units because * in Apache SIS implementation, the former returns directly ConventionalUnit.toTarget * while the later implies a recursive call to this method. */ return unit.getConverterTo(step).inverse(); }
/** * Returns a converter of numeric values from this unit to another unit of same type. * * @param that the unit of same type to which to convert the numeric values. * @return the converter from this unit to {@code that} unit. * @throws UnconvertibleException if the converter can not be constructed. */ @Override public UnitConverter getConverterTo(final Unit<Q> that) throws UnconvertibleException { ArgumentChecks.ensureNonNull("that", that); final Unit<Q> step = that.getSystemUnit(); if (step != this && !equalsIgnoreMetadata(step)) { // Should never occur unless parameterized type has been compromised. throw new UnconvertibleException(incompatible(that)); } if (step == that) { return LinearConverter.IDENTITY; } /* * At this point we know that the given units is not a system unit. Ask the conversion * FROM the given units (before to inverse it) instead than TO the given units because * in Apache SIS implementation, the former returns directly ConventionalUnit.toTarget * while the later implies a recursive call to this method. */ return that.getConverterTo(step).inverse(); }
/** * Returns a converter of numeric values from this unit to another unit of same type. * * @param that the unit of same type to which to convert the numeric values. * @return the converter from this unit to {@code that} unit. * @throws UnconvertibleException if the converter can not be constructed. */ @Override public UnitConverter getConverterTo(final Unit<Q> that) throws UnconvertibleException { if (that == this) { return LinearConverter.IDENTITY; } ArgumentChecks.ensureNonNull("that", that); UnitConverter c = toTarget; if (target != that) { // Optimization for a common case. final Unit<Q> step = that.getSystemUnit(); if (target != step && !target.isCompatible(step)) { // Should never occur unless parameterized type has been compromised. throw new UnconvertibleException(incompatible(that)); } c = target.getConverterTo(step).concatenate(c); // Usually leave 'c' unchanged. c = step.getConverterTo(that).concatenate(c); } return c; }
/** * Returns a converter of numeric values from this unit to another unit of same type. * * @param that the unit of same type to which to convert the numeric values. * @return the converter from this unit to {@code that} unit. * @throws UnconvertibleException if the converter can not be constructed. */ @Override public UnitConverter getConverterTo(final Unit<Q> that) throws UnconvertibleException { if (that == this) { return LinearConverter.IDENTITY; } ArgumentChecks.ensureNonNull("that", that); UnitConverter c = toTarget; if (target != that) { // Optimization for a common case. final Unit<Q> step = that.getSystemUnit(); if (target != step && !target.isCompatible(step)) { // Should never occur unless parameterized type has been compromised. throw new UnconvertibleException(incompatible(that)); } c = target.getConverterTo(step).concatenate(c); // Usually leave 'c' unchanged. c = step.getConverterTo(that).concatenate(c); } return c; }