task4/solution13/src/org/apidesign/apifest08/currency/ConversionResult.java
changeset 61 58ec6da75f6f
parent 45 251d0ed461fb
child 63 20d332739f60
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/task4/solution13/src/org/apidesign/apifest08/currency/ConversionResult.java	Sat Oct 11 23:38:46 2008 +0200
     1.3 @@ -0,0 +1,49 @@
     1.4 +
     1.5 +package org.apidesign.apifest08.currency;
     1.6 +
     1.7 +import java.math.BigDecimal;
     1.8 +
     1.9 +/**
    1.10 + * Result of currency conversion. Holds converted value and remainder.
    1.11 + * <p>
    1.12 + * <em>Converted</em> describes value converted to <em>target</em> currenty. <em>Remainder</em> describes
    1.13 + * how much from original <em>amount</em> was not possible to convert. Convertor never loses any (small) money
    1.14 + * in conversion error (rounding), but instead of rounding is converts only as much as possible and keeps rest as remainder.
    1.15 + * 
    1.16 + * @author arnostvalicek
    1.17 + */
    1.18 +public class ConversionResult {
    1.19 +    private BigDecimal converted;
    1.20 +    private BigDecimal remainder;
    1.21 +    
    1.22 +    /**
    1.23 +     * Get converted value.
    1.24 +     * @return Returns converted value.
    1.25 +     */
    1.26 +    public BigDecimal getConverted() {
    1.27 +        return converted;
    1.28 +    }
    1.29 +
    1.30 +    void setConverted(BigDecimal converted) {
    1.31 +        this.converted = converted;
    1.32 +    }
    1.33 +
    1.34 +    
    1.35 +    /**
    1.36 +     * Get remainder of conversion. Remainder is set if part of converted amount which can't be converted 
    1.37 +     * because this target currency precision can't handle small numbers. Remainder value is in <em>from currency</em>
    1.38 +     * <p>
    1.39 +     * Converter never loses any precision in conversion. Remainer describes how much of amount can't be converted. 
    1.40 +     * If we substract <em>remainder</em> from <em>amount</em> we will be able to get exact conversion.
    1.41 +     * 
    1.42 +     * @return Returns remainder of conversion.
    1.43 +     */
    1.44 +    public BigDecimal getRemainder() {
    1.45 +        return remainder;
    1.46 +    }
    1.47 +
    1.48 +    void setRemainder(BigDecimal remainder) {
    1.49 +        this.remainder = remainder;
    1.50 +    }
    1.51 +
    1.52 +}