public void divideValue(Decimal divisor) throws UcumException { value = value.divide(divisor); }
public Decimal divInt(Decimal other) throws UcumException { if (other == null) return null; Decimal t = divide(other); return t.trunc(); }
public void divideValue(int divisor) throws UcumException { value = value.divide(new Decimal(divisor)); }
@Override public Decimal getValue() { try { return new Decimal(5).divide(new Decimal(9)); } catch (Exception e) { // won't happen return null; } }
private void testDivide(String s1, String s2, String s3) throws UcumException { Decimal v1 = new Decimal(s1); Decimal v2 = new Decimal(s2); Decimal v3 = v1.divide(v2); check(v3.asDecimal().equals(s3), s1+" / "+s2+" = "+s3+", but the library returned "+v3.asDecimal()); }
private List<Base> opDivideBy(List<Base> left, List<Base> right) throws PathEngineException { if (left.size() == 0) throw new PathEngineException("Error performing /: left operand has no value"); if (left.size() > 1) throw new PathEngineException("Error performing /: left operand has more than one value"); if (!left.get(0).isPrimitive()) throw new PathEngineException(String.format("Error performing -: left operand has the wrong type (%s)", left.get(0).fhirType())); if (right.size() == 0) throw new PathEngineException("Error performing /: right operand has no value"); if (right.size() > 1) throw new PathEngineException("Error performing /: right operand has more than one value"); if (!right.get(0).isPrimitive()) throw new PathEngineException(String.format("Error performing /: right operand has the wrong type (%s)", right.get(0).fhirType())); List<Base> result = new ArrayList<Base>(); Base l = left.get(0); Base r = right.get(0); if (l.hasType("integer", "decimal") && r.hasType("integer", "decimal")) { Decimal d1; try { d1 = new Decimal(l.primitiveValue()); Decimal d2 = new Decimal(r.primitiveValue()); result.add(new DecimalType(d1.divide(d2).asDecimal())); } catch (UcumException e) { throw new PathEngineException(e); } } else throw new PathEngineException(String.format("Error performing /: left and right operand have incompatible or illegal types (%s, %s)", left.get(0).fhirType(), right.get(0).fhirType())); return result; }
private List<Base> opDivideBy(List<Base> left, List<Base> right) throws PathEngineException { if (left.size() == 0) throw new PathEngineException("Error performing /: left operand has no value"); if (left.size() > 1) throw new PathEngineException("Error performing /: left operand has more than one value"); if (!left.get(0).isPrimitive()) throw new PathEngineException(String.format("Error performing -: left operand has the wrong type (%s)", left.get(0).fhirType())); if (right.size() == 0) throw new PathEngineException("Error performing /: right operand has no value"); if (right.size() > 1) throw new PathEngineException("Error performing /: right operand has more than one value"); if (!right.get(0).isPrimitive()) throw new PathEngineException(String.format("Error performing /: right operand has the wrong type (%s)", right.get(0).fhirType())); List<Base> result = new ArrayList<Base>(); Base l = left.get(0); Base r = right.get(0); if (l.hasType("integer", "decimal") && r.hasType("integer", "decimal")) { Decimal d1; try { d1 = new Decimal(l.primitiveValue()); Decimal d2 = new Decimal(r.primitiveValue()); result.add(new DecimalType(d1.divide(d2).asDecimal())); } catch (UcumException e) { throw new PathEngineException(e); } } else throw new PathEngineException(String.format("Error performing /: left and right operand have incompatible or illegal types (%s, %s)", left.get(0).fhirType(), right.get(0).fhirType())); return result; }
public void divideValue(Decimal divisor) throws UcumException { value = value.divide(divisor); }
@Override public Decimal convert(Decimal value, String sourceUnit, String destUnit) throws UcumException { assert value != null : paramError("convert", "value", "must not be null"); assert checkStringParam(sourceUnit) : paramError("convert", "sourceUnit", "must not be null or empty"); assert checkStringParam(destUnit) : paramError("convert", "destUnit", "must not be null or empty"); if (sourceUnit.equals(destUnit)) return value; Canonical src = new Converter(model, handlers).convert(new ExpressionParser(model).parse(sourceUnit)); Canonical dst = new Converter(model, handlers).convert(new ExpressionParser(model).parse(destUnit)); String s = new ExpressionComposer().compose(src, false); String d = new ExpressionComposer().compose(dst, false); if (!s.equals(d)) throw new UcumException("Unable to convert between units "+sourceUnit+" and "+destUnit+" as they do not have matching canonical forms ("+s+" and "+d+" respectively)"); Decimal canValue = value.multiply(src.getValue()); // System.out.println(value.toPlainString()+sourceUnit+" =("+src.getValue().toPlainString()+")= "+ // canValue.toPlainString()+s+" =("+dst.getValue().toPlainString()+")= "+ // canValue.divide(dst.getValue())+destUnit); return canValue.divide(dst.getValue()); }
public Decimal divInt(Decimal other) throws UcumException { if (other == null) return null; Decimal t = divide(other); return t.trunc(); }
public void divideValue(int divisor) throws UcumException { value = value.divide(new Decimal(divisor)); }
@Override public Decimal getValue() { try { return new Decimal(5).divide(new Decimal(9)); } catch (Exception e) { // won't happen return null; } }
private void testDivide(String s1, String s2, String s3) throws UcumException { Decimal v1 = new Decimal(s1); Decimal v2 = new Decimal(s2); Decimal v3 = v1.divide(v2); check(v3.asDecimal().equals(s3), s1+" / "+s2+" = "+s3+", but the library returned "+v3.asDecimal()); }
private List<Base> opDivideBy(List<Base> left, List<Base> right) throws PathEngineException { if (left.size() == 0) throw new PathEngineException("Error performing /: left operand has no value"); if (left.size() > 1) throw new PathEngineException("Error performing /: left operand has more than one value"); if (!left.get(0).isPrimitive()) throw new PathEngineException(String.format("Error performing -: left operand has the wrong type (%s)", left.get(0).fhirType())); if (right.size() == 0) throw new PathEngineException("Error performing /: right operand has no value"); if (right.size() > 1) throw new PathEngineException("Error performing /: right operand has more than one value"); if (!right.get(0).isPrimitive()) throw new PathEngineException(String.format("Error performing /: right operand has the wrong type (%s)", right.get(0).fhirType())); List<Base> result = new ArrayList<Base>(); Base l = left.get(0); Base r = right.get(0); if (l.hasType("integer", "decimal") && r.hasType("integer", "decimal")) { Decimal d1; try { d1 = new Decimal(l.primitiveValue()); Decimal d2 = new Decimal(r.primitiveValue()); result.add(new DecimalType(d1.divide(d2).asDecimal())); } catch (UcumException e) { throw new PathEngineException(e); } } else throw new PathEngineException(String.format("Error performing /: left and right operand have incompatible or illegal types (%s, %s)", left.get(0).fhirType(), right.get(0).fhirType())); return result; }
private List<Base> opDivideBy(List<Base> left, List<Base> right) throws PathEngineException { if (left.size() == 0) throw new PathEngineException("Error performing /: left operand has no value"); if (left.size() > 1) throw new PathEngineException("Error performing /: left operand has more than one value"); if (!left.get(0).isPrimitive()) throw new PathEngineException(String.format("Error performing -: left operand has the wrong type (%s)", left.get(0).fhirType())); if (right.size() == 0) throw new PathEngineException("Error performing /: right operand has no value"); if (right.size() > 1) throw new PathEngineException("Error performing /: right operand has more than one value"); if (!right.get(0).isPrimitive()) throw new PathEngineException(String.format("Error performing /: right operand has the wrong type (%s)", right.get(0).fhirType())); List<Base> result = new ArrayList<Base>(); Base l = left.get(0); Base r = right.get(0); if (l.hasType("integer", "decimal", "unsignedInt", "positiveInt") && r.hasType("integer", "decimal", "unsignedInt", "positiveInt")) { Decimal d1; try { d1 = new Decimal(l.primitiveValue()); Decimal d2 = new Decimal(r.primitiveValue()); result.add(new DecimalType(d1.divide(d2).asDecimal())); } catch (UcumException e) { throw new PathEngineException(e); } } else throw new PathEngineException(String.format("Error performing /: left and right operand have incompatible or illegal types (%s, %s)", left.get(0).fhirType(), right.get(0).fhirType())); return result; }
private List<Base> opDivideBy(List<Base> left, List<Base> right) throws PathEngineException { if (left.size() == 0) throw new PathEngineException("Error performing /: left operand has no value"); if (left.size() > 1) throw new PathEngineException("Error performing /: left operand has more than one value"); if (!left.get(0).isPrimitive()) throw new PathEngineException(String.format("Error performing -: left operand has the wrong type (%s)", left.get(0).fhirType())); if (right.size() == 0) throw new PathEngineException("Error performing /: right operand has no value"); if (right.size() > 1) throw new PathEngineException("Error performing /: right operand has more than one value"); if (!right.get(0).isPrimitive()) throw new PathEngineException(String.format("Error performing /: right operand has the wrong type (%s)", right.get(0).fhirType())); List<Base> result = new ArrayList<Base>(); Base l = left.get(0); Base r = right.get(0); if (l.hasType("integer", "decimal") && r.hasType("integer", "decimal")) { Decimal d1; try { d1 = new Decimal(l.primitiveValue()); Decimal d2 = new Decimal(r.primitiveValue()); result.add(new DecimalType(d1.divide(d2).asDecimal())); } catch (UcumException e) { throw new PathEngineException(e); } } else throw new PathEngineException(String.format("Error performing /: left and right operand have incompatible or illegal types (%s, %s)", left.get(0).fhirType(), right.get(0).fhirType())); return result; }
@Override public Decimal convert(Decimal value, String sourceUnit, String destUnit) throws UcumException { assert value != null : paramError("convert", "value", "must not be null"); assert checkStringParam(sourceUnit) : paramError("convert", "sourceUnit", "must not be null or empty"); assert checkStringParam(destUnit) : paramError("convert", "destUnit", "must not be null or empty"); if (sourceUnit.equals(destUnit)) return value; Canonical src = new Converter(model, handlers).convert(new ExpressionParser(model).parse(sourceUnit)); Canonical dst = new Converter(model, handlers).convert(new ExpressionParser(model).parse(destUnit)); String s = new ExpressionComposer().compose(src, false); String d = new ExpressionComposer().compose(dst, false); if (!s.equals(d)) throw new UcumException("Unable to convert between units "+sourceUnit+" and "+destUnit+" as they do not have matching canonical forms ("+s+" and "+d+" respectively)"); Decimal canValue = value.multiply(src.getValue()); // System.out.println(value.toPlainString()+sourceUnit+" =("+src.getValue().toPlainString()+")= "+ // canValue.toPlainString()+s+" =("+dst.getValue().toPlainString()+")= "+ // canValue.divide(dst.getValue())+destUnit); return canValue.divide(dst.getValue()); }