1 21 22 27 28 package javax.mail.search; 29 30 38 public abstract class StringTerm extends SearchTerm { 39 44 protected String pattern; 45 46 51 protected boolean ignoreCase; 52 53 private static final long serialVersionUID = 1274042129007696269L; 54 55 protected StringTerm(String pattern) { 56 this.pattern = pattern; 57 ignoreCase = true; 58 } 59 60 protected StringTerm(String pattern, boolean ignoreCase) { 61 this.pattern = pattern; 62 this.ignoreCase = ignoreCase; 63 } 64 65 68 public String getPattern() { 69 return pattern; 70 } 71 72 75 public boolean getIgnoreCase() { 76 return ignoreCase; 77 } 78 79 protected boolean match(String s) { 80 int len = s.length() - pattern.length(); 81 for (int i=0; i <= len; i++) { 82 if (s.regionMatches(ignoreCase, i, 83 pattern, 0, pattern.length())) 84 return true; 85 } 86 return false; 87 } 88 89 92 public boolean equals(Object obj) { 93 if (!(obj instanceof StringTerm )) 94 return false; 95 StringTerm st = (StringTerm )obj; 96 if (ignoreCase) 97 return st.pattern.equalsIgnoreCase(this.pattern) && 98 st.ignoreCase == this.ignoreCase; 99 else 100 return st.pattern.equals(this.pattern) && 101 st.ignoreCase == this.ignoreCase; 102 } 103 104 107 public int hashCode() { 108 return ignoreCase ? pattern.hashCode() : ~pattern.hashCode(); 109 } 110 } 111 | Popular Tags |