ClassLikeFilter extends AbstractLogFilter { protected void addClassesLeafs(Set<String> classesSet, DefaultMutableTreeNode root, HashMap<Clazz, DefaultMutableTreeNode> map) { for (String string : classesSet) { Clazz clazz = new Clazz(string); DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(clazz); DefaultMutableTreeNode parentNode; Clazz packetClazz = new Clazz(clazz.pack); if (map.containsKey(packetClazz)) { parentNode = map.get(packetClazz); } else if (clazz.pack.length() == 0) { parentNode = root; } else { parentNode = new DefaultMutableTreeNode(packetClazz); root.add(parentNode); map.put(packetClazz, parentNode); } parentNode.add(newNode); map.put(clazz, newNode); } } ClassLikeFilter(String name, String description); abstract Function<LogData, String> extractValueFunction(); @Override boolean accept(LogData logData, int row); @Override Component getGUI(); @Override void init(Properties properties, LogDataTableModel collector, Theme theme); @Override void setEnable(boolean enable); void ignoreClass(String... classes); void focusOn(String... classes);  }
@Test public void testAddClassesLeafs() throws Exception { DefaultMutableTreeNode root = new DefaultMutableTreeNode("root"); Set<String> classesSet = new HashSet<>(Arrays.asList("a.C1","a.b.C1","b.A","C1","C2")); TreeSet<String> packages = filter.preparePackagesNodes(classesSet); HashMap<ClassLikeFilter.Clazz, DefaultMutableTreeNode> clazzNodeMap = new HashMap<>(); filter.createPackagesTree(packages, clazzNodeMap, root); filter.addClassesLeafs(classesSet, root, clazzNodeMap); final List<DefaultMutableTreeNode> level1Nodes = Collections.list(root.children()); assertEquals(level1Nodes.size(),4); final List<ClassLikeFilter.Clazz> clazzesLevel1 = level1Nodes.stream() .map(n -> (ClassLikeFilter.Clazz) n.getUserObject()) .sorted((c1,c2)->c1.toFullString().compareTo(c2.toFullString())) .collect(Collectors.toList()); clazzesLevel1.stream().forEach(l -> System.out.println("\"" + l + "\"")); assertEquals(clazzesLevel1.get(0),new ClassLikeFilter.Clazz("C1")); assertEquals(clazzesLevel1.get(1),new ClassLikeFilter.Clazz("C2")); assertEquals(clazzesLevel1.get(2),new ClassLikeFilter.Clazz("a")); assertEquals(clazzesLevel1.get(3),new ClassLikeFilter.Clazz("b")); }