1 package net.sf.jga.fn.string; 33 34 import java.util.regex.Pattern ; 35 import net.sf.jga.fn.UnaryPredicate; 36 37 47 48 public class Match extends UnaryPredicate<String > { 49 50 static final long serialVersionUID = 4842042451096017684L; 51 52 private String _regex; 55 56 private Pattern _pattern; 58 59 62 public Match () { this(""); } 63 64 67 public Match (String regex){ 68 _regex = (regex != null) ? regex : ""; 69 _pattern = Pattern.compile(_regex); 70 } 71 72 75 public Match (Pattern pattern) { 76 _pattern = pattern; 77 _regex = pattern.pattern(); 78 } 79 80 84 85 public String getRegex() { 86 return _regex; 87 } 88 89 91 98 99 public Boolean fn(String arg) { 100 if (arg == null) 101 throw new NullPointerException (); 102 103 return _pattern.matcher(arg).find(); 104 } 105 106 110 public void accept(net.sf.jga.fn.Visitor v) { 111 if (v instanceof Match.Visitor) 112 ((Match.Visitor)v).visit(this); 113 else 114 v.visit(this); 115 } 116 117 119 public String toString() { 120 return "Match("+_regex+")"; 121 } 122 123 125 129 public interface Visitor extends net.sf.jga.fn.Visitor { 130 public void visit(Match host); 131 } 132 } 133 | Popular Tags |