4 */ 5 /* 6 * Licensed to the Apache Software Foundation (ASF) under one or more 7 * contributor license agreements. See the NOTICE file distributed with 8 * this work for additional information regarding copyright ownership. 9 * The ASF licenses this file to You under the Apache License, Version 2.0 10 * (the "License"); you may not use this file except in compliance with 11 * the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 */ 21 22 package com.sun.org.apache.bcel.internal.util; 23 24 import java.util.HashMap; 25 import java.util.Collection; 26 import com.sun.org.apache.bcel.internal.classfile.JavaClass; 27 28 /** 29 * Utility class implementing a (typesafe) set of JavaClass objects. 30 * Since JavaClass has no equals() method, the name of the class is 31 * used for comparison. 32 * 33 * @author <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A> 34 * @see ClassStack 35 */ 36 public class ClassSet implements java.io.Serializable { 37 private HashMap _map = new HashMap(); 38 39 public boolean add(JavaClass clazz) { 40 boolean result = false; 41 42 if(!_map.containsKey(clazz.getClassName())) { 43 result = true; 44 _map.put(clazz.getClassName(), clazz); 45 } 46 47 return result; 48 } 49 50 public void remove(JavaClass clazz) { _map.remove(clazz.getClassName()); } 51 public boolean empty() { return _map.isEmpty(); } 52 53 public JavaClass[] toArray() { 54 Collection values = _map.values(); 55 JavaClass[] classes = new JavaClass[values.size()]; 56 values.toArray(classes); 57 return classes; 58 } 59 60 public String[] getClassNames() { 61 return (String[])_map.keySet().toArray(new String[_map.keySet().size()]); 62 } 63 } | 4 */ 5 /* 6 * Licensed to the Apache Software Foundation (ASF) under one or more 7 * contributor license agreements. See the NOTICE file distributed with 8 * this work for additional information regarding copyright ownership. 9 * The ASF licenses this file to You under the Apache License, Version 2.0 10 * (the "License"); you may not use this file except in compliance with 11 * the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 */ 21 22 package com.sun.org.apache.bcel.internal.util; 23 24 import java.util.Collection; 25 import java.util.HashMap; 26 import java.util.Map; 27 28 import com.sun.org.apache.bcel.internal.classfile.JavaClass; 29 30 /** 31 * Utility class implementing a (typesafe) set of JavaClass objects. 32 * Since JavaClass has no equals() method, the name of the class is 33 * used for comparison. 34 * 35 * @version $Id: ClassSet.java 1749603 2016-06-21 20:50:19Z ggregory $ 36 * @see ClassStack 37 */ 38 public class ClassSet { 39 40 private final Map<String, JavaClass> map = new HashMap<>(); 41 42 43 public boolean add( final JavaClass clazz ) { 44 boolean result = false; 45 if (!map.containsKey(clazz.getClassName())) { 46 result = true; 47 map.put(clazz.getClassName(), clazz); 48 } 49 return result; 50 } 51 52 53 public void remove( final JavaClass clazz ) { 54 map.remove(clazz.getClassName()); 55 } 56 57 58 public boolean empty() { 59 return map.isEmpty(); 60 } 61 62 63 public JavaClass[] toArray() { 64 final Collection<JavaClass> values = map.values(); 65 final JavaClass[] classes = new JavaClass[values.size()]; 66 values.toArray(classes); 67 return classes; 68 } 69 70 71 public String[] getClassNames() { 72 return map.keySet().toArray(new String[map.size()]); 73 } 74 } |