Coverage Report - us.daveread.basicquery.util.FileFilterDefinition
 
Classes in this File Line Coverage Branch Coverage Complexity
FileFilterDefinition
0%
0/21
0%
0/3
0
 
 1  
 package us.daveread.basicquery.util;
 2  
 
 3  
 /**
 4  
  * The file filter pattern definitions used within the program
 5  
  * 
 6  
  * @author David Read
 7  
  * 
 8  
  */
 9  0
 public enum FileFilterDefinition {
 10  
   /**
 11  
    * BasicQuery Query Files
 12  
    */
 13  0
   QUERY_BQ("BasicQuery Files",
 14  
       new String[] {
 15  
           ".bq"
 16  
       }, true),
 17  
 
 18  
   /**
 19  
    * SQL Query Files
 20  
    */
 21  0
   QUERY_SQL("SQL Files",
 22  
           new String[] {
 23  
             ".sql"
 24  
           }, false),
 25  
 
 26  
   /**
 27  
    * Text Files
 28  
    */
 29  0
   QUERY_TXT("Text Files",
 30  
       new String[] {
 31  
         ".txt"
 32  
       }, false);
 33  
 
 34  
   /**
 35  
    * The description of the file filter
 36  
    */
 37  
   private final String description;
 38  
 
 39  
   /**
 40  
    * The accepted file name suffixes for the file filter
 41  
    */
 42  
   private final String[] acceptedSuffixes;
 43  
 
 44  
   /**
 45  
    * Is this the preferred option within its set of patterns
 46  
    */
 47  
   private boolean isPreferredOption;
 48  
 
 49  
   /**
 50  
    * Create a file filter
 51  
    * 
 52  
    * @param pDescription
 53  
    *          The description of the filter
 54  
    * @param pAcceptedSuffixes
 55  
    *          The accepted file name suffixes for the filter
 56  
    * @param pIsPreferredOption
 57  
    *          Is this the preferred filter within the related group of filters
 58  
    */
 59  
   FileFilterDefinition(String pDescription, String[] pAcceptedSuffixes,
 60  0
       boolean pIsPreferredOption) {
 61  0
     description = formatDescription(pDescription, pAcceptedSuffixes);
 62  0
     acceptedSuffixes = pAcceptedSuffixes;
 63  0
     isPreferredOption = pIsPreferredOption;
 64  0
   }
 65  
 
 66  
   /**
 67  
    * Format the description to include a list of suffixes
 68  
    * 
 69  
    * @param pDescription
 70  
    *          The description
 71  
    * @param suffixes
 72  
    *          The file name suffixes this filter accepts
 73  
    *          
 74  
    * @return The description including suffixes
 75  
    */
 76  
   private String formatDescription(String pDescription, String[] suffixes) {
 77  0
     String formatted = pDescription;
 78  
 
 79  0
     if (suffixes != null && suffixes.length > 0) {
 80  0
       formatted += " (";
 81  0
       for (int index = 0; index < suffixes.length; ++index) {
 82  0
         if (index > 0) {
 83  0
           formatted = formatted + ", ";
 84  
         }
 85  0
         formatted += suffixes[index];
 86  
       }
 87  0
       formatted += ")";
 88  
     }
 89  
 
 90  0
     return formatted;
 91  
   }
 92  
 
 93  
   /**
 94  
    * Get the description for the file filter
 95  
    * 
 96  
    * @return The file filter description
 97  
    */
 98  
   public String description() {
 99  0
     return description;
 100  
   }
 101  
 
 102  
   /**
 103  
    * Get the accepted file name suffixes for the filter
 104  
    * 
 105  
    * @return The file name suffixes
 106  
    */
 107  
   public String[] acceptedSuffixes() {
 108  0
     return acceptedSuffixes;
 109  
   }
 110  
 
 111  
   /**
 112  
    * Determine whether this is the preferred (default) option for a group of
 113  
    * file filters
 114  
    * 
 115  
    * @return True if this filter is preferred
 116  
    */
 117  
   public boolean isPreferredOption() {
 118  0
     return isPreferredOption;
 119  
   }
 120  
 }