1 package org.apidesign.apifest08.currency;
3 import java.math.BigDecimal;
4 import java.math.RoundingMode;
5 import java.util.Currency;
6 import static org.apidesign.apifest08.currency.Assert.*;
10 * A bid representation. A did is defined as two currenncies and its value.
12 public final class Bid {
13 private final Currency first;
14 private final Currency second;
15 private final BigDecimal bidValue; // a bid between the first currency and the second currency
16 public static final BigDecimal one = new BigDecimal(1);
18 Bid(Currency first, Currency second, BigDecimal bid) {
19 notNull(first, "first");
20 notNull(second, "second");
26 Bid(Currency first, Currency second) {
27 notNull(first, "first");
28 notNull(second, "second");
35 BigDecimal getBidValue(Currency from, Currency to) {
36 if((from != first || from != second) || (to != first || to != second)) {
37 new IllegalArgumentException("This bid can be used only for: " + first + " " + second);
40 notNull(bidValue, "bidValue");
48 retVal = one.divide(bidValue, 10 ,RoundingMode.HALF_UP);
55 public int hashCode() {
58 result = prime * result + first.hashCode() + second.hashCode();
63 public boolean equals(Object obj) {
68 if (getClass() != obj.getClass())
70 Bid other = (Bid) obj;
72 return (this.first == other.first || this.first == other.second) && (this.second == other.second || this.second == other.first) ;