Clover coverage report - Maven Clover report
Coverage timestamp: Sun Aug 20 2006 04:01:04 PDT
file stats: LOC: 110   Methods: 7
NCLOC: 48   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
StringTerm.java 0% 0% 0% 0%
coverage
 1    /**
 2    *
 3    * Copyright 2003-2004 The Apache Software Foundation
 4    *
 5    * Licensed under the Apache License, Version 2.0 (the "License");
 6    * you may not use this file except in compliance with the License.
 7    * You may obtain a copy of the License at
 8    *
 9    * http://www.apache.org/licenses/LICENSE-2.0
 10    *
 11    * Unless required by applicable law or agreed to in writing, software
 12    * distributed under the License is distributed on an "AS IS" BASIS,
 13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14    * See the License for the specific language governing permissions and
 15    * limitations under the License.
 16    */
 17   
 18    package javax.mail.search;
 19   
 20    /**
 21    * A Term that provides matching criteria for Strings.
 22    *
 23    * @version $Rev: 125583 $ $Date: 2005-01-18 19:44:27 -0800 (Tue, 18 Jan 2005) $
 24    */
 25    public abstract class StringTerm extends SearchTerm {
 26    /**
 27    * If true, case should be ignored during matching.
 28    */
 29    protected boolean ignoreCase;
 30   
 31    /**
 32    * The pattern associated with this term.
 33    */
 34    protected String pattern;
 35   
 36    /**
 37    * Constructor specifying a pattern.
 38    * Defaults to case insensitive matching.
 39    * @param pattern the pattern for this term
 40    */
 41  0 protected StringTerm(String pattern) {
 42  0 this(pattern, true);
 43    }
 44   
 45    /**
 46    * Constructor specifying pattern and case sensitivity.
 47    * @param pattern the pattern for this term
 48    * @param ignoreCase if true, case should be ignored during matching
 49    */
 50  0 protected StringTerm(String pattern, boolean ignoreCase) {
 51  0 this.pattern = pattern;
 52  0 this.ignoreCase = ignoreCase;
 53    }
 54   
 55    /**
 56    * Return the pattern associated with this term.
 57    * @return the pattern associated with this term
 58    */
 59  0 public String getPattern() {
 60  0 return pattern;
 61    }
 62   
 63    /**
 64    * Indicate if case should be ignored when matching.
 65    * @return if true, case should be ignored during matching
 66    */
 67  0 public boolean getIgnoreCase() {
 68  0 return ignoreCase;
 69    }
 70   
 71    /**
 72    * Determine if the pattern associated with this term is a substring of the
 73    * supplied String. If ignoreCase is true then case will be ignored.
 74    *
 75    * @param match the String to compare to
 76    * @return true if this patter is a substring of the supplied String
 77    */
 78  0 protected boolean match(String match) {
 79  0 match: for (int length = match.length() - pattern.length(); length > 0; length--) {
 80  0 for (int i = 0; i < pattern.length(); i++) {
 81  0 char c1 = match.charAt(length + i);
 82  0 char c2 = match.charAt(i);
 83  0 if (c1 == c2) {
 84  0 continue;
 85    }
 86  0 if (ignoreCase) {
 87  0 if (Character.toLowerCase(c1) == Character.toLowerCase(c2)) {
 88  0 continue;
 89    }
 90  0 if (Character.toUpperCase(c1) == Character.toUpperCase(c2)) {
 91  0 continue;
 92    }
 93    }
 94  0 continue match;
 95    }
 96  0 return true;
 97    }
 98  0 return false;
 99    }
 100   
 101  0 public boolean equals(Object other) {
 102  0 return super.equals(other)
 103    && ((StringTerm) other).pattern.equals(pattern)
 104    && ((StringTerm) other).ignoreCase == ignoreCase;
 105    }
 106   
 107  0 public int hashCode() {
 108  0 return super.hashCode() + pattern.hashCode() + (ignoreCase ? 32 : 79);
 109    }
 110    }