View Javadoc

1   /*
2    * @(#)$Id: AlgorithmTool.java 689 2009-07-22 00:10:27Z bsigner $
3    *
4    * Author		:	Ueli Kurmann, igesture@uelikurmann.ch
5    *
6    * Purpose		: 	Static helper methods used by different algorithms.
7    *
8    * -----------------------------------------------------------------------
9    *
10   * Revision Information:
11   *
12   * Date				Who			Reason
13   *
14   * Dec 11 2006      ukurmann	Initial Release
15   * Mar 14, 2007     bsigner     Cleanup
16   *
17   * -----------------------------------------------------------------------
18   *
19   * Copyright 1999-2009 ETH Zurich. All Rights Reserved.
20   *
21   * This software is the proprietary information of ETH Zurich.
22   * Use is subject to license terms.
23   * 
24   */
25  
26  
27  package org.ximtec.igesture.algorithm;
28  
29  import java.util.Map;
30  
31  import org.ximtec.igesture.core.Descriptor;
32  import org.ximtec.igesture.core.GestureClass;
33  import org.ximtec.igesture.core.GestureSet;
34  
35  
36  /**
37   * Static helper methods used by different algorithms.
38   * 
39   * @version 1.0 Dec 2006
40   * @author Ueli Kurmann, igesture@uelikurmann.ch
41   * @author Beat Signer, signer@inf.ethz.ch
42   */
43  public class AlgorithmTool {
44  
45     /**
46      * Returns a string parameter value. given is a parameter name and two maps
47      * with name/value parameters. If the parameter is not available in the first
48      * set, the default value is returned.
49      * 
50      * @param parameter the parameter name.
51      * @param parameters the map with parameter name/value pairs.
52      * @param defaultParameters the map with default parameter name/value pairs.
53      * @return the parameter value.
54      */
55     public static String getParameterValue(String parameter,
56           Map<String, String> parameters, Map<String, String> defaultParameters) {
57        String result = parameters.get(parameter);
58        return (result != null) ? result : defaultParameters.get(parameter);
59     } // getParameter
60  
61  
62     /**
63      * Returns a double parameter.
64      * 
65      * @see org.ximtec.igesture.algorithm.AlgorithmTool#getParameterValue
66      * @param parameter the parameter name.
67      * @param parameters the map with parameter name/value pairs.
68      * @param defaultParameters the map with default parameter name/value pairs.
69      * @return the parameter value.
70      */
71     public static double getDoubleParameterValue(String parameter,
72           Map<String, String> parameters, Map<String, String> defaultParameters) {
73        return Double.parseDouble(getParameterValue(parameter, parameters,
74              defaultParameters));
75     } // getDoubleParameterValue
76  
77  
78     /**
79      * Returns an int parameter.
80      * 
81      * @see org.ximtec.igesture.algorithm.AlgorithmTool#getParameterValue
82      * @param parameter the parameter name.
83      * @param parameters the map with parameter name/value pairs.
84      * @param defaultParameters the map with default parameter name/value pairs.
85      * @return the parameter value.
86      */
87     public static int getIntParameterValue(String parameter,
88           Map<String, String> parameters, Map<String, String> defaultParameters) {
89        return Integer.parseInt(getParameterValue(parameter, parameters,
90              defaultParameters));
91     } // getIntParameterValue
92  
93  
94     /**
95      * Returns true if all Gesture Classes of the Gesture Set have the required
96      * descriptor. As soon that one Class does not fulfill the requirements the
97      * result is false.
98      * 
99      * @param set the gesture set to test.
100     * @param descriptorType the descriptor type.
101     * @return true if all gesture classes of the gesture set have the specified
102     *         descriptor.
103     */
104    public static boolean verifyDescriptor(GestureSet set,
105          Class< ? extends Descriptor> descriptorType) {
106       for (final GestureClass gestureClass : set.getGestureClasses()) {
107 
108          if (gestureClass.hasDescriptor(descriptorType)) {
109             return false;
110          }
111 
112       }
113 
114       return true;
115    } // verifyDescriptor
116 
117 }