Counters (@NotNull DefaultMutableTreeNode foundNode) { Counters counters = new Counters(); @SuppressWarnings("unchecked") Enumeration<TreeNode> enumeration = ((DefaultMutableTreeNode)foundNode.getRoot()).preorderEnumeration(); while (enumeration.hasMoreElements()) { TreeNode node = enumeration.nextElement(); if (node instanceof DefaultMutableTreeNode && isOccurrenceNode((DefaultMutableTreeNode)node)) { counters.myOccurencesCount++; } if (node == foundNode) { counters.myFoundOccurenceNumber = counters.myOccurencesCount; } } return counters; }