Clover coverage report - Replica - 1.0-Alpha
Coverage timestamp: Dom Fev 1 2004 17:00:58 WET
file stats: LOC: 78   Methods: 4
NCLOC: 54   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
WildcardString.java 0% 0% 0% 0%
coverage
 1   
 package nmp.util;
 2   
 
 3   
 /**
 4   
 * Implements facilities to compare a string with the '*' wildcard and common strings.
 5   
 * Wildcard string should have the form
 6   
 * [ * | ** | other char]+
 7   
 * 
 8   
 * @author Nuno Preguica
 9   
 */
 10   
 public class WildcardString
 11   
 {
 12   
     private String    nameFilter;
 13   
 
 14  0
     public WildcardString( String s) {
 15  0
         nameFilter = s;
 16   
     }
 17   
 
 18   
     private static final char wildChar = '*';
 19   
 
 20   
     /**
 21   
     * Returns true if str1.substring( from1, len1) could be a compacted
 22   
     * form of str2.substring( from2, len2) (using wildcards)
 23   
     */
 24  0
     private static boolean match( String str1, int from1, int len1,
 25   
                             String str2, int from2, int len2) {
 26  0
         char    ch, nextch;
 27  0
         for( ; ; ) {
 28  0
             if( from1 == len1 && from2 == len2)
 29  0
                 return true;
 30  0
             if( from1 == len1)
 31  0
                 return false;
 32  0
             if( from2 == len2)
 33  0
                 return len1 - from1 == 1 && str1.charAt( from1) == wildChar;
 34   
 
 35  0
             ch = str1.charAt( from1);
 36  0
             nextch = ' ';
 37  0
             if( from1 + 1 < len1)
 38  0
                 nextch = str1.charAt( from1 + 1);
 39  0
 condition:
 40   
             {
 41  0
                 if( ch == wildChar && nextch != wildChar) {
 42  0
                     from1++;
 43  0
                     if( len1 == from1)    //wild char e o ultimo caracter
 44  0
                         return true;
 45  0
                     ch = str1.charAt( from1);
 46  0
                     if( ch == wildChar) {
 47  0
                         break condition;
 48   
                     }
 49  0
                     for( ; from2 < len2 ;from2++ )
 50  0
                         if( ch == str2.charAt( from2))
 51  0
                             if( match( str1, from1 + 1, len1, str2, from2 + 1, len2))
 52  0
                                 return true;
 53  0
                     return false;
 54   
                 }
 55   
             }
 56  0
             if( ch == wildChar && nextch == wildChar)
 57  0
                 from1++;
 58  0
             if( ch != str2.charAt( from2))
 59  0
                 return false;
 60  0
             from1++;
 61  0
             from2++;
 62   
         }
 63   
     }
 64   
 
 65   
     /**
 66   
     * Returns true if 1.st string could be a compacted form of
 67   
     * the second (using wildcards)
 68   
     */
 69  0
     public static boolean match( String str1, String str2) {
 70  0
         return match( str1, 0, str1.length(), str2, 0, str2.length());
 71   
     }
 72   
 
 73  0
     public boolean match( String name) {
 74  0
         return match( nameFilter, name);
 75   
     }
 76   
 }
 77   
 
 78