Clover coverage report - Replica - 1.0-Alpha
Coverage timestamp: Dom Fev 1 2004 17:00:58 WET
file stats: LOC: 96   Methods: 5
NCLOC: 60   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
SimpleFilenameFilter.java 0% 0% 0% 0%
coverage
 1   
 package nmp.file_utils;
 2   
 
 3   
 import java.io.*;
 4   
 
 5   
 /**
 6   
 * Implements a simple filename filter. Wildcard character is defined
 7   
 * in wildChar.
 8   
 *@author Nuno Preguica
 9   
 */
 10   
 public class SimpleFilenameFilter
 11   
     implements FilenameFilter
 12   
 {
 13   
     private String    nameFilter;
 14   
 
 15   
     /**
 16   
     * Initializes filter.
 17   
     *@param s String containing filename filter. It should not contain
 18   
     *    directories' information, i.e., it should has the form
 19   
     *    [ \* | nameSubString]+
 20   
     * Character stuffing used for wildChar
 21   
     */
 22  0
     public SimpleFilenameFilter( String s)
 23   
     {
 24  0
         nameFilter = s;
 25   
     }
 26   
 
 27   
     public final char wildChar = '*';
 28   
 
 29   
     /**
 30   
     * Returns true if str1.substring( from1, len1) could be a compacted
 31   
     * form of str2.substring( from2, len2) (using wildcards)
 32   
     */
 33  0
     private boolean match( String str1, int from1, int len1,
 34   
                             String str2, int from2, int len2)
 35   
     {
 36  0
         char    ch;
 37  0
         if( from1 == len1 && from2 == len2)
 38  0
             return true;
 39  0
         if( from1 == len1 || from2 == len2)
 40  0
             return false;
 41   
 
 42  0
         ch = str1.charAt( from1);
 43  0
 condition:
 44   
         {
 45  0
         if( ch == wildChar )
 46   
         {
 47  0
             from1++;
 48  0
             if( len1 == from1)    //wild char e o ultimo caracter
 49  0
                 return true;
 50  0
             ch = str1.charAt( from1);
 51  0
             if( ch == wildChar)
 52   
             {
 53  0
                 break condition;
 54   
             }
 55   
 
 56  0
             for( ; from2 < len2 ;from2++ )
 57  0
                 if( ch == str2.charAt( from2))
 58  0
                     if( match( str1, from1 + 1, len1,
 59   
                                 str2, from2 + 1, len2))
 60  0
                         return true;
 61  0
             return false;
 62   
         }
 63   
         }
 64  0
         if( ch == str2.charAt( from2))
 65  0
             return match( str1, from1 + 1, len1,
 66   
                             str2, from2 + 1, len2);
 67  0
         return false;
 68   
     }
 69   
 
 70  0
     private boolean match( String str1, int from1,
 71   
                             String str2, int from2)
 72   
     {
 73  0
         return match( str1, from1, str1.length(),
 74   
                         str2, from2, str2.length());
 75   
     }
 76   
 
 77   
     /**
 78   
     * Returns true if 1.st string could be a compacted form of
 79   
     * the second (using wildcards)
 80   
     */
 81  0
     private boolean match( String str1, String str2)
 82   
     {
 83  0
         return match( str1, 0, str2, 0);
 84   
     }
 85   
 
 86   
     /**
 87   
     * Setermines if the given name is acceptable under the current
 88   
     * FilenameFilter
 89   
     */
 90  0
     public boolean accept( File dir, String name)
 91   
     {
 92  0
         return match( nameFilter, name);
 93   
     }
 94   
 }
 95   
 
 96