01: /*
02: * $Id: ResultCodeImpl.java,v 1.8 2007/09/18 11:27:13 agoubard Exp $
03: */
04: package com.mycompany.allinone.api;
05:
06: import java.util.HashMap;
07: import java.util.Map;
08:
09: /**
10: * Implementation of the <code>ResultCode</code> function.
11: *
12: * @version $Revision: 1.8 $ $Date: 2007/09/18 11:27:13 $
13: * @author <a href="mailto:anthony.goubard@japplis.com">Anthony Goubard</a>
14: */
15: public class ResultCodeImpl extends ResultCode {
16:
17: /**
18: * Constructs a new <code>ResultCodeImpl</code> instance.
19: *
20: * @param api
21: * the API to which this function belongs, guaranteed to be not
22: * <code>null</code>.
23: */
24: public ResultCodeImpl(APIImpl api) {
25: super (api);
26: }
27:
28: private Map paramsCount = new HashMap();
29:
30: public final Result call(Request request) throws Throwable {
31: String parameter = request.getInputText();
32:
33: // Test if the input parameter contains no vowel
34: if (parameter.indexOf('a') == -1
35: && parameter.indexOf('e') == -1
36: && parameter.indexOf('i') == -1
37: && parameter.indexOf('o') == -1
38: && parameter.indexOf('u') == -1
39: && parameter.indexOf('y') == -1) {
40: return new NoVowelResult();
41: }
42:
43: // Test in the local map
44: if (paramsCount.containsKey(parameter)) {
45: int count = ((Integer) paramsCount.get(parameter))
46: .intValue();
47: AlreadySetResult invalidResult = new AlreadySetResult();
48: invalidResult.setCount(count);
49: count++;
50: paramsCount.put(parameter, new Integer(count));
51: return invalidResult;
52: }
53:
54: // Lookup in the shared map
55: if (_sharedInstance.get(parameter) != null) {
56: AlreadySetResult invalidResult = new AlreadySetResult();
57: invalidResult.setCount(-1);
58: return invalidResult;
59: }
60:
61: paramsCount.put(parameter, new Integer(1));
62:
63: SuccessfulResult result = new SuccessfulResult();
64: result.setOutputText(parameter + " added.");
65: return result;
66: }
67: }
|