View Javadoc

1   package cz.cuni.amis.utils.collections;
2   
3   import java.util.Collection;
4   import java.util.HashSet;
5   
6   import cz.cuni.amis.utils.ClassUtils;
7   
8   /**
9    * HashSet that provides extended meaning of the .containsClass(cls) method.
10   * <p><p> 
11   * .contains(cls) first probes for class's ancestors
12   * and interfaces. The operation is then run against all of them.
13   * 
14   * @author Jimmy
15   */
16  public class HashSetClass extends HashSet<Class> {
17  	
18  	/**
19  	 * Returns class that is part of 'arg0' ancestors/interface classes.
20  	 * @param arg0
21  	 * @return
22  	 */
23  	public Class containsClass(Class arg0) {
24  		Collection<Class> classes = ClassUtils.getSubclasses((Class)arg0);
25  		for (Class cls : classes) {
26  			if (contains(cls)) return cls;
27  		}
28  		return null;
29  	}
30  
31  }