int (DefaultMutableTreeNode parent, DNamedElement namedElement) { if (parent.getChildCount() == 0) return 0; int res = 0; for (DefaultMutableTreeNode child = (DefaultMutableTreeNode) parent.getFirstChild(); child != null; child = (DefaultMutableTreeNode) parent.getChildAfter(child)) { Object childObject = child.getUserObject(); if (!(childObject instanceof DNamedElement)) return 0; String otherName = ((DNamedElement) childObject).getName(); if (otherName.compareTo(namedElement.getName()) > 0) return res; res++; } return res; }