1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/task2/solution11/src/org/apidesign/apifest08/currency/Computer.java Wed Oct 01 10:43:05 2008 +0200
1.3 @@ -0,0 +1,65 @@
1.4 +package org.apidesign.apifest08.currency;
1.5 +
1.6 +/**
1.7 + * Interface declaring method for computing conversion.
1.8 + *
1.9 + * Because of a vague definition of currency amount's type,
1.10 + * the interface has a generic type.
1.11 + *
1.12 + * @author ked
1.13 + * @see http://wiki.apidesign.org/wiki/APIDesignPatterns:ResponseReply
1.14 + */
1.15 +interface Computer<AmountType> {
1.16 +
1.17 + ComputerResponse<AmountType> compute(ComputerRequest<AmountType> request);
1.18 +
1.19 + /**
1.20 + *
1.21 + * @param <AmountType>
1.22 + */
1.23 + final class ComputerRequest<AmountType> {
1.24 +
1.25 + private AmountType input;
1.26 + private AmountType inputCurrencyRatio;
1.27 + private AmountType outputCurrencyRatio;
1.28 +
1.29 + AmountType getInput() {
1.30 + return input;
1.31 + }
1.32 +
1.33 + void setInput(AmountType input) {
1.34 + this.input = input;
1.35 + }
1.36 +
1.37 + AmountType getInputCurrencyRatio() {
1.38 + return inputCurrencyRatio;
1.39 + }
1.40 +
1.41 + void setInputCurrencyRatio(AmountType inputCurrencyRatio) {
1.42 + this.inputCurrencyRatio = inputCurrencyRatio;
1.43 + }
1.44 +
1.45 + AmountType getOutputCurrencyRatio() {
1.46 + return outputCurrencyRatio;
1.47 + }
1.48 +
1.49 + void setOutputCurrencyRatio(AmountType outputCurrencyRatio) {
1.50 + this.outputCurrencyRatio = outputCurrencyRatio;
1.51 + }
1.52 + }
1.53 +
1.54 + final class ComputerResponse<AmountType> {
1.55 +
1.56 + private AmountType result;
1.57 +
1.58 + AmountType getResult() {
1.59 + return result;
1.60 + }
1.61 +
1.62 + void setResult(AmountType result) {
1.63 + this.result = result;
1.64 + }
1.65 + }
1.66 +
1.67 +
1.68 +}
1.69 \ No newline at end of file