1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package ch.elca.el4j.tests.remoting.service.impl;
19
20 import ch.elca.el4j.tests.remoting.service.Calculator;
21 import ch.elca.el4j.tests.remoting.service.CalculatorException;
22 import ch.elca.el4j.tests.remoting.service.CalculatorOperation;
23 import ch.elca.el4j.tests.remoting.service.CalculatorValueObject;
24 import ch.elca.el4j.tests.remoting.service.SpecialCalculatorException;
25
26
27
28
29
30
31
32
33
34 public class CalculatorImpl implements Calculator {
35
36
37
38 public double getArea(double a, double b) {
39 return a * b;
40 }
41
42
43
44
45 public void throwMeAnException() throws CalculatorException {
46 throw new CalculatorException();
47 }
48
49
50
51
52 public void throwMeASpecialException(String action)
53 throws SpecialCalculatorException {
54 throw new SpecialCalculatorException(action);
55 }
56
57
58
59
60 public int countNumberOfUppercaseLetters(String text) {
61 if (text == null) {
62 return 0;
63 }
64
65 int numberOfUppercaseLetters = 0;
66 char[] c = text.toCharArray();
67 for (int i = 0; i < c.length; i++) {
68 if (c[i] >= 'A' && c[i] <= 'Z') {
69 numberOfUppercaseLetters++;
70 }
71 }
72 return numberOfUppercaseLetters;
73 }
74
75
76
77
78 public CalculatorValueObject echoValueObject(
79 CalculatorValueObject valueObject) {
80 return valueObject;
81 }
82
83
84
85
86 public double calculate(double a, double b, CalculatorOperation operation) {
87 double result;
88 if (operation == CalculatorOperation.ADDITION) {
89 result = a + b;
90 } else if (operation == CalculatorOperation.SUBTRACTION) {
91 result = a - b;
92 } else if (operation == CalculatorOperation.MULTIPLICATION) {
93 result = a * b;
94 } else if (operation == CalculatorOperation.DIVISION) {
95 result = a / b;
96 } else {
97 throw new IllegalArgumentException(
98 "Unknown calculator operation: " + operation);
99 }
100 return result;
101 }
102 }