1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.bcel.util;
18
19 import java.util.Collection;
20 import java.util.HashMap;
21 import java.util.Map;
22 import org.apache.bcel.classfile.JavaClass;
23
24 /***
25 * Utility class implementing a (typesafe) set of JavaClass objects.
26 * Since JavaClass has no equals() method, the name of the class is
27 * used for comparison.
28 *
29 * @version $Id: ClassSet.java 386056 2006-03-15 11:31:56Z tcurdt $
30 * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
31 * @see ClassStack
32 */
33 public class ClassSet implements java.io.Serializable {
34
35 private Map _map = new HashMap();
36
37
38 public boolean add( JavaClass clazz ) {
39 boolean result = false;
40 if (!_map.containsKey(clazz.getClassName())) {
41 result = true;
42 _map.put(clazz.getClassName(), clazz);
43 }
44 return result;
45 }
46
47
48 public void remove( JavaClass clazz ) {
49 _map.remove(clazz.getClassName());
50 }
51
52
53 public boolean empty() {
54 return _map.isEmpty();
55 }
56
57
58 public JavaClass[] toArray() {
59 Collection values = _map.values();
60 JavaClass[] classes = new JavaClass[values.size()];
61 values.toArray(classes);
62 return classes;
63 }
64
65
66 public String[] getClassNames() {
67 return (String[]) _map.keySet().toArray(new String[_map.keySet().size()]);
68 }
69 }