if (amount.currency().equals(source_)) {
return new Money(amount.value() * rate_, target_);
} else if (amount.currency().equals(target_)) {
return new Money(amount.value() / rate_, source_);
} else {
throw new LibraryException("exchange rate not applicable"); // QA:[RG]::verified // TODO: message
}
case Derived:
if (amount.currency() == rateChain_.getFirst().source() || amount.currency() == rateChain_.getFirst().target()) {
return rateChain_.getSecond().exchange(rateChain_.getFirst().exchange(amount));
} else if (amount.currency() == rateChain_.getSecond().source() || amount.currency() == rateChain_.getSecond().target()) {
return rateChain_.getFirst().exchange(rateChain_.getSecond().exchange(amount));
} else {
throw new LibraryException("exchange rate not applicable"); // QA:[RG]::verified // TODO: message
}
default:
throw new LibraryException("unknown exchange-rate type"); // QA:[RG]::verified // TODO: message
}
}