ClassLikeFilter extends AbstractLogFilter { protected void createPackagesTree(TreeSet<String> packages, HashMap<Clazz, DefaultMutableTreeNode> map, DefaultMutableTreeNode root) { for (String string : packages) { Clazz clazz = new Clazz(string); DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(clazz); DefaultMutableTreeNode parentNode; if (map.containsKey(new Clazz(clazz.pack))) { parentNode = map.get(new Clazz(clazz.pack)); } else { parentNode = root; } map.put(clazz, newNode); parentNode.add(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 testCreatePackagesTree() throws Exception { TreeSet<String> packages = new TreeSet<>(Arrays.asList("a", "a.b", "c", "c.d")); HashMap<ClassLikeFilter.Clazz, DefaultMutableTreeNode> map = new HashMap<>(); final DefaultMutableTreeNode root = new DefaultMutableTreeNode(new ClassLikeFilter.Clazz("root")); filter.createPackagesTree(packages, map, root); assertEquals(map.size(), 4); assertTrue(map.containsKey(new ClassLikeFilter.Clazz("a"))); assertTrue(map.containsKey(new ClassLikeFilter.Clazz("a.b"))); assertTrue(map.containsKey(new ClassLikeFilter.Clazz("c"))); assertTrue(map.containsKey(new ClassLikeFilter.Clazz("c.d"))); final DefaultMutableTreeNode child = map.get(new ClassLikeFilter.Clazz("a.b")); final DefaultMutableTreeNode parent = map.get(new ClassLikeFilter.Clazz("a")); System.out.println(parent); final TreeNode parent1 = child.getParent(); assertEquals(parent1, parent); }