Beispiel #1
0
 /**
  * Returns the product of this unit with the one specified.
  *
  * @param that the unit multiplicand.
  * @return <code>this * that</code>
  */
 @SuppressWarnings({"unchecked", "rawtypes"})
 public final Unit<?> multiply(Unit<?> that) {
   if (this.equals(ONE)) return that;
   if (that.equals(ONE)) return this;
   if (this.isRationalFactor()) return that.transform(this.getConverterTo(ONE));
   if (((MoneyUnit<?>) that).isRationalFactor())
     return this.transform(that.getConverterTo((Unit) ONE));
   return ProductUnit.getProductInstance(this, (AbstractUnit<?>) that);
 }
Beispiel #2
0
 @Test
 public void testParseParseMult1() {
   Parser<String, Term> p = new ExpressionParser(ucumService.getModel());
   try {
     Term t = p.parse("m.s2");
     assertNotNull(t);
     assertEquals("MULTIPLICATION", t.getOp().toString());
     Symbol s = (Symbol) t.getComp();
     Unit<?> u = s.getUnit();
     assertEquals("m", u.getSymbol());
   } catch (UOMoException e) {
     println(e.getLocalizedMessage());
     fail(e.getLocalizedMessage());
   }
 }
Beispiel #3
0
 /** @see <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=371433">Bugzilla: 371433</a> */
 @Test
 public void testParseParseParenthes1() {
   Parser<String, Term> p = new ExpressionParser(ucumService.getModel());
   try {
     Term t = p.parse("kg/m/s");
     assertNotNull(t);
     assertEquals("DIVISION", t.getOp().toString());
     Symbol s = (Symbol) t.getComp();
     Unit<?> u = s.getUnit();
     assertEquals("g", u.getSymbol());
     assertEquals("k", s.getPrefix().getSymbol());
   } catch (UOMoException e) {
     println(e.getLocalizedMessage());
     fail(e.getLocalizedMessage());
   }
 }
Beispiel #4
0
 public long longValue(Unit<IMoney> unit) throws ArithmeticException {
   Unit<IMoney> myUnit = unit();
   try {
     UnitConverter converter = unit.getConverterToAny(myUnit);
     return (converter.convert(BigDecimal.valueOf(super.getNumber().longValue())).longValue());
   } catch (UnconvertibleException e) {
     throw e;
   } catch (IncommensurableException e) {
     throw new IllegalArgumentException(e.getMessage());
   }
 }
Beispiel #5
0
 public double doubleValue(Unit<IMoney> unit) {
   Unit<IMoney> myUnit = unit();
   try {
     UnitConverter converter = unit.getConverterToAny(myUnit);
     return converter.convert(getNumber().doubleValue());
   } catch (UnconvertibleException e) {
     throw e;
   } catch (IncommensurableException e) {
     throw new IllegalArgumentException(e.getMessage());
   }
 }
Beispiel #6
0
 /**
  * Returns the quotient of this unit with the one specified.
  *
  * @param that the unit divisor.
  * @return <code>this / that</code>
  */
 public final Unit<?> divide(Unit<?> that) {
   return (Unit<?>) this.multiply(that.inverse());
 }
Beispiel #7
0
 public boolean isCompatible(Unit<?> that) {
   return (this == that)
       || this.toMetric().equals(that.getSystemUnit())
       || (!"".equals(this.getDimension().toString())
           && this.getDimension().equals(that.getDimension())); // $NON-NLS-1$
 }