KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > jayasoft > ivy > matcher > RegexpPatternMatcher


1 /*
2  * This file is subject to the licence found in LICENCE.TXT in the root directory of the project.
3  * Copyright Jayasoft 2005 - All rights reserved
4  *
5  * #SNAPSHOT#
6  */

7 package fr.jayasoft.ivy.matcher;
8
9 import java.util.regex.Pattern JavaDoc;
10
11 public final class RegexpPatternMatcher implements PatternMatcher {
12     public static class RegexpMatcher implements Matcher {
13         private Pattern JavaDoc _p;
14
15         public RegexpMatcher(String JavaDoc exp) {
16             _p = Pattern.compile(exp);
17         }
18
19         public boolean matches(String JavaDoc str) {
20             return _p.matcher(str).matches();
21         }
22
23         public boolean isExact() {
24             return false;
25         }
26     }
27     private static final RegexpPatternMatcher INSTANCE = new RegexpPatternMatcher();
28     public static PatternMatcher getInstance() {
29         return INSTANCE;
30     }
31     
32     private RegexpPatternMatcher() {
33     }
34     
35     public boolean match(String JavaDoc str, String JavaDoc exp) {
36         if (exp == null) {
37             return str == null;
38         }
39         return Pattern.matches(exp, str);
40     }
41
42     public String JavaDoc getName() {
43         return REGEXP;
44     }
45
46     public Matcher getMatcher(String JavaDoc exp) {
47         if (ANY_EXPRESSION.equals(exp)) {
48             return AnyMatcher.getInstance();
49         }
50         return new RegexpMatcher(exp);
51     }
52 }
53
Popular Tags