author | Jaroslav Tulach <jtulach@netbeans.org> |
Sat, 25 Oct 2008 20:53:00 +0200 | |
changeset 84 | 2ae6e4aa7aef |
parent 61 | 58ec6da75f6f |
permissions | -rw-r--r-- |
japod@23 | 1 |
|
japod@23 | 2 |
package org.apidesign.apifest08.currency; |
japod@23 | 3 |
|
japod@23 | 4 |
import java.math.BigDecimal; |
japod@23 | 5 |
|
japod@23 | 6 |
/** |
japod@23 | 7 |
* Result of currency conversion. Holds converted value and remainder. |
japod@23 | 8 |
* <p> |
japod@41 | 9 |
* <em>Converted</em> describes value converted to <em>target</em> currenty. <em>Remainder</em> describes |
japod@41 | 10 |
* how much from original <em>amount</em> was not possible to convert. Convertor never loses any (small) money |
japod@23 | 11 |
* in conversion error (rounding), but instead of rounding is converts only as much as possible and keeps rest as remainder. |
japod@23 | 12 |
* |
japod@23 | 13 |
* @author arnostvalicek |
japod@23 | 14 |
*/ |
japod@23 | 15 |
public class ConversionResult { |
japod@23 | 16 |
private BigDecimal converted; |
japod@23 | 17 |
private BigDecimal remainder; |
japod@23 | 18 |
|
japod@23 | 19 |
/** |
japod@23 | 20 |
* Get converted value. |
japod@23 | 21 |
* @return Returns converted value. |
japod@23 | 22 |
*/ |
japod@23 | 23 |
public BigDecimal getConverted() { |
japod@23 | 24 |
return converted; |
japod@23 | 25 |
} |
japod@23 | 26 |
|
japod@23 | 27 |
void setConverted(BigDecimal converted) { |
japod@23 | 28 |
this.converted = converted; |
japod@23 | 29 |
} |
japod@23 | 30 |
|
japod@23 | 31 |
|
japod@23 | 32 |
/** |
japod@23 | 33 |
* Get remainder of conversion. Remainder is set if part of converted amount which can't be converted |
japod@23 | 34 |
* because this target currency precision can't handle small numbers. Remainder value is in <em>from currency</em> |
japod@23 | 35 |
* <p> |
japod@23 | 36 |
* Converter never loses any precision in conversion. Remainer describes how much of amount can't be converted. |
japod@23 | 37 |
* If we substract <em>remainder</em> from <em>amount</em> we will be able to get exact conversion. |
japod@23 | 38 |
* |
japod@23 | 39 |
* @return Returns remainder of conversion. |
japod@23 | 40 |
*/ |
japod@23 | 41 |
public BigDecimal getRemainder() { |
japod@23 | 42 |
return remainder; |
japod@23 | 43 |
} |
japod@23 | 44 |
|
japod@23 | 45 |
void setRemainder(BigDecimal remainder) { |
japod@23 | 46 |
this.remainder = remainder; |
japod@23 | 47 |
} |
japod@23 | 48 |
|
jaroslav@63 | 49 |
@Override |
jaroslav@63 | 50 |
public String toString() { |
jaroslav@63 | 51 |
return getClass().getSimpleName()+": converter:"+getConverted()+", remainder:"+getRemainder(); |
jaroslav@63 | 52 |
} |
jaroslav@63 | 53 |
|
jaroslav@63 | 54 |
|
jaroslav@63 | 55 |
|
japod@23 | 56 |
} |