Object (boolean showRoot) { final Object rootElement = myTreeStructure.getRootElement(); if (showRoot) return rootElement; final Object[] rootChildren = myTreeStructure.getChildElements(rootElement); if (rootChildren.length == 1 && shouldEnterSingleTopLevelElement(rootChildren[0])) { return rootChildren[0]; } else { return rootElement; } }