View Javadoc

1   /*
2    * EL4J, the Extension Library for the J2EE, adds incremental enhancements to
3    * the spring framework, http://el4j.sf.net
4    * Copyright (C) 2005 by ELCA Informatique SA, Av. de la Harpe 22-24,
5    * 1000 Lausanne, Switzerland, http://www.elca.ch
6    *
7    * EL4J is published under the GNU Lesser General Public License (LGPL)
8    * Version 2.1. See http://www.gnu.org/licenses/
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13   * GNU Lesser General Public License for more details.
14   *
15   * For alternative licensing, please contact info@elca.ch
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   * This class is the implementation of the calculator.
29   *
30   * @svnLink $Revision: 3873 $;$Date: 2009-08-04 13:59:45 +0200 (Di, 04. Aug 2009) $;$Author: swismer $;$URL: https://el4j.svn.sourceforge.net/svnroot/el4j/branches/el4j_3_1/el4j/framework/tests/remoting/web/jar/src/main/java/ch/elca/el4j/tests/remoting/service/impl/CalculatorImpl.java $
31   *
32   * @author Martin Zeltner (MZE)
33   */
34  public class CalculatorImpl implements Calculator {
35  	/**
36  	 * {@inheritDoc}
37  	 */
38  	public double getArea(double a, double b) {
39  		return a * b;
40  	}
41  
42  	/**
43  	 * {@inheritDoc}
44  	 */
45  	public void throwMeAnException() throws CalculatorException {
46  		throw new CalculatorException();
47  	}
48  
49  	/**
50  	 * {@inheritDoc}
51  	 */
52  	public void throwMeASpecialException(String action)
53  		throws SpecialCalculatorException {
54  		throw new SpecialCalculatorException(action);
55  	}
56  
57  	/**
58  	 * {@inheritDoc}
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  	 * {@inheritDoc}
77  	 */
78  	public CalculatorValueObject echoValueObject(
79  		CalculatorValueObject valueObject) {
80  		return valueObject;
81  	}
82  	
83  	/**
84  	 * {@inheritDoc}
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 }