KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > csdl > jblanket > methodset > MethodSetManager


1 package csdl.jblanket.methodset;
2
3 import java.util.HashMap JavaDoc;
4 import java.util.Map JavaDoc;
5
6 /**
7  * Implements a Singleton design pattern for the container of method information
8  * collected by JBlanket. This class is needed to avoid collisions when method
9  * type signatures are stored by the JUnit test classes.
10  *
11  * @author Joy M. Agustin
12  * @version $Id: MethodSetManager.java,v 1.1 2004/11/07 00:32:38 timshadel Exp $
13  */

14 public class MethodSetManager {
15
16   /** The instance of the MethodSetManager class */
17   private static MethodSetManager theInstance = null;
18
19   /** Container mapping fileName -> MethodSetManager */
20   private Map JavaDoc managerMap;
21
22   /**
23    * Initializes a new MethodSetManager instance.
24    */

25   private MethodSetManager() {
26     this.managerMap = new HashMap JavaDoc();
27   }
28
29   /**
30    * Gets the current instance of MethodSetManager.
31    *
32    * @return the MethodSetManager instance.
33    */

34   public static synchronized MethodSetManager getInstance() {
35
36     if (MethodSetManager.theInstance == null) {
37       MethodSetManager.theInstance = new MethodSetManager();
38     }
39
40     return MethodSetManager.theInstance;
41   }
42
43   /**
44    * Gets the MethodSet instance corresponding to <code>fileName</code> from the
45    * MethodSetManager instance.
46    *
47    * @param fileName the name of the file the MethodSet instance will be store in.
48    * @return the MethodSet instance corresponding to <code>fileName</code>.
49    * If none exists, create a new one.
50    */

51   public MethodSet getMethodSet(String JavaDoc fileName) {
52     MethodSet methodSet = (MethodSet) this.managerMap.get(fileName);
53
54     if (methodSet == null) {
55       methodSet = new MethodSet();
56       this.managerMap.put(fileName, methodSet);
57     }
58
59     return methodSet;
60   }
61 }
62
Popular Tags