1 7 package fr.jayasoft.ivy.matcher; 8 9 import java.util.regex.Pattern ; 10 11 public final class RegexpPatternMatcher implements PatternMatcher { 12 public static class RegexpMatcher implements Matcher { 13 private Pattern _p; 14 15 public RegexpMatcher(String exp) { 16 _p = Pattern.compile(exp); 17 } 18 19 public boolean matches(String 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 str, String exp) { 36 if (exp == null) { 37 return str == null; 38 } 39 return Pattern.matches(exp, str); 40 } 41 42 public String getName() { 43 return REGEXP; 44 } 45 46 public Matcher getMatcher(String exp) { 47 if (ANY_EXPRESSION.equals(exp)) { 48 return AnyMatcher.getInstance(); 49 } 50 return new RegexpMatcher(exp); 51 } 52 } 53 | Popular Tags |