KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > csdl > jblanket > util > MethodCategories


1 package csdl.jblanket.util;
2
3 import csdl.jblanket.modifier.MethodCollector;
4
5 import java.io.File JavaDoc;
6 import java.util.HashMap JavaDoc;
7 import java.util.Map JavaDoc;
8 import java.util.Set JavaDoc;
9
10 /**
11  * Provides an access point to all types of method categories. Implementation of this class
12  * follows the Singleton design pattern.
13  * <p>
14  * The following are supported method categories with default file names:
15  * <ul>
16  * <li> totalMethods
17  * <li> untestableMethods
18  * <li> excludedMethods
19  * <li> oneLineMethods
20  * <li> constructorMethods
21  * <li> excludedIndividualMethods
22  * <li> total.testedMethods
23  * <li> total.untestedMethods
24  * <li> testedMethods
25  * <li> untestedMethods
26  * </ul>
27  * <p>
28  * This class was implemented to simplify passing file names and associating them with the above
29  * mentioned method categories.
30  *
31  * @author Joy M. Agustin
32  * @version $Id: MethodCategories.java,v 1.1 2004/11/07 00:32:24 timshadel Exp $
33  */

34 public class MethodCategories {
35
36   /** Instance of the MethodCategories class */
37   private static MethodCategories theInstance = null;
38   /** Container mapping category -> fileName */
39   private Map JavaDoc categories;
40   /** Output directory for JBlanket data */
41   private String JavaDoc jblanketDir;
42
43   /** Initializes a new MethodCategories instance. */
44   private MethodCategories() {
45
46     this.categories = new HashMap JavaDoc();
47     this.jblanketDir = MethodCollector.getJBlanketDir();
48   }
49
50   /**
51    * Gets the current instance of MethodCategories
52    *
53    * @return the MehtodCategories instance.
54    */

55   public static MethodCategories getInstance() {
56
57     if (MethodCategories.theInstance == null) {
58       MethodCategories.theInstance = new MethodCategories();
59     }
60
61     return MethodCategories.theInstance;
62   }
63
64   /**
65    * Adds a category and maps it to the default XML file name. If no default file name exists,
66    * then <code>null</code> is stored as the file name.
67    * <p>
68    * Example:
69    * <pre>
70    * category -&gt; &lt;jblanket.dir&gt;/&lt;default file name&gt;
71    * </pre>
72    *
73    * @param category the method category.
74    */

75   public void addCategory(String JavaDoc category) {
76     this.addCategory(category, DefaultFileName.getDefaultFileName(category));
77   }
78   
79   /**
80    * Adds a category and maps it to <code>fileName</code>.
81    * <p>
82    * Example:
83    * <pre>
84    * category -&gt; &lt;jblanket.dir&gt;/<code>fileName</code>
85    * </pre>
86    *
87    * @param category the method category.
88    * @param fileName the name of the file where methods in <code>category</code> is stored.
89    */

90   public void addCategory(String JavaDoc category, String JavaDoc fileName) {
91
92     if (fileName == null) {
93       this.categories.put(category, null);
94     }
95     else {
96       this.categories.put(category, this.jblanketDir + File.separator + fileName);
97     }
98   }
99
100   /**
101    * Returns the fully qualified <code>fileName</code> associated with <code>category</code>.
102    *
103    * @param category the category to retrieve.
104    * @return the fully qualified <code>fileName</code> associated with <code>category</code>,
105    * or null if one doesn't exist.
106    */

107   public String JavaDoc getFileName(String JavaDoc category) {
108
109     String JavaDoc fileName = (String JavaDoc) this.categories.get(category);
110     if (fileName == null) {
111       addCategory(category);
112       fileName = (String JavaDoc) this.categories.get(category);
113     }
114
115     return fileName;
116   }
117
118   /**
119    * Returns all the categories stored in this container.
120    *
121    * @return the categories stored in this container.
122    */

123   public Set JavaDoc getCategories() {
124     return this.categories.keySet();
125   }
126 }
Popular Tags