public void multiplyValue(Decimal multiplicand) { value = value.multiply(multiplicand); }
public void multiplyValue(int multiplicand) { value = value.multiply(new Decimal(multiplicand)); }
public Decimal modulo(Decimal other) throws UcumException { if (other == null) return null; Decimal t = divInt(other); Decimal t2 = t.multiply(other); return subtract(t2); }
private void testMultiply(String s1, String s2, String s3) throws UcumException { Decimal v1 = new Decimal(s1); Decimal v2 = new Decimal(s2); Decimal v3 = v1.multiply(v2); check(v3.asDecimal().equals(s3), s1+" * "+s2+" = "+s3+", but the library returned "+v3.asDecimal()); }
@Override public Pair multiply(Pair o1, Pair o2) throws UcumException { Pair res = new Pair(o1.getValue().multiply(o2.getValue()), o1.getCode() +"."+o2.getCode()); return getCanonicalForm(res); }
public void multiplyValue(Decimal multiplicand) { value = value.multiply(multiplicand); }
@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()); }
@Override public Pair getCanonicalForm(Pair value) throws UcumException { assert value != null : paramError("getCanonicalForm", "value", "must not be null"); assert checkStringParam(value.getCode()) : paramError("getCanonicalForm", "value.code", "must not be null or empty"); Term term = new ExpressionParser(model).parse(value.getCode()); Canonical c = new Converter(model, handlers).convert(term); if (value.getValue() == null) return new Pair(null, new ExpressionComposer().compose(c, false)); else return new Pair(value.getValue().multiply(c.getValue()), new ExpressionComposer().compose(c, false)); }
public void multiplyValue(int multiplicand) { value = value.multiply(new Decimal(multiplicand)); }
public Decimal modulo(Decimal other) throws UcumException { if (other == null) return null; Decimal t = divInt(other); Decimal t2 = t.multiply(other); return subtract(t2); }
private void testMultiply(String s1, String s2, String s3) throws UcumException { Decimal v1 = new Decimal(s1); Decimal v2 = new Decimal(s2); Decimal v3 = v1.multiply(v2); check(v3.asDecimal().equals(s3), s1+" * "+s2+" = "+s3+", but the library returned "+v3.asDecimal()); }
@Override public Pair multiply(Pair o1, Pair o2) throws UcumException { Pair res = new Pair(o1.getValue().multiply(o2.getValue()), o1.getCode() +"."+o2.getCode()); return getCanonicalForm(res); }
@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()); }
@Override public Pair getCanonicalForm(Pair value) throws UcumException { assert value != null : paramError("getCanonicalForm", "value", "must not be null"); assert checkStringParam(value.getCode()) : paramError("getCanonicalForm", "value.code", "must not be null or empty"); Term term = new ExpressionParser(model).parse(value.getCode()); Canonical c = new Converter(model, handlers).convert(term); if (value.getValue() == null) return new Pair(null, new ExpressionComposer().compose(c, false)); else return new Pair(value.getValue().multiply(c.getValue()), new ExpressionComposer().compose(c, false)); }