Initial Commit
[packages] / xemacs-packages / jde / java / src / jde / wizards / SignatureContainer.java
1 /*
2  * Copyright (c) Paul Kinnucan 2003. All Rights Reserved.
3  *
4  * $Revision: 1.2 $ 
5  * $Date: 2003/09/08 03:42:17 $ 
6  *
7  * SignatureContainer is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2, or (at
10  * your option) any later version.
11  *
12  * SignatureContainer is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License for more details.
16  *
17  * To obtain a copy of the GNU General Public License write to the
18  * Free Software Foundation, Inc.,  59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.  
20  */
21 package jde.wizards;
22
23 import java.util.Hashtable;
24 import java.util.Vector;
25 import java.util.Enumeration;
26
27 /**
28  * A container for method signatures. The signatures are stored in
29  * vectors with their declaring classes as keys in a hashtable.  This
30  * allows them to be pulled out in groups when we print, and keeping
31  * the declaring class info lets us put in comments about where the
32  * method (or method group) comes from.
33  *
34  * @author <a href="mailto:mschw@web.de">Martin Schwamberger</a>
35  * @version $Revision: 1.2 $
36  */
37 public class SignatureContainer {
38   
39   /**
40    * A table with declaring classes as keys and vectors of method
41    * signatures as values
42    */
43   private Hashtable classes = new Hashtable();
44   
45   /** 
46    * Adds a signature to the container. Signatures are not
47    * added if they're already registered because we do not want
48    * duplicate method implementations even though a class might
49    * implement interfaces that inherit from some common
50    * super-interface.
51    *
52    * @param sig Signature to be stored in the signature table.
53    */
54   public final void add(Signature sig) {
55     
56     // There can be only one, even though declaring classes differ.
57     if (!alreadyStored(sig)) {
58       
59       String declaring = sig.getDeclaringClass().getName();
60       
61       if (classes.containsKey(declaring)) {
62           ((Vector) classes.get(declaring)).addElement(sig);
63       } else {    
64         Vector v = new Vector();
65         v.addElement(sig);
66         classes.put(declaring, v);
67       }
68     
69     }
70   }
71
72   /**
73    * Check whether container already contains signature.
74    *
75    * @param sig a <code>Signature</code> value
76    * @return a <code>boolean</code> value
77    */
78   private final boolean alreadyStored(Signature sig) {
79     Enumeration declaringClasses = classes.keys();
80     boolean found = false;
81     
82     while (declaringClasses.hasMoreElements() && !found) {
83       String interf = (String) declaringClasses.nextElement();
84       Vector v = (Vector) classes.get(interf);
85       found = v.contains(sig);
86     }
87
88     return found;
89   }
90
91   /** 
92    * Clear the signature container.
93    */
94   public void clear() {
95     classes.clear();
96   }
97
98   /**
99    * True if this container is empty of signatures.
100    *
101    * @return a <code>boolean</code> value
102    */
103   public boolean isEmpty() {
104     return classes.isEmpty();
105   }
106
107   /**
108    * Visit each signature in the container.
109    *
110    * @param visitor the SignatureVisitor object visiting the signatures
111    */
112   public void visit(SignatureVisitor visitor) {
113     
114     Enumeration declaringClasses = classes.keys();
115     while (declaringClasses.hasMoreElements()) {
116       
117       String className = (String) declaringClasses.nextElement();
118       Vector v = (Vector) classes.get(className);
119       boolean firstOfClass = true;
120       Enumeration e = v.elements();
121       
122       while (e.hasMoreElements()) {
123         Signature sig = (Signature) e.nextElement();
124         visitor.visit(sig, firstOfClass);
125         firstOfClass = false;
126       }
127     }
128   }
129 }
130
131 /*
132  * $Log: SignatureContainer.java,v $
133  * Revision 1.2  2003/09/08 03:42:17  paulk
134  * Remove DOS line endings.
135  *
136  * Revision 1.1  2003/09/07 05:32:01  paulk
137  * Initial revision.
138  *
139  */
140
141 // End of SignatureContainer.java