View Javadoc

1   /*
2    * @(#)$Id: ClassMatcher.java 689 2009-07-22 00:10:27Z bsigner $
3    *
4    * Author		:	Ueli Kurmann, igesture@uelikurmann.ch
5    *
6    * Purpose		: 	Instantiated Regex of a gesture class.
7    *
8    * -----------------------------------------------------------------------
9    *
10   * Revision Information:
11   *
12   * Date				Who			Reason
13   *
14   * Dec 7, 2006		ukurmann	Initial Release
15   * Mar 16, 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.siger;
28  
29  import java.util.regex.Matcher;
30  import java.util.regex.Pattern;
31  
32  
33  /**
34   * Instantiated Regex of a gesture class.
35   * 
36   * @version 1.0 Dec 2006
37   * @author Ueli Kurmann, igesture@uelikurmann.ch
38   * @author Beat Signer, signer@inf.ethz.ch
39   */
40  public class ClassMatcher {
41  
42     private String description;
43  
44     private Pattern pattern;
45  
46     private Parser parser;
47  
48  
49     public ClassMatcher(String description) {
50        this.description = description;
51        init();
52     }
53  
54  
55     private void init() {
56        parser = new Parser(description);
57        pattern = parser.getPattern();
58     } // init
59  
60  
61     /**
62      * Tests if a stroke matches the gesture class.
63      * @param strokeInfo the stroke to be tested.
64      * @return true if there is a match.
65      */
66     public boolean isMatch(StrokeInfo strokeInfo) {
67        final Matcher m = pattern.matcher(strokeInfo.getString());
68        final boolean regexMatches = m.matches();
69        final boolean constraints = parser.evaluateConstraints(strokeInfo
70              .getStatistics());
71        return regexMatches && constraints;
72     } // isMatch
73  
74  }