KickJava   Java API By Example, From Geeks To Geeks.

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


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
10 public final class ExactOrRegexpPatternMatcher implements PatternMatcher {
11     public static class ExactOrRegexpMatcher implements Matcher {
12         private Matcher _exact;
13         private Matcher _regexp;
14
15         public ExactOrRegexpMatcher(String JavaDoc exp) {
16             _exact = ExactPatternMatcher.getInstance().getMatcher(exp);
17             _regexp = RegexpPatternMatcher.getInstance().getMatcher(exp);
18         }
19
20         public boolean matches(String JavaDoc str) {
21             return _exact.matches(str) || _regexp.matches(str);
22         }
23
24         public boolean isExact() {
25             return false;
26         }
27     }
28     private static final ExactOrRegexpPatternMatcher INSTANCE = new ExactOrRegexpPatternMatcher();
29     public static PatternMatcher getInstance() {
30         return INSTANCE;
31     }
32     
33     private ExactOrRegexpPatternMatcher() {
34     }
35     
36     public String JavaDoc getName() {
37         return EXACT_OR_REGEXP;
38     }
39
40     public Matcher getMatcher(String JavaDoc exp) {
41         if (ANY_EXPRESSION.equals(exp)) {
42             return AnyMatcher.getInstance();
43         }
44         return new ExactOrRegexpMatcher(exp);
45     }
46 }
47
Popular Tags