2 * Copyright (c) Paul Kinnucan 2003. All Rights Reserved.
5 * $Date: 2003/09/08 03:42:17 $
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.
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.
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.
23 import java.util.Hashtable;
24 import java.util.Vector;
25 import java.util.Enumeration;
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.
34 * @author <a href="mailto:mschw@web.de">Martin Schwamberger</a>
35 * @version $Revision: 1.2 $
37 public class SignatureContainer {
40 * A table with declaring classes as keys and vectors of method
41 * signatures as values
43 private Hashtable classes = new Hashtable();
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
52 * @param sig Signature to be stored in the signature table.
54 public final void add(Signature sig) {
56 // There can be only one, even though declaring classes differ.
57 if (!alreadyStored(sig)) {
59 String declaring = sig.getDeclaringClass().getName();
61 if (classes.containsKey(declaring)) {
62 ((Vector) classes.get(declaring)).addElement(sig);
64 Vector v = new Vector();
66 classes.put(declaring, v);
73 * Check whether container already contains signature.
75 * @param sig a <code>Signature</code> value
76 * @return a <code>boolean</code> value
78 private final boolean alreadyStored(Signature sig) {
79 Enumeration declaringClasses = classes.keys();
80 boolean found = false;
82 while (declaringClasses.hasMoreElements() && !found) {
83 String interf = (String) declaringClasses.nextElement();
84 Vector v = (Vector) classes.get(interf);
85 found = v.contains(sig);
92 * Clear the signature container.
99 * True if this container is empty of signatures.
101 * @return a <code>boolean</code> value
103 public boolean isEmpty() {
104 return classes.isEmpty();
108 * Visit each signature in the container.
110 * @param visitor the SignatureVisitor object visiting the signatures
112 public void visit(SignatureVisitor visitor) {
114 Enumeration declaringClasses = classes.keys();
115 while (declaringClasses.hasMoreElements()) {
117 String className = (String) declaringClasses.nextElement();
118 Vector v = (Vector) classes.get(className);
119 boolean firstOfClass = true;
120 Enumeration e = v.elements();
122 while (e.hasMoreElements()) {
123 Signature sig = (Signature) e.nextElement();
124 visitor.visit(sig, firstOfClass);
125 firstOfClass = false;
132 * $Log: SignatureContainer.java,v $
133 * Revision 1.2 2003/09/08 03:42:17 paulk
134 * Remove DOS line endings.
136 * Revision 1.1 2003/09/07 05:32:01 paulk
141 // End of SignatureContainer.java