2015-04-20 15:36:01 -07:00
|
|
|
//: net/mindview/util/ContainerMethodDifferences.java
|
|
|
|
package net.mindview.util;
|
|
|
|
import java.lang.reflect.*;
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
public class ContainerMethodDifferences {
|
|
|
|
static Set<String> methodSet(Class<?> type) {
|
2015-05-05 11:20:13 -07:00
|
|
|
Set<String> result = new TreeSet<>();
|
2015-04-20 15:36:01 -07:00
|
|
|
for(Method m : type.getMethods())
|
|
|
|
result.add(m.getName());
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
static void interfaces(Class<?> type) {
|
|
|
|
System.out.print("Interfaces in " +
|
|
|
|
type.getSimpleName() + ": ");
|
2015-05-05 11:20:13 -07:00
|
|
|
List<String> result = new ArrayList<>();
|
2015-04-20 15:36:01 -07:00
|
|
|
for(Class<?> c : type.getInterfaces())
|
|
|
|
result.add(c.getSimpleName());
|
|
|
|
System.out.println(result);
|
|
|
|
}
|
|
|
|
static Set<String> object = methodSet(Object.class);
|
|
|
|
static { object.add("clone"); }
|
|
|
|
static void
|
|
|
|
difference(Class<?> superset, Class<?> subset) {
|
|
|
|
System.out.print(superset.getSimpleName() +
|
|
|
|
" extends " + subset.getSimpleName() + ", adds: ");
|
|
|
|
Set<String> comp = Sets.difference(
|
|
|
|
methodSet(superset), methodSet(subset));
|
|
|
|
comp.removeAll(object); // Don't show 'Object' methods
|
|
|
|
System.out.println(comp);
|
|
|
|
interfaces(superset);
|
|
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
|
|
System.out.println("Collection: " +
|
|
|
|
methodSet(Collection.class));
|
|
|
|
interfaces(Collection.class);
|
|
|
|
difference(Set.class, Collection.class);
|
|
|
|
difference(HashSet.class, Set.class);
|
|
|
|
difference(LinkedHashSet.class, HashSet.class);
|
|
|
|
difference(TreeSet.class, Set.class);
|
|
|
|
difference(List.class, Collection.class);
|
|
|
|
difference(ArrayList.class, List.class);
|
|
|
|
difference(LinkedList.class, List.class);
|
|
|
|
difference(Queue.class, Collection.class);
|
|
|
|
difference(PriorityQueue.class, Queue.class);
|
|
|
|
System.out.println("Map: " + methodSet(Map.class));
|
|
|
|
difference(HashMap.class, Map.class);
|
|
|
|
difference(LinkedHashMap.class, HashMap.class);
|
|
|
|
difference(SortedMap.class, Map.class);
|
|
|
|
difference(TreeMap.class, Map.class);
|
|
|
|
}
|
|
|
|
} ///:~
|