Tabnine Logo
UnconvertibleException
Code IndexAdd Tabnine to your IDE (free)

How to use
UnconvertibleException
in
javax.measure

Best Java code snippets using javax.measure.UnconvertibleException (Showing top 17 results out of 315)

origin: geotools/geotools

/**
 * 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);
}
origin: tec.uom/uom-se

@Override
public ComparableQuantity<?> multiply(Quantity<?> multiplier) {
 if (getUnit().equals(multiplier.getUnit())) {
  return TimeQuantities.getQuantity(value * multiplier.getValue().intValue(), timeUnit);
 }
 Unit<?> mulUnit = getUnit().multiply(multiplier.getUnit());
 UnitConverter conv;
 try {
  conv = getUnit().getConverterToAny(mulUnit);
  return TimeQuantities.getQuantity(value * conv.convert(multiplier.getValue()).intValue(), timeUnit);
 } catch (UnconvertibleException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  return TimeQuantities.getQuantity(value * multiplier.getValue().intValue(), timeUnit);
 } catch (IncommensurableException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  return TimeQuantities.getQuantity(value * multiplier.getValue().intValue(), timeUnit);
 }
}
origin: apache/sis

/**
 * Tests {@link SystemUnit#getConverterTo(Unit)} with illegal arguments.
 * Those calls are not allowed by the Java compiler if parameterized types have not been erased.
 * But if the users nevertheless erased parameter types, {@link SystemUnit} implementation should
 * have some safety nets.
 */
@Test
@SuppressWarnings("unchecked")
@DependsOnMethod("testGetConverterTo")
public void testIllegalGetConverterTo() {
  try {
    Units.METRE.getConverterTo((Unit) Units.SECOND);
    fail("Conversion should not have been allowed.");
  } catch (UnconvertibleException e) {
    final String message = e.getMessage();
    assertTrue(message, message.contains("m"));     // metre unit symbol
    assertTrue(message, message.contains("s"));     // second unit symbol
  }
  /*
   * Following is tricker because "radian" and "unity" are compatible units,
   * but should nevertheless not be allowed by the 'getConverterTo' method.
   */
  try {
    Units.RADIAN.getConverterTo((Unit) Units.UNITY);
    fail("Conversion should not have been allowed.");
  } catch (UnconvertibleException e) {
    final String message = e.getMessage();
    assertTrue(message, message.contains("rad"));
  }
}
origin: tec.units/indriya

@Override
public ComparableQuantity<?> multiply(Quantity<?> multiplier) {
 if (getUnit().equals(multiplier.getUnit())) {
  return TimeQuantities.getQuantity(value * multiplier.getValue().intValue(), timeUnit);
 }
 Unit<?> mulUnit = getUnit().multiply(multiplier.getUnit());
 UnitConverter conv;
 try {
  conv = getUnit().getConverterToAny(mulUnit);
  return TimeQuantities.getQuantity(value * conv.convert(multiplier.getValue()).intValue(), timeUnit);
 } catch (UnconvertibleException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  return TimeQuantities.getQuantity(value * multiplier.getValue().intValue(), timeUnit);
 } catch (IncommensurableException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  return TimeQuantities.getQuantity(value * multiplier.getValue().intValue(), timeUnit);
 }
}
origin: tec.units/unit-ri

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);
}
origin: tec.uom/uom-se

@Override
public ComparableQuantity<?> divide(Quantity<?> that) {
 if (getUnit().equals(that.getUnit())) {
  return TimeQuantities.getQuantity(value / that.getValue().intValue(), timeUnit);
 }
 Unit<?> divUnit = getUnit().divide(that.getUnit());
 UnitConverter conv;
 try {
  conv = getUnit().getConverterToAny(divUnit);
  return TimeQuantities.getQuantity(value / conv.convert(that.getValue()).intValue(), timeUnit);
 } catch (UnconvertibleException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  return TimeQuantities.getQuantity(value / that.getValue().intValue(), timeUnit);
 } catch (IncommensurableException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  return TimeQuantities.getQuantity(value / that.getValue().intValue(), timeUnit);
 }
}
origin: tec.uom/uom-se

@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);
}
origin: tec.uom/uom-se

/**
 * @since 1.0.1
 */
@Override
public ComparableQuantity<?> divide(Quantity<?> that) {
 if (getUnit().equals(that.getUnit())) {
  return TimeQuantities.getQuantity(value / that.getValue().intValue(), timeUnit);
 }
 Unit<?> divUnit = getUnit().divide(that.getUnit());
 UnitConverter conv;
 try {
  conv = getUnit().getConverterToAny(divUnit);
  return TimeQuantities.getQuantity(value / conv.convert(that.getValue()).intValue(), timeUnit);
 } catch (UnconvertibleException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  return TimeQuantities.getQuantity(value / that.getValue().intValue(), timeUnit);
 } catch (IncommensurableException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  return TimeQuantities.getQuantity(value / that.getValue().intValue(), timeUnit);
 }
}
origin: tec.units/indriya

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);
}
origin: tec.units/indriya

/**
 * @since 1.0.1
 */
@Override
public ComparableQuantity<?> divide(Quantity<?> that) {
 if (getUnit().equals(that.getUnit())) {
  return TimeQuantities.getQuantity(value / that.getValue().intValue(), timeUnit);
 }
 Unit<?> divUnit = getUnit().divide(that.getUnit());
 UnitConverter conv;
 try {
  conv = getUnit().getConverterToAny(divUnit);
  return TimeQuantities.getQuantity(value / conv.convert(that.getValue()).intValue(), timeUnit);
 } catch (UnconvertibleException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  return TimeQuantities.getQuantity(value / that.getValue().intValue(), timeUnit);
 } catch (IncommensurableException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  return TimeQuantities.getQuantity(value / that.getValue().intValue(), timeUnit);
 }
}
origin: org.apache.sis.core/sis-utility

/**
 * 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();
}
origin: tec.units/indriya

@Override
public ComparableQuantity<?> divide(Quantity<?> that) {
 if (getUnit().equals(that.getUnit())) {
  return TimeQuantities.getQuantity(value / that.getValue().intValue(), timeUnit);
 }
 Unit<?> divUnit = getUnit().divide(that.getUnit());
 UnitConverter conv;
 try {
  conv = getUnit().getConverterToAny(divUnit);
  return TimeQuantities.getQuantity(value / conv.convert(that.getValue()).intValue(), timeUnit);
 } catch (UnconvertibleException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  return TimeQuantities.getQuantity(value / that.getValue().intValue(), timeUnit);
 } catch (IncommensurableException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  return TimeQuantities.getQuantity(value / that.getValue().intValue(), timeUnit);
 }
}
origin: apache/sis

/**
 * 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();
}
origin: tec.uom/uom-se

/**
 * @since 1.0.1
 */
@Override
public ComparableQuantity<?> multiply(Quantity<?> multiplier) {
 if (getUnit().equals(multiplier.getUnit())) {
  return TimeQuantities.getQuantity(value * multiplier.getValue().intValue(), timeUnit);
 }
 Unit<?> mulUnit = getUnit().multiply(multiplier.getUnit());
 UnitConverter conv;
 try {
  conv = getUnit().getConverterToAny(mulUnit);
  return TimeQuantities.getQuantity(value * conv.convert(multiplier.getValue()).intValue(), timeUnit);
 } catch (UnconvertibleException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  return TimeQuantities.getQuantity(value * multiplier.getValue().intValue(), timeUnit);
 } catch (IncommensurableException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  return TimeQuantities.getQuantity(value * multiplier.getValue().intValue(), timeUnit);
 }
}
origin: org.apache.sis.core/sis-utility

/**
 * 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;
}
origin: tec.units/indriya

/**
 * @since 1.0.1
 */
@Override
public ComparableQuantity<?> multiply(Quantity<?> multiplier) {
 if (getUnit().equals(multiplier.getUnit())) {
  return TimeQuantities.getQuantity(value * multiplier.getValue().intValue(), timeUnit);
 }
 Unit<?> mulUnit = getUnit().multiply(multiplier.getUnit());
 UnitConverter conv;
 try {
  conv = getUnit().getConverterToAny(mulUnit);
  return TimeQuantities.getQuantity(value * conv.convert(multiplier.getValue()).intValue(), timeUnit);
 } catch (UnconvertibleException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  return TimeQuantities.getQuantity(value * multiplier.getValue().intValue(), timeUnit);
 } catch (IncommensurableException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
  return TimeQuantities.getQuantity(value * multiplier.getValue().intValue(), timeUnit);
 }
}
origin: apache/sis

/**
 * 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;
}
javax.measureUnconvertibleException

Most used methods

  • <init>
  • printStackTrace
  • getMessage

Popular in Java

  • Reactive rest calls using spring rest template
  • startActivity (Activity)
  • setScale (BigDecimal)
  • getResourceAsStream (ClassLoader)
  • Menu (java.awt)
  • ConnectException (java.net)
    A ConnectException is thrown if a connection cannot be established to a remote host on a specific po
  • AtomicInteger (java.util.concurrent.atomic)
    An int value that may be updated atomically. See the java.util.concurrent.atomic package specificati
  • Stream (java.util.stream)
    A sequence of elements supporting sequential and parallel aggregate operations. The following exampl
  • ZipFile (java.util.zip)
    This class provides random read access to a zip file. You pay more to read the zip file's central di
  • Servlet (javax.servlet)
    Defines methods that all servlets must implement. A servlet is a small Java program that runs within
  • Top plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now